Contract 0x47b0eC1beA7d8EcC7cF70C3bF82c5f5d15a96b6D 5

 

Contract Overview

Zapper.Fi: SushiSwap Zap In
Balance:
16.41158 MATIC

MATIC Value:
$9.57 (@ $0.58/MATIC)

Token:
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xc64c2c4dfbe4c74c929f65f1d43d9894ebfe4590bf8674e823f31f55c0ef6ed4Zap In299830882022-06-25 14:07:358 mins ago0xf399ef3067d2165f43e0bea3addcd4f882646573 IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.01541452567 48.540972709
0xb015bcc2818847d869af9bb680787d49ec25cba6691f835b8d73aed213b6b121Zap In299765942022-06-25 9:43:194 hrs 32 mins ago0xaae01c21624dbba0413c4913c7092bd58eed8afc IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.013150434422 41.657483599
0x422b0ba036513e6ee29bed1e5b823fbd76b4abd5769f56f5f6b2e32c15552533Zap In299748652022-06-25 8:29:495 hrs 46 mins ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In5 MATIC0.030255521597 61.36437621
0xa6f898b7b3347611369d351d0c392cf68e120407ff9b814326f4a2fbedf90f6fZap In299748582022-06-25 8:29:355 hrs 46 mins ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In5 MATIC0.016422395725 61.36437621
0xcbb562d1e14ea6d114f65623f78bccb3fbd292c572e93735a244a6abc4e33bc2Zap In299698382022-06-25 4:54:149 hrs 22 mins ago0xffdcaf0f5f80066da3a886f6cd241b16572489f0 IN  Zapper.Fi: SushiSwap Zap In0.11 MATIC0.019796040007 30.000000012
0x1775a55aa4476ee095869b3ed9dfcbe48d21574851bc4937e72f371a542ee47bZap In299468502022-06-24 13:50:091 day 26 mins ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In5 MATIC0.029608551413 61.346946101
0x371def2d26601642e640cfa41f7dc5aa6efe866c777e83998672ee9433384d69Zap In299468362022-06-24 13:49:411 day 26 mins ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In5 MATIC0.016295048245 61.346987797
0x23ec7656e64fed063a4f82ee5fa208959f37bd0c84ea357dae4e35c3309c28d8Zap In299377282022-06-24 8:12:471 day 6 hrs ago0xf6a82125fc010aa50acc58dd486136302f4d0fb9 IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.009326400005 30.000000017
0x88f20743f44b1938048609de71e9e885420f8d1d35dd269399ef8ca86b8fa8e3Zap In299270692022-06-24 1:26:391 day 12 hrs ago0x0e22b17cbc92cc9bfaf06e875dfaf1fdca5d3715 IN  Zapper.Fi: SushiSwap Zap In0.4 MATIC0.009283909513 31.040106164
0x1c3e672d93d0c89c56c8f7d880d0da84e05b1086aa8a3b2394d6d9d04729f685Zap In299270432022-06-24 1:24:551 day 12 hrs ago0x0e22b17cbc92cc9bfaf06e875dfaf1fdca5d3715 IN  Zapper.Fi: SushiSwap Zap In1 MATIC0.015063811146 30.00006203
0x2524dd29da81e745ab243d9158b70ceadae75b1c0bc9bb7ef072875aad9d9ef3Zap In299269232022-06-24 1:20:391 day 12 hrs ago0x0e22b17cbc92cc9bfaf06e875dfaf1fdca5d3715 IN  Zapper.Fi: SushiSwap Zap In1 MATIC0.014654517377 30.002697112
0xc98759bee644e56cfbc40f93fdd4a374fb09f4d948350c934173e31a8faedbd6Zap In299269032022-06-24 1:19:551 day 12 hrs ago0x0e22b17cbc92cc9bfaf06e875dfaf1fdca5d3715 IN  Zapper.Fi: SushiSwap Zap In1 MATIC0.01728479296 30.004726796
0x27a55bc18b4e8cf56dcced49e7ac33776307c6814e69d65d42228e3b47d70e6aZap In299210302022-06-23 21:45:101 day 16 hrs ago0x059c457a26473bf20fb80221e474146c29dd6ead IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.017306484366 33.395244536
0x794718f484f6db44d207c78542cebb10ad81b49cc4113fe3851501293b496cc8Zap In299132692022-06-23 16:52:371 day 21 hrs ago0x99cf935c4e8d757b23e6a73e7463c8af06c1f750 IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.010293926553 35.480271165
0x0a3020da128adb7973e5bec528230a1e4b9cc535968cc941d6ab00dbee6a8330Zap In299131282022-06-23 16:47:471 day 21 hrs ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In5 MATIC0.047266585783 61.36437621
0xd531048bf962cb04b5db498e5753085e551ea6ab4db74f1fa5fa3a1bc31c166cZap In299130292022-06-23 16:44:251 day 21 hrs ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In5 MATIC0.027611704504 61.352117427
0x5a046d4c0a3690ffb1a28797d91f68b8a66fc6ccc5148debf702cd06c1be6d30Zap In299121882022-06-23 16:13:191 day 22 hrs ago0x1cf41ad63f67f3e7f8a1db240d812f5392b9a9c4 IN  Zapper.Fi: SushiSwap Zap In80 MATIC0.013772219334 43.960532338
0xb2accc308bfe43d6a709bc0cf7e03cf4efe69b2bd7f5c5618b32f8adec1585d4Zap In299094742022-06-23 14:29:401 day 23 hrs ago0xa9408ec2e069e714c4161b1eee963346dc867ee1 IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.009327235103 30.000370221
0x60a5f7ce9d194a51e44a482a101bb73157b74f1b801956538c812177d7be2b5bZap In298990102022-06-23 7:53:372 days 6 hrs ago0xf4dd167c2a61f94cf454bc9663a79ea8c38ee78c IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.010357776346 35.066767599
0x53e479d113222e187a70561e275c22b5279386288a9d06c5d56ad6f9728cba17Zap In298830862022-06-22 22:16:162 days 16 hrs ago0x9d8813f2cd2ea0c70f3ea5137b566ca826fd647a IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.010006834649 32.596614382
0xe1e3618a9c06715f5a8271d737250ae7045ea5a4788611867f2d80b7ffe9f252Zap In298826172022-06-22 22:00:062 days 16 hrs ago0x99cf935c4e8d757b23e6a73e7463c8af06c1f750 IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.009961229675 30.906029579
0xc943fefb1c6f1ddcfa460fdb1c015ac56e36d4e0dc784edb29dd134956bcdf3cZap In298737282022-06-22 16:33:152 days 21 hrs ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In3 MATIC0.041031803384 61.364042497
0x846e6aff336982878d6fac89238f39304609a28e5b8b9cd7b04a336b2e4762b5Zap In298737142022-06-22 16:32:432 days 21 hrs ago0xba8765802198e5c19f2ba8fe9b0da2b225927aaf IN  Zapper.Fi: SushiSwap Zap In3 MATIC0.016422395725 61.36437621
0xd5821c2a402ac6cafb772efd0f6568915251299dccdbcc8085f809a95af368c3Zap In298631942022-06-22 9:52:313 days 4 hrs ago0x109a69e3599b48baba48dc8cfaca6f7e4bffeb5d IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.008440287812 30.069998763
0xc4a0b738e1d17424c27f3e0ec2500ca1a1cd1f2e524e9ba229dda297aa44f054Zap In298518062022-06-22 2:52:593 days 11 hrs ago0x109a69e3599b48baba48dc8cfaca6f7e4bffeb5d IN  Zapper.Fi: SushiSwap Zap In0 MATIC0.020333146202 34.919997326
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x422b0ba036513e6ee29bed1e5b823fbd76b4abd5769f56f5f6b2e32c15552533299748652022-06-25 8:29:495 hrs 46 mins ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy5 MATIC
0xa6f898b7b3347611369d351d0c392cf68e120407ff9b814326f4a2fbedf90f6f299748582022-06-25 8:29:355 hrs 46 mins ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token5 MATIC
0xcbb562d1e14ea6d114f65623f78bccb3fbd292c572e93735a244a6abc4e33bc2299698382022-06-25 4:54:149 hrs 22 mins ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy0.11 MATIC
0x1775a55aa4476ee095869b3ed9dfcbe48d21574851bc4937e72f371a542ee47b299468502022-06-24 13:50:091 day 26 mins ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy5 MATIC
0x371def2d26601642e640cfa41f7dc5aa6efe866c777e83998672ee9433384d69299468362022-06-24 13:49:411 day 26 mins ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token5 MATIC
0x88f20743f44b1938048609de71e9e885420f8d1d35dd269399ef8ca86b8fa8e3299270692022-06-24 1:26:391 day 12 hrs ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token0.4 MATIC
0x1c3e672d93d0c89c56c8f7d880d0da84e05b1086aa8a3b2394d6d9d04729f685299270432022-06-24 1:24:551 day 12 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy1 MATIC
0x2524dd29da81e745ab243d9158b70ceadae75b1c0bc9bb7ef072875aad9d9ef3299269232022-06-24 1:20:391 day 12 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy1 MATIC
0xc98759bee644e56cfbc40f93fdd4a374fb09f4d948350c934173e31a8faedbd6299269032022-06-24 1:19:551 day 12 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy1 MATIC
0x0a3020da128adb7973e5bec528230a1e4b9cc535968cc941d6ab00dbee6a8330299131282022-06-23 16:47:471 day 21 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy5 MATIC
0xd531048bf962cb04b5db498e5753085e551ea6ab4db74f1fa5fa3a1bc31c166c299130292022-06-23 16:44:251 day 21 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy5 MATIC
0x5a046d4c0a3690ffb1a28797d91f68b8a66fc6ccc5148debf702cd06c1be6d30299121882022-06-23 16:13:191 day 22 hrs ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token80 MATIC
0xc943fefb1c6f1ddcfa460fdb1c015ac56e36d4e0dc784edb29dd134956bcdf3c298737282022-06-22 16:33:152 days 21 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy3 MATIC
0x846e6aff336982878d6fac89238f39304609a28e5b8b9cd7b04a336b2e4762b5298737142022-06-22 16:32:432 days 21 hrs ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token3 MATIC
0x1b398705d9cb35c671eb854d6d5d0d6668274247684f7fb43492084082fbd037298513532022-06-22 2:36:093 days 11 hrs ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token300 MATIC
0x3f5be05f2b4c74f26a5081720d67d8e3536f31307bc93b4b0e350dc6122cea33298470812022-06-22 0:03:223 days 14 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy300 MATIC
0xdd19b7e2d8957efaf665502d4c661167d2baf9f07528ad3368e4e6d42356cc9d298342722022-06-21 16:13:293 days 22 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy5 MATIC
0xb96e9bba353ddf3763a9ffd375b17ac9882b799eb02613fe47b7fc4aa9a0e444298342502022-06-21 16:12:453 days 22 hrs ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token5 MATIC
0x71d92a32baa7e188f0217ae12d3ad65317955876140310064568e5289ddd549e298056502022-06-20 22:18:364 days 15 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy1 MATIC
0xdb8144929da36cd06affe9b24ada199641431ae2aad87ff6ad62440ede614765298056262022-06-20 22:17:444 days 15 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy1 MATIC
0x91c19f7c47d9319ed5bc260edd152c4443392b6fef55f707284d09ad340a34ac297976642022-06-20 16:44:194 days 21 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy5 MATIC
0x47cf5f9db4ceaa468d638db59f75a94a58a8aa0b1523f85cf26ab5058b1fee35297976572022-06-20 16:44:054 days 21 hrs ago Zapper.Fi: SushiSwap Zap In Polygon: WMATIC Token5 MATIC
0xb2c320f6c20a1926b43879e143fb8b88cd05e1f1de57239f5a63bcbd153f754e297897282022-06-20 11:39:145 days 2 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy0.1 MATIC
0xd08e4bb117fe20e455ff6626cd6681029d8869f8d1bb8916a4580fb1cb085c67297667422022-06-19 20:58:535 days 17 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy9 MATIC
0x09afdda3dabada7c6a53d9a9b367e9f2922dbd5edb7d01ae6c729ed3f133f748297667422022-06-19 20:58:535 days 17 hrs ago Zapper.Fi: SushiSwap Zap In 0x: Exchange Proxy9 MATIC
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Sushiswap_ZapIn_Polygon_V3

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, GNU GPLv2 license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 24 : ZapBaseV2.sol
// SPDX-License-Identifier: GPL-2.0
pragma solidity ^0.8.0;

import "../oz/0.8.0/access/Ownable.sol";
import "../oz/0.8.0/token/ERC20/utils/SafeERC20.sol";

abstract contract ZapBaseV2 is Ownable {
    using SafeERC20 for IERC20;
    bool public stopped = false;

    // if true, goodwill is not deducted
    mapping(address => bool) public feeWhitelist;

    uint256 public goodwill;
    // % share of goodwill (0-100 %)
    uint256 affiliateSplit;
    // restrict affiliates
    mapping(address => bool) public affiliates;
    // affiliate => token => amount
    mapping(address => mapping(address => uint256)) public affiliateBalance;
    // token => amount
    mapping(address => uint256) public totalAffiliateBalance;
    // swapTarget => approval status
    mapping(address => bool) public approvedTargets;

    address internal constant ETHAddress =
        0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    constructor(uint256 _goodwill, uint256 _affiliateSplit) {
        goodwill = _goodwill;
        affiliateSplit = _affiliateSplit;
    }

    // circuit breaker modifiers
    modifier stopInEmergency {
        if (stopped) {
            revert("Temporarily Paused");
        } else {
            _;
        }
    }

    function _getBalance(address token)
        internal
        view
        returns (uint256 balance)
    {
        if (token == address(0)) {
            balance = address(this).balance;
        } else {
            balance = IERC20(token).balanceOf(address(this));
        }
    }

    function _approveToken(address token, address spender) internal {
        IERC20 _token = IERC20(token);
        if (_token.allowance(address(this), spender) > 0) return;
        else {
            _token.safeApprove(spender, type(uint256).max);
        }
    }

    function _approveToken(
        address token,
        address spender,
        uint256 amount
    ) internal {
        IERC20(token).safeApprove(spender, 0);
        IERC20(token).safeApprove(spender, amount);
    }

    // - to Pause the contract
    function toggleContractActive() public onlyOwner {
        stopped = !stopped;
    }

    function set_feeWhitelist(address zapAddress, bool status)
        external
        onlyOwner
    {
        feeWhitelist[zapAddress] = status;
    }

    function set_new_goodwill(uint256 _new_goodwill) public onlyOwner {
        require(
            _new_goodwill >= 0 && _new_goodwill <= 100,
            "GoodWill Value not allowed"
        );
        goodwill = _new_goodwill;
    }

    function set_new_affiliateSplit(uint256 _new_affiliateSplit)
        external
        onlyOwner
    {
        require(
            _new_affiliateSplit <= 100,
            "Affiliate Split Value not allowed"
        );
        affiliateSplit = _new_affiliateSplit;
    }

    function set_affiliate(address _affiliate, bool _status)
        external
        onlyOwner
    {
        affiliates[_affiliate] = _status;
    }

    ///@notice Withdraw goodwill share, retaining affilliate share
    function withdrawTokens(address[] calldata tokens) external onlyOwner {
        for (uint256 i = 0; i < tokens.length; i++) {
            uint256 qty;

            if (tokens[i] == ETHAddress) {
                qty = address(this).balance - totalAffiliateBalance[tokens[i]];

                Address.sendValue(payable(owner()), qty);
            } else {
                qty =
                    IERC20(tokens[i]).balanceOf(address(this)) -
                    totalAffiliateBalance[tokens[i]];
                IERC20(tokens[i]).safeTransfer(owner(), qty);
            }
        }
    }

    ///@notice Withdraw affilliate share, retaining goodwill share
    function affilliateWithdraw(address[] calldata tokens) external {
        uint256 tokenBal;
        for (uint256 i = 0; i < tokens.length; i++) {
            tokenBal = affiliateBalance[msg.sender][tokens[i]];
            affiliateBalance[msg.sender][tokens[i]] = 0;
            totalAffiliateBalance[tokens[i]] =
                totalAffiliateBalance[tokens[i]] -
                tokenBal;

            if (tokens[i] == ETHAddress) {
                Address.sendValue(payable(msg.sender), tokenBal);
            } else {
                IERC20(tokens[i]).safeTransfer(msg.sender, tokenBal);
            }
        }
    }

    function setApprovedTargets(
        address[] calldata targets,
        bool[] calldata isApproved
    ) external onlyOwner {
        require(targets.length == isApproved.length, "Invalid Input length");

        for (uint256 i = 0; i < targets.length; i++) {
            approvedTargets[targets[i]] = isApproved[i];
        }
    }

    receive() external payable {
        require(msg.sender != tx.origin, "Do not send ETH directly");
    }
}

File 2 of 24 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(
            newOwner != address(0),
            "Ownable: new owner is the zero address"
        );
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

File 3 of 24 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(token.transfer.selector, to, value)
        );
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(token.transferFrom.selector, from, to, value)
        );
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(token.approve.selector, spender, value)
        );
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(
                token.approve.selector,
                spender,
                newAllowance
            )
        );
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(
                oldAllowance >= value,
                "SafeERC20: decreased allowance below zero"
            );
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(
                token,
                abi.encodeWithSelector(
                    token.approve.selector,
                    spender,
                    newAllowance
                )
            );
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata =
            address(token).functionCall(
                data,
                "SafeERC20: low-level call failed"
            );
        if (returndata.length > 0) {
            // Return data is optional
            // solhint-disable-next-line max-line-length
            require(
                abi.decode(returndata, (bool)),
                "SafeERC20: ERC20 operation did not succeed"
            );
        }
    }
}

File 4 of 24 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

File 5 of 24 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount)
        external
        returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
}

File 6 of 24 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(
            address(this).balance >= amount,
            "Address: insufficient balance"
        );

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(
            success,
            "Address: unable to send value, recipient may have reverted"
        );
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data)
        internal
        returns (bytes memory)
    {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return
            functionCallWithValue(
                target,
                data,
                value,
                "Address: low-level call with value failed"
            );
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(
            address(this).balance >= value,
            "Address: insufficient balance for call"
        );
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) =
            target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data)
        internal
        view
        returns (bytes memory)
    {
        return
            functionStaticCall(
                target,
                data,
                "Address: low-level static call failed"
            );
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data)
        internal
        returns (bytes memory)
    {
        return
            functionDelegateCall(
                target,
                data,
                "Address: low-level delegate call failed"
            );
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) private pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 7 of 24 : Zapper_Matic_Bridge_V1.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//

///@author Zapper
///@notice This contract swaps and bridges ETH/Tokens to Matic/Polygon
// SPDX-License-Identifier: GPLv2

pragma solidity ^0.8.0;

import "../../_base/ZapBaseV2.sol";

// PoS Bridge
interface IRootChainManager {
    function depositEtherFor(address user) external payable;

    function depositFor(
        address user,
        address rootToken,
        bytes calldata depositData
    ) external;

    function tokenToType(address) external returns (bytes32);

    function typeToPredicate(bytes32) external returns (address);
}

// Plasma Bridge
interface IDepositManager {
    function depositERC20ForUser(
        address _token,
        address _user,
        uint256 _amount
    ) external;
}

interface IWETH {
    function deposit() external payable;
}

contract Zapper_Matic_Bridge_V1_1 is ZapBaseV2 {
    using SafeERC20 for IERC20;

    address private constant wethTokenAddress =
        0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    IRootChainManager public rootChainManager =
        IRootChainManager(0xA0c68C638235ee32657e8f720a23ceC1bFc77C77);
    IDepositManager public depositManager =
        IDepositManager(0x401F6c983eA34274ec46f84D70b31C151321188b);

    address private constant maticAddress =
        0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0;

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        _approveToken(maticAddress, address(depositManager));

        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    /**
    @notice Bridge from Ethereum to Matic
    @notice Use index 0 for primary swap and index 1 for matic swap
    @param fromToken Address of the token to swap from
    @param toToken Address of the token to bridge
    @param swapAmounts Quantites of fromToken to swap to toToken and matic
    @param minTokensRec Minimum acceptable quantity of swapped tokens and/or matic
    @param swapTargets Execution targets for swaps
    @param swapData DEX swap data
    @param affiliate Affiliate address
    */
    function ZapBridge(
        address fromToken,
        address toToken,
        uint256[2] calldata swapAmounts,
        uint256[2] calldata minTokensRec,
        address[2] calldata swapTargets,
        bytes[2] calldata swapData,
        address affiliate
    ) external payable stopInEmergency {
        uint256[2] memory toInvest =
            _pullTokens(fromToken, swapAmounts, affiliate);

        if (swapAmounts[0] > 0) {
            // Token swap
            uint256 toTokenAmt =
                _fillQuote(
                    fromToken,
                    toInvest[0],
                    toToken,
                    swapTargets[0],
                    swapData[0]
                );
            require(toTokenAmt >= minTokensRec[0], "ERR: High Slippage 1");

            _bridgeToken(toToken, toTokenAmt);
        }

        // Matic swap
        if (swapAmounts[1] > 0) {
            uint256 maticAmount =
                _fillQuote(
                    fromToken,
                    toInvest[1],
                    maticAddress,
                    swapTargets[1],
                    swapData[1]
                );
            require(maticAmount >= minTokensRec[1], "ERR: High Slippage 2");

            _bridgeMatic(maticAmount);
        }
    }

    function _bridgeToken(address toToken, uint256 toTokenAmt) internal {
        if (toToken == address(0)) {
            rootChainManager.depositEtherFor{ value: toTokenAmt }(msg.sender);
        } else {
            bytes32 tokenType = rootChainManager.tokenToType(toToken);
            address predicate = rootChainManager.typeToPredicate(tokenType);
            _approveToken(toToken, predicate);
            rootChainManager.depositFor(
                msg.sender,
                toToken,
                abi.encode(toTokenAmt)
            );
        }
    }

    function _bridgeMatic(uint256 maticAmount) internal {
        depositManager.depositERC20ForUser(
            maticAddress,
            msg.sender,
            maticAmount
        );
    }

    // 0x Swap
    function _fillQuote(
        address fromToken,
        uint256 amount,
        address toToken,
        address swapTarget,
        bytes memory swapCallData
    ) internal returns (uint256 amtBought) {
        if (fromToken == wethTokenAddress && toToken == address(0)) {
            IWETH(wethTokenAddress).deposit{ value: amount }();
            return amount;
        }

        uint256 valueToSend;

        if (fromToken == toToken) {
            return amount;
        }

        if (fromToken == address(0)) {
            valueToSend = amount;
        } else {
            _approveToken(fromToken, swapTarget);
        }

        uint256 iniBal = _getBalance(toToken);
        require(approvedTargets[swapTarget], "Target not Authorized");
        (bool success, ) = swapTarget.call{ value: valueToSend }(swapCallData);
        require(success, "Error Swapping Tokens");
        uint256 finalBal = _getBalance(toToken);

        amtBought = finalBal - iniBal;
    }

    function _pullTokens(
        address fromToken,
        uint256[2] memory swapAmounts,
        address affiliate
    ) internal returns (uint256[2] memory toInvest) {
        if (fromToken == address(0)) {
            require(msg.value > 0, "No eth sent");
            require(
                swapAmounts[0] + (swapAmounts[1]) == msg.value,
                "msg.value != fromTokenAmounts"
            );
        } else {
            require(msg.value == 0, "Eth sent with token");

            // transfer token
            IERC20(fromToken).safeTransferFrom(
                msg.sender,
                address(this),
                swapAmounts[0] + (swapAmounts[1])
            );
        }

        if (swapAmounts[0] > 0) {
            toInvest[0] =
                swapAmounts[0] -
                (_subtractGoodwill(fromToken, swapAmounts[0], affiliate));
        }

        if (swapAmounts[1] > 0) {
            toInvest[1] =
                swapAmounts[1] -
                (_subtractGoodwill(fromToken, swapAmounts[1], affiliate));
        }
    }

    function _subtractGoodwill(
        address token,
        uint256 amount,
        address affiliate
    ) internal returns (uint256 totalGoodwillPortion) {
        bool whitelisted = feeWhitelist[msg.sender];
        if (!whitelisted && goodwill > 0) {
            totalGoodwillPortion = (amount * goodwill) / 10000;

            if (affiliates[affiliate]) {
                if (token == address(0)) {
                    token = ETHAddress;
                }

                uint256 affiliatePortion =
                    (totalGoodwillPortion * affiliateSplit) / 100;
                affiliateBalance[affiliate][token] += affiliatePortion;
                totalAffiliateBalance[token] += affiliatePortion;
            }
        }
    }
}

File 8 of 24 : ZapOutBaseV3.sol
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "./ZapBaseV2.sol";

abstract contract ZapOutBaseV3 is ZapBaseV2 {
    using SafeERC20 for IERC20;

    /**
        @dev Transfer tokens from msg.sender to this contract
        @param token The ERC20 token to transfer to this contract
        @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
        @return Quantity of tokens transferred to this contract
     */
    function _pullTokens(
        address token,
        uint256 amount,
        bool shouldSellEntireBalance
    ) internal returns (uint256) {
        if (shouldSellEntireBalance) {
            require(
                Address.isContract(msg.sender),
                "ERR: shouldSellEntireBalance is true for EOA"
            );

            uint256 allowance =
                IERC20(token).allowance(msg.sender, address(this));
            IERC20(token).safeTransferFrom(
                msg.sender,
                address(this),
                allowance
            );

            return allowance;
        } else {
            IERC20(token).safeTransferFrom(msg.sender, address(this), amount);

            return amount;
        }
    }

    function _subtractGoodwill(
        address token,
        uint256 amount,
        address affiliate,
        bool enableGoodwill
    ) internal returns (uint256 totalGoodwillPortion) {
        bool whitelisted = feeWhitelist[msg.sender];
        if (enableGoodwill && !whitelisted && goodwill > 0) {
            totalGoodwillPortion = (amount * goodwill) / 10000;

            if (affiliates[affiliate]) {
                if (token == address(0)) {
                    token = ETHAddress;
                }

                uint256 affiliatePortion =
                    (totalGoodwillPortion * affiliateSplit) / 100;
                affiliateBalance[affiliate][token] += affiliatePortion;
                totalAffiliateBalance[token] += affiliatePortion;
            }
        }
    }
}

File 9 of 24 : UniswapV2_ZapOut_General_V4.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// Visit <https://www.gnu.org/licenses/>for a copy of the GNU Affero General Public License

///@author Zapper
///@notice this contract implements one click removal of liquidity from UniswapV2 pools, receiving ETH, ERC20 or both.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../_base/ZapOutBaseV3.sol";

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

interface IUniswapV2Router02 {
    function WETH() external pure returns (address);

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function balanceOf(address user) external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

interface IWETH {
    function withdraw(uint256 wad) external;
}

contract UniswapV2_ZapOut_General_V4_0_1 is ZapOutBaseV3 {
    using SafeERC20 for IERC20;

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    IUniswapV2Router02 private constant uniswapV2Router =
        IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
    IUniswapV2Factory private constant uniswapFactory =
        IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);

    address private constant wethTokenAddress =
        address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapOut(
        address sender,
        address pool,
        address token,
        uint256 tokensRec
    );

    /**
        @notice Zap out in both tokens
        @param fromPoolAddress Pool from which to remove liquidity
        @param incomingLP Quantity of LP to remove from pool
        @param affiliate Affiliate address
        @return amountA Quantity of tokenA received after zapout
        @return amountB Quantity of tokenB received after zapout
    */
    function ZapOut2PairToken(
        address fromPoolAddress,
        uint256 incomingLP,
        address affiliate
    ) public stopInEmergency returns (uint256 amountA, uint256 amountB) {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);

        require(address(pair) != address(0), "Pool Cannot be Zero Address");

        // get reserves
        address token0 = pair.token0();
        address token1 = pair.token1();

        IERC20(fromPoolAddress).safeTransferFrom(
            msg.sender,
            address(this),
            incomingLP
        );

        _approveToken(fromPoolAddress, address(uniswapV2Router), incomingLP);

        if (token0 == wethTokenAddress || token1 == wethTokenAddress) {
            address _token = token0 == wethTokenAddress ? token1 : token0;
            (amountA, amountB) = uniswapV2Router.removeLiquidityETH(
                _token,
                incomingLP,
                1,
                1,
                address(this),
                deadline
            );

            // subtract goodwill
            uint256 tokenGoodwill =
                _subtractGoodwill(_token, amountA, affiliate, true);
            uint256 ethGoodwill =
                _subtractGoodwill(ETHAddress, amountB, affiliate, true);

            // send tokens
            IERC20(_token).safeTransfer(msg.sender, amountA - tokenGoodwill);
            Address.sendValue(payable(msg.sender), amountB - ethGoodwill);
        } else {
            (amountA, amountB) = uniswapV2Router.removeLiquidity(
                token0,
                token1,
                incomingLP,
                1,
                1,
                address(this),
                deadline
            );

            // subtract goodwill
            uint256 tokenAGoodwill =
                _subtractGoodwill(token0, amountA, affiliate, true);
            uint256 tokenBGoodwill =
                _subtractGoodwill(token1, amountB, affiliate, true);

            // send tokens
            IERC20(token0).safeTransfer(msg.sender, amountA - tokenAGoodwill);
            IERC20(token1).safeTransfer(msg.sender, amountB - tokenBGoodwill);
        }
        emit zapOut(msg.sender, fromPoolAddress, token0, amountA);
        emit zapOut(msg.sender, fromPoolAddress, token1, amountB);
    }

    /**
        @notice Zap out in a single token
        @param toTokenAddress Address of desired token
        @param fromPoolAddress Pool from which to remove liquidity
        @param incomingLP Quantity of LP to remove from pool
        @param minTokensRec Minimum quantity of tokens to receive
        @param swapTargets Execution targets for swaps
        @param swapData DEX swap data
        @param affiliate Affiliate address
        @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    */
    function ZapOut(
        address toTokenAddress,
        address fromPoolAddress,
        uint256 incomingLP,
        uint256 minTokensRec,
        address[] memory swapTargets,
        bytes[] memory swapData,
        address affiliate,
        bool shouldSellEntireBalance
    ) public stopInEmergency returns (uint256 tokensRec) {
        (uint256 amount0, uint256 amount1) =
            _removeLiquidity(
                fromPoolAddress,
                incomingLP,
                shouldSellEntireBalance
            );

        //swaps tokens to token
        tokensRec = _swapTokens(
            fromPoolAddress,
            amount0,
            amount1,
            toTokenAddress,
            swapTargets,
            swapData
        );
        require(tokensRec >= minTokensRec, "High Slippage");

        uint256 totalGoodwillPortion;

        // transfer toTokens to sender
        if (toTokenAddress == address(0)) {
            totalGoodwillPortion = _subtractGoodwill(
                ETHAddress,
                tokensRec,
                affiliate,
                true
            );

            payable(msg.sender).transfer(tokensRec - totalGoodwillPortion);
        } else {
            totalGoodwillPortion = _subtractGoodwill(
                toTokenAddress,
                tokensRec,
                affiliate,
                true
            );

            IERC20(toTokenAddress).safeTransfer(
                msg.sender,
                tokensRec - totalGoodwillPortion
            );
        }

        tokensRec = tokensRec - totalGoodwillPortion;

        emit zapOut(msg.sender, fromPoolAddress, toTokenAddress, tokensRec);

        return tokensRec;
    }

    /**
        @notice Zap out in both tokens with permit
        @param fromPoolAddress Pool from which to remove liquidity
        @param incomingLP Quantity of LP to remove from pool
        @param affiliate Affiliate address to share fees
        @param permitData Encoded permit data, which contains owner, spender, value, deadline, r,s,v values 
        @return amountA Quantity of tokenA received
        @return amountB Quantity of tokenB received
    */
    function ZapOut2PairTokenWithPermit(
        address fromPoolAddress,
        uint256 incomingLP,
        address affiliate,
        bytes calldata permitData
    ) external stopInEmergency returns (uint256 amountA, uint256 amountB) {
        // permit
        _validatePool(fromPoolAddress);
        (bool success, ) = fromPoolAddress.call(permitData);
        require(success, "Could Not Permit");

        (amountA, amountB) = ZapOut2PairToken(
            fromPoolAddress,
            incomingLP,
            affiliate
        );
    }

    /**
        @notice Zap out in a single token with permit
        @param toTokenAddress Address of desired token
        @param fromPoolAddress Pool from which to remove liquidity
        @param incomingLP Quantity of LP to remove from pool
        @param minTokensRec Minimum quantity of tokens to receive
        @param swapTargets Execution targets for swaps
        @param swapData DEX swap data
        @param affiliate Affiliate address
    */
    function ZapOutWithPermit(
        address toTokenAddress,
        address fromPoolAddress,
        uint256 incomingLP,
        uint256 minTokensRec,
        bytes memory permitData,
        address[] memory swapTargets,
        bytes[] memory swapData,
        address affiliate
    ) public stopInEmergency returns (uint256) {
        // permit
        _validatePool(fromPoolAddress);
        (bool success, ) = fromPoolAddress.call(permitData);
        require(success, "Could Not Permit");

        return (
            ZapOut(
                toTokenAddress,
                fromPoolAddress,
                incomingLP,
                minTokensRec,
                swapTargets,
                swapData,
                affiliate,
                false
            )
        );
    }

    function _validatePool(address poolAddress) internal view {
        IUniswapV2Pair pair = IUniswapV2Pair(poolAddress);
        address token0 = pair.token0();
        address token1 = pair.token1();

        address retrievedAddress = uniswapFactory.getPair(token0, token1);

        require(retrievedAddress == poolAddress, "Invalid Pool Address");
    }

    function _removeLiquidity(
        address fromPoolAddress,
        uint256 incomingLP,
        bool shouldSellEntireBalance
    ) internal returns (uint256 amount0, uint256 amount1) {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);

        require(address(pair) != address(0), "Pool Cannot be Zero Address");

        address token0 = pair.token0();
        address token1 = pair.token1();

        _pullTokens(fromPoolAddress, incomingLP, shouldSellEntireBalance);

        _approveToken(fromPoolAddress, address(uniswapV2Router), incomingLP);

        (amount0, amount1) = uniswapV2Router.removeLiquidity(
            token0,
            token1,
            incomingLP,
            1,
            1,
            address(this),
            deadline
        );
        require(amount0 > 0 && amount1 > 0, "Removed Insufficient Liquidity");
    }

    function _swapTokens(
        address fromPoolAddress,
        uint256 amount0,
        uint256 amount1,
        address toToken,
        address[] memory swapTargets,
        bytes[] memory swapData
    ) internal returns (uint256 tokensBought) {
        address token0 = IUniswapV2Pair(fromPoolAddress).token0();
        address token1 = IUniswapV2Pair(fromPoolAddress).token1();

        //swap token0 to toToken
        if (token0 == toToken) {
            tokensBought = tokensBought + amount0;
        } else {
            //swap token using 0x swap
            tokensBought =
                tokensBought +
                _fillQuote(
                    token0,
                    toToken,
                    amount0,
                    swapTargets[0],
                    swapData[0]
                );
        }

        //swap token1 to toToken
        if (token1 == toToken) {
            tokensBought = tokensBought + amount1;
        } else {
            //swap token using 0x swap
            tokensBought =
                tokensBought +
                _fillQuote(
                    token1,
                    toToken,
                    amount1,
                    swapTargets[1],
                    swapData[1]
                );
        }
    }

    function _fillQuote(
        address fromTokenAddress,
        address toToken,
        uint256 amount,
        address swapTarget,
        bytes memory swapData
    ) internal returns (uint256) {
        if (fromTokenAddress == wethTokenAddress && toToken == address(0)) {
            IWETH(wethTokenAddress).withdraw(amount);
            return amount;
        }

        uint256 valueToSend;
        if (fromTokenAddress == address(0)) {
            valueToSend = amount;
        } else {
            _approveToken(fromTokenAddress, swapTarget, amount);
        }

        uint256 initialBalance = _getBalance(toToken);

        require(approvedTargets[swapTarget], "Target not Authorized");
        (bool success, ) = swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens");

        uint256 finalBalance = _getBalance(toToken) - initialBalance;

        require(finalBalance > 0, "Swapped to Invalid Intermediate");

        return finalBalance;
    }

    /**
        @notice Utility function to determine quantity and addresses of tokens being removed
        @param fromPoolAddress Pool from which to remove liquidity
        @param liquidity Quantity of LP tokens to remove.
        @return amountA Quantity of tokenA removed
        @return amountB Quantity of tokenB removed
        @return token0 Address of the underlying token to be removed
        @return token1 Address of the underlying token to be removed
    */
    function removeLiquidityReturn(address fromPoolAddress, uint256 liquidity)
        external
        view
        returns (
            uint256 amountA,
            uint256 amountB,
            address token0,
            address token1
        )
    {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);
        token0 = pair.token0();
        token1 = pair.token1();

        uint256 balance0 = IERC20(token0).balanceOf(fromPoolAddress);
        uint256 balance1 = IERC20(token1).balanceOf(fromPoolAddress);

        uint256 _totalSupply = pair.totalSupply();

        amountA = (liquidity * balance0) / _totalSupply;
        amountB = (liquidity * balance1) / _totalSupply;
    }
}

File 10 of 24 : Sushiswap_ZapOut_General_V3.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// Visit <https://www.gnu.org/licenses/>for a copy of the GNU Affero General Public License

///@author Zapper
///@notice this contract implements one click removal of liquidity from Sushiswap pools, receiving ETH, ERC20 or both.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../_base/ZapOutBaseV3.sol";

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

interface IUniswapV2Router02 {
    function WETH() external pure returns (address);

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function balanceOf(address user) external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

interface IWETH {
    function withdraw(uint256 wad) external;
}

contract Sushiswap_ZapOut_General_V3 is ZapOutBaseV3 {
    using SafeERC20 for IERC20;

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    IUniswapV2Router02 private constant sushiswapRouter =
        IUniswapV2Router02(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);
    IUniswapV2Factory private constant sushiswapFactory =
        IUniswapV2Factory(0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac);

    address private constant wethTokenAddress =
        address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapOut(
        address sender,
        address pool,
        address token,
        uint256 tokensRec
    );

    /**
        @notice Zap out in both tokens
        @param fromPoolAddress Pool from which to remove liquidity
        @param incomingLP Quantity of LP to remove from pool
        @param affiliate Affiliate address
        @return amountA Quantity of tokenA received after zapout
        @return amountB Quantity of tokenB received after zapout
    */
    function ZapOut2PairToken(
        address fromPoolAddress,
        uint256 incomingLP,
        address affiliate
    ) public stopInEmergency returns (uint256 amountA, uint256 amountB) {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);

        require(address(pair) != address(0), "Pool Cannot be Zero Address");

        // get reserves
        address token0 = pair.token0();
        address token1 = pair.token1();

        IERC20(fromPoolAddress).safeTransferFrom(
            msg.sender,
            address(this),
            incomingLP
        );

        _approveToken(fromPoolAddress, address(sushiswapRouter), incomingLP);

        if (token0 == wethTokenAddress || token1 == wethTokenAddress) {
            address _token = token0 == wethTokenAddress ? token1 : token0;
            (amountA, amountB) = sushiswapRouter.removeLiquidityETH(
                _token,
                incomingLP,
                1,
                1,
                address(this),
                deadline
            );

            // subtract goodwill
            uint256 tokenGoodwill =
                _subtractGoodwill(_token, amountA, affiliate, true);
            uint256 ethGoodwill =
                _subtractGoodwill(ETHAddress, amountB, affiliate, true);

            // send tokens
            IERC20(_token).safeTransfer(msg.sender, amountA - tokenGoodwill);
            Address.sendValue(payable(msg.sender), amountB - ethGoodwill);
        } else {
            (amountA, amountB) = sushiswapRouter.removeLiquidity(
                token0,
                token1,
                incomingLP,
                1,
                1,
                address(this),
                deadline
            );

            // subtract goodwill
            uint256 tokenAGoodwill =
                _subtractGoodwill(token0, amountA, affiliate, true);
            uint256 tokenBGoodwill =
                _subtractGoodwill(token1, amountB, affiliate, true);

            // send tokens
            IERC20(token0).safeTransfer(msg.sender, amountA - tokenAGoodwill);
            IERC20(token1).safeTransfer(msg.sender, amountB - tokenBGoodwill);
        }
        emit zapOut(msg.sender, fromPoolAddress, token0, amountA);
        emit zapOut(msg.sender, fromPoolAddress, token1, amountB);
    }

    /**
    @notice Zap out in a single token
    @param toTokenAddress Address of desired token
    @param fromPoolAddress Pool from which to remove liquidity
    @param incomingLP Quantity of LP to remove from pool
    @param minTokensRec Minimum quantity of tokens to receive
    @param swapTargets Execution targets for swaps
    @param swapData DEX swap data
    @param affiliate Affiliate address
    @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    */
    function ZapOut(
        address toTokenAddress,
        address fromPoolAddress,
        uint256 incomingLP,
        uint256 minTokensRec,
        address[] memory swapTargets,
        bytes[] memory swapData,
        address affiliate,
        bool shouldSellEntireBalance
    ) public stopInEmergency returns (uint256 tokensRec) {
        (uint256 amount0, uint256 amount1) =
            _removeLiquidity(
                fromPoolAddress,
                incomingLP,
                shouldSellEntireBalance
            );

        //swaps tokens to token
        tokensRec = _swapTokens(
            fromPoolAddress,
            amount0,
            amount1,
            toTokenAddress,
            swapTargets,
            swapData
        );
        require(tokensRec >= minTokensRec, "High Slippage");

        uint256 totalGoodwillPortion;

        // transfer toTokens to sender
        if (toTokenAddress == address(0)) {
            totalGoodwillPortion = _subtractGoodwill(
                ETHAddress,
                tokensRec,
                affiliate,
                true
            );

            payable(msg.sender).transfer(tokensRec - totalGoodwillPortion);
        } else {
            totalGoodwillPortion = _subtractGoodwill(
                toTokenAddress,
                tokensRec,
                affiliate,
                true
            );

            IERC20(toTokenAddress).safeTransfer(
                msg.sender,
                tokensRec - totalGoodwillPortion
            );
        }

        tokensRec = tokensRec - totalGoodwillPortion;

        emit zapOut(msg.sender, fromPoolAddress, toTokenAddress, tokensRec);

        return tokensRec;
    }

    /**
    @notice Zap out in both tokens with permit
    @param fromPoolAddress Pool from which to remove liquidity
    @param incomingLP Quantity of LP to remove from pool
    @param affiliate Affiliate address to share fees
    @param permitData Encoded permit data, which contains owner, spender, value, deadline, r,s,v values 
    @return amountA Quantity of tokenA received
    @return amountB Quantity of tokenB received
    */
    function ZapOut2PairTokenWithPermit(
        address fromPoolAddress,
        uint256 incomingLP,
        address affiliate,
        bytes calldata permitData
    ) external stopInEmergency returns (uint256 amountA, uint256 amountB) {
        // permit
        _validatePool(fromPoolAddress);
        (bool success, ) = fromPoolAddress.call(permitData);
        require(success, "Could Not Permit");

        (amountA, amountB) = ZapOut2PairToken(
            fromPoolAddress,
            incomingLP,
            affiliate
        );
    }

    /**
    @notice Zap out in a single token with permit
    @param toTokenAddress Address of desired token
    @param fromPoolAddress Pool from which to remove liquidity
    @param incomingLP Quantity of LP to remove from pool
    @param minTokensRec Minimum quantity of tokens to receive
    @param swapTargets Execution targets for swaps
    @param swapData DEX swap data
    @param affiliate Affiliate address
    */
    function ZapOutWithPermit(
        address toTokenAddress,
        address fromPoolAddress,
        uint256 incomingLP,
        uint256 minTokensRec,
        bytes memory permitData,
        address[] memory swapTargets,
        bytes[] memory swapData,
        address affiliate
    ) public stopInEmergency returns (uint256) {
        // permit
        _validatePool(fromPoolAddress);
        (bool success, ) = fromPoolAddress.call(permitData);
        require(success, "Could Not Permit");

        return (
            ZapOut(
                toTokenAddress,
                fromPoolAddress,
                incomingLP,
                minTokensRec,
                swapTargets,
                swapData,
                affiliate,
                false
            )
        );
    }

    function _validatePool(address poolAddress) internal view {
        IUniswapV2Pair pair = IUniswapV2Pair(poolAddress);
        address token0 = pair.token0();
        address token1 = pair.token1();

        address retrievedAddress = sushiswapFactory.getPair(token0, token1);

        require(retrievedAddress == poolAddress, "Invalid Pool Address");
    }

    function _removeLiquidity(
        address fromPoolAddress,
        uint256 incomingLP,
        bool shouldSellEntireBalance
    ) internal returns (uint256 amount0, uint256 amount1) {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);

        require(address(pair) != address(0), "Pool Cannot be Zero Address");

        address token0 = pair.token0();
        address token1 = pair.token1();

        _pullTokens(fromPoolAddress, incomingLP, shouldSellEntireBalance);

        _approveToken(fromPoolAddress, address(sushiswapRouter), incomingLP);

        (amount0, amount1) = sushiswapRouter.removeLiquidity(
            token0,
            token1,
            incomingLP,
            1,
            1,
            address(this),
            deadline
        );
        require(amount0 > 0 && amount1 > 0, "Removed Insufficient Liquidity");
    }

    function _swapTokens(
        address fromPoolAddress,
        uint256 amount0,
        uint256 amount1,
        address toToken,
        address[] memory swapTargets,
        bytes[] memory swapData
    ) internal returns (uint256 tokensBought) {
        address token0 = IUniswapV2Pair(fromPoolAddress).token0();
        address token1 = IUniswapV2Pair(fromPoolAddress).token1();

        //swap token0 to toToken
        if (token0 == toToken) {
            tokensBought = tokensBought + amount0;
        } else {
            //swap token using 0x swap
            tokensBought =
                tokensBought +
                _fillQuote(
                    token0,
                    toToken,
                    amount0,
                    swapTargets[0],
                    swapData[0]
                );
        }

        //swap token1 to toToken
        if (token1 == toToken) {
            tokensBought = tokensBought + amount1;
        } else {
            //swap token using 0x swap
            tokensBought =
                tokensBought +
                _fillQuote(
                    token1,
                    toToken,
                    amount1,
                    swapTargets[1],
                    swapData[1]
                );
        }
    }

    function _fillQuote(
        address fromTokenAddress,
        address toToken,
        uint256 amount,
        address swapTarget,
        bytes memory swapData
    ) internal returns (uint256) {
        if (fromTokenAddress == wethTokenAddress && toToken == address(0)) {
            IWETH(wethTokenAddress).withdraw(amount);
            return amount;
        }

        uint256 valueToSend;
        if (fromTokenAddress == address(0)) {
            valueToSend = amount;
        } else {
            _approveToken(fromTokenAddress, swapTarget, amount);
        }

        uint256 initialBalance = _getBalance(toToken);

        require(approvedTargets[swapTarget], "Target not Authorized");
        (bool success, ) = swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens");

        uint256 finalBalance = _getBalance(toToken) - initialBalance;

        require(finalBalance > 0, "Swapped to Invalid Intermediate");

        return finalBalance;
    }

    /**
        @notice Utility function to determine quantity and addresses of tokens being removed
        @param fromPoolAddress Pool from which to remove liquidity
        @param liquidity Quantity of LP tokens to remove.
        @return amountA Quantity of tokenA removed
        @return amountB Quantity of tokenB removed
        @return token0 Address of the underlying token to be removed
        @return token1 Address of the underlying token to be removed
    */
    function removeLiquidityReturn(address fromPoolAddress, uint256 liquidity)
        external
        view
        returns (
            uint256 amountA,
            uint256 amountB,
            address token0,
            address token1
        )
    {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);
        token0 = pair.token0();
        token1 = pair.token1();

        uint256 balance0 = IERC20(token0).balanceOf(fromPoolAddress);
        uint256 balance1 = IERC20(token1).balanceOf(fromPoolAddress);

        uint256 _totalSupply = pair.totalSupply();

        amountA = (liquidity * balance0) / _totalSupply;
        amountB = (liquidity * balance1) / _totalSupply;
    }
}

File 11 of 24 : Sushiswap_ZapOut_Polygon_V2.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// Visit <https://www.gnu.org/licenses/>for a copy of the GNU Affero General Public License

///@author Zapper
///@notice this contract removes liquidity from Sushiswap pools on Polygon (Matic), receiving ETH, ERC20 or both.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../../_base/ZapOutBaseV3.sol";

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

interface IUniswapV2Router02 {
    function WETH() external pure returns (address);

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function balanceOf(address user) external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

interface IWETH {
    function withdraw(uint256 wad) external;
}

contract Sushiswap_ZapOut_Polygon_V2 is ZapOutBaseV3 {
    using SafeERC20 for IERC20;

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    IUniswapV2Router02 private constant sushiswapRouter =
        IUniswapV2Router02(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506);
    IUniswapV2Factory private constant sushiswapFactory =
        IUniswapV2Factory(0xc35DADB65012eC5796536bD9864eD8773aBc74C4);

    address private constant wmaticTokenAddress =
        address(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270);

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapOut(
        address sender,
        address pool,
        address token,
        uint256 tokensRec
    );

    /**
        @notice Zap out in both tokens
        @param fromPoolAddress Pool from which to remove liquidity
        @param incomingLP Quantity of LP to remove from pool
        @param affiliate Affiliate address
        @return amountA Quantity of tokenA received after zapout
        @return amountB Quantity of tokenB received after zapout
    */
    function ZapOut2PairToken(
        address fromPoolAddress,
        uint256 incomingLP,
        address affiliate
    ) public stopInEmergency returns (uint256 amountA, uint256 amountB) {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);

        require(address(pair) != address(0), "Pool Cannot be Zero Address");

        // get reserves
        address token0 = pair.token0();
        address token1 = pair.token1();

        IERC20(fromPoolAddress).safeTransferFrom(
            msg.sender,
            address(this),
            incomingLP
        );

        _approveToken(fromPoolAddress, address(sushiswapRouter), incomingLP);

        if (token0 == wmaticTokenAddress || token1 == wmaticTokenAddress) {
            address _token = token0 == wmaticTokenAddress ? token1 : token0;
            (amountA, amountB) = sushiswapRouter.removeLiquidityETH(
                _token,
                incomingLP,
                1,
                1,
                address(this),
                deadline
            );

            // subtract goodwill
            uint256 tokenGoodwill =
                _subtractGoodwill(_token, amountA, affiliate, true);
            uint256 ethGoodwill =
                _subtractGoodwill(ETHAddress, amountB, affiliate, true);

            // send tokens
            IERC20(_token).safeTransfer(msg.sender, amountA - tokenGoodwill);
            Address.sendValue(payable(msg.sender), amountB - ethGoodwill);
        } else {
            (amountA, amountB) = sushiswapRouter.removeLiquidity(
                token0,
                token1,
                incomingLP,
                1,
                1,
                address(this),
                deadline
            );

            // subtract goodwill
            uint256 tokenAGoodwill =
                _subtractGoodwill(token0, amountA, affiliate, true);
            uint256 tokenBGoodwill =
                _subtractGoodwill(token1, amountB, affiliate, true);

            // send tokens
            IERC20(token0).safeTransfer(msg.sender, amountA - tokenAGoodwill);
            IERC20(token1).safeTransfer(msg.sender, amountB - tokenBGoodwill);
        }
        emit zapOut(msg.sender, fromPoolAddress, token0, amountA);
        emit zapOut(msg.sender, fromPoolAddress, token1, amountB);
    }

    /**
    @notice Zap out in a single token
    @param toTokenAddress Address of desired token
    @param fromPoolAddress Pool from which to remove liquidity
    @param incomingLP Quantity of LP to remove from pool
    @param minTokensRec Minimum quantity of tokens to receive
    @param swapTargets Execution targets for swaps
    @param swapData DEX swap data
    @param affiliate Affiliate address
    @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    */
    function ZapOut(
        address toTokenAddress,
        address fromPoolAddress,
        uint256 incomingLP,
        uint256 minTokensRec,
        address[] memory swapTargets,
        bytes[] memory swapData,
        address affiliate,
        bool shouldSellEntireBalance
    ) public stopInEmergency returns (uint256 tokensRec) {
        (uint256 amount0, uint256 amount1) =
            _removeLiquidity(
                fromPoolAddress,
                incomingLP,
                shouldSellEntireBalance
            );

        //swaps tokens to token
        tokensRec = _swapTokens(
            fromPoolAddress,
            amount0,
            amount1,
            toTokenAddress,
            swapTargets,
            swapData
        );
        require(tokensRec >= minTokensRec, "High Slippage");

        uint256 totalGoodwillPortion;

        // transfer toTokens to sender
        if (toTokenAddress == address(0)) {
            totalGoodwillPortion = _subtractGoodwill(
                ETHAddress,
                tokensRec,
                affiliate,
                true
            );

            payable(msg.sender).transfer(tokensRec - totalGoodwillPortion);
        } else {
            totalGoodwillPortion = _subtractGoodwill(
                toTokenAddress,
                tokensRec,
                affiliate,
                true
            );

            IERC20(toTokenAddress).safeTransfer(
                msg.sender,
                tokensRec - totalGoodwillPortion
            );
        }

        tokensRec = tokensRec - totalGoodwillPortion;

        emit zapOut(msg.sender, fromPoolAddress, toTokenAddress, tokensRec);

        return tokensRec;
    }

    /**
    @notice Zap out in both tokens with permit
    @param fromPoolAddress Pool from which to remove liquidity
    @param incomingLP Quantity of LP to remove from pool
    @param affiliate Affiliate address to share fees
    @param permitData Encoded permit data, which contains owner, spender, value, deadline, r,s,v values 
    @return amountA Quantity of tokenA received
    @return amountB Quantity of tokenB received
    */
    function ZapOut2PairTokenWithPermit(
        address fromPoolAddress,
        uint256 incomingLP,
        address affiliate,
        bytes calldata permitData
    ) external stopInEmergency returns (uint256 amountA, uint256 amountB) {
        // permit
        _validatePool(fromPoolAddress);
        (bool success, ) = fromPoolAddress.call(permitData);
        require(success, "Could Not Permit");

        (amountA, amountB) = ZapOut2PairToken(
            fromPoolAddress,
            incomingLP,
            affiliate
        );
    }

    /**
    @notice Zap out in a single token with permit
    @param toTokenAddress Address of desired token
    @param fromPoolAddress Pool from which to remove liquidity
    @param incomingLP Quantity of LP to remove from pool
    @param minTokensRec Minimum quantity of tokens to receive
    @param swapTargets Execution targets for swaps
    @param swapData DEX swap data
    @param affiliate Affiliate address
    */
    function ZapOutWithPermit(
        address toTokenAddress,
        address fromPoolAddress,
        uint256 incomingLP,
        uint256 minTokensRec,
        bytes memory permitData,
        address[] memory swapTargets,
        bytes[] memory swapData,
        address affiliate
    ) public stopInEmergency returns (uint256) {
        // permit
        _validatePool(fromPoolAddress);
        (bool success, ) = fromPoolAddress.call(permitData);
        require(success, "Could Not Permit");

        return (
            ZapOut(
                toTokenAddress,
                fromPoolAddress,
                incomingLP,
                minTokensRec,
                swapTargets,
                swapData,
                affiliate,
                false
            )
        );
    }

    function _validatePool(address poolAddress) internal view {
        IUniswapV2Pair pair = IUniswapV2Pair(poolAddress);
        address token0 = pair.token0();
        address token1 = pair.token1();

        address retrievedAddress = sushiswapFactory.getPair(token0, token1);

        require(retrievedAddress == poolAddress, "Invalid Pool Address");
    }

    function _removeLiquidity(
        address fromPoolAddress,
        uint256 incomingLP,
        bool shouldSellEntireBalance
    ) internal returns (uint256 amount0, uint256 amount1) {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);

        require(address(pair) != address(0), "Pool Cannot be Zero Address");

        address token0 = pair.token0();
        address token1 = pair.token1();

        _pullTokens(fromPoolAddress, incomingLP, shouldSellEntireBalance);

        _approveToken(fromPoolAddress, address(sushiswapRouter), incomingLP);

        (amount0, amount1) = sushiswapRouter.removeLiquidity(
            token0,
            token1,
            incomingLP,
            1,
            1,
            address(this),
            deadline
        );
        require(amount0 > 0 && amount1 > 0, "Removed Insufficient Liquidity");
    }

    function _swapTokens(
        address fromPoolAddress,
        uint256 amount0,
        uint256 amount1,
        address toToken,
        address[] memory swapTargets,
        bytes[] memory swapData
    ) internal returns (uint256 tokensBought) {
        address token0 = IUniswapV2Pair(fromPoolAddress).token0();
        address token1 = IUniswapV2Pair(fromPoolAddress).token1();

        //swap token0 to toToken
        if (token0 == toToken) {
            tokensBought = tokensBought + amount0;
        } else {
            //swap token using 0x swap
            tokensBought =
                tokensBought +
                _fillQuote(
                    token0,
                    toToken,
                    amount0,
                    swapTargets[0],
                    swapData[0]
                );
        }

        //swap token1 to toToken
        if (token1 == toToken) {
            tokensBought = tokensBought + amount1;
        } else {
            //swap token using 0x swap
            tokensBought =
                tokensBought +
                _fillQuote(
                    token1,
                    toToken,
                    amount1,
                    swapTargets[1],
                    swapData[1]
                );
        }
    }

    function _fillQuote(
        address fromTokenAddress,
        address toToken,
        uint256 amount,
        address swapTarget,
        bytes memory swapData
    ) internal returns (uint256) {
        if (fromTokenAddress == wmaticTokenAddress && toToken == address(0)) {
            IWETH(wmaticTokenAddress).withdraw(amount);
            return amount;
        }

        uint256 valueToSend;
        if (fromTokenAddress == address(0)) {
            valueToSend = amount;
        } else {
            _approveToken(fromTokenAddress, swapTarget, amount);
        }

        uint256 initialBalance = _getBalance(toToken);

        require(approvedTargets[swapTarget], "Target not Authorized");
        (bool success, ) = swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens");

        uint256 finalBalance = _getBalance(toToken) - initialBalance;

        require(finalBalance > 0, "Swapped to Invalid Intermediate");

        return finalBalance;
    }

    /**
        @notice Utility function to determine quantity and addresses of tokens being removed
        @param fromPoolAddress Pool from which to remove liquidity
        @param liquidity Quantity of LP tokens to remove.
        @return amountA Quantity of tokenA removed
        @return amountB Quantity of tokenB removed
        @return token0 Address of the underlying token to be removed
        @return token1 Address of the underlying token to be removed
    */
    function removeLiquidityReturn(address fromPoolAddress, uint256 liquidity)
        external
        view
        returns (
            uint256 amountA,
            uint256 amountB,
            address token0,
            address token1
        )
    {
        IUniswapV2Pair pair = IUniswapV2Pair(fromPoolAddress);
        token0 = pair.token0();
        token1 = pair.token1();

        uint256 balance0 = IERC20(token0).balanceOf(fromPoolAddress);
        uint256 balance1 = IERC20(token1).balanceOf(fromPoolAddress);

        uint256 _totalSupply = pair.totalSupply();

        amountA = (liquidity * balance0) / _totalSupply;
        amountB = (liquidity * balance1) / _totalSupply;
    }
}

File 12 of 24 : ZapInBaseV3.sol
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "./ZapBaseV2.sol";

abstract contract ZapInBaseV3 is ZapBaseV2 {
    using SafeERC20 for IERC20;

    function _pullTokens(
        address token,
        uint256 amount,
        address affiliate,
        bool enableGoodwill,
        bool shouldSellEntireBalance
    ) internal returns (uint256 value) {
        uint256 totalGoodwillPortion;

        if (token == address(0)) {
            require(msg.value > 0, "No eth sent");

            // subtract goodwill
            totalGoodwillPortion = _subtractGoodwill(
                ETHAddress,
                msg.value,
                affiliate,
                enableGoodwill
            );

            return msg.value - totalGoodwillPortion;
        }
        require(amount > 0, "Invalid token amount");
        require(msg.value == 0, "Eth sent with token");

        //transfer token
        if (shouldSellEntireBalance) {
            require(
                Address.isContract(msg.sender),
                "ERR: shouldSellEntireBalance is true for EOA"
            );
            amount = IERC20(token).allowance(msg.sender, address(this));
        }
        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);

        // subtract goodwill
        totalGoodwillPortion = _subtractGoodwill(
            token,
            amount,
            affiliate,
            enableGoodwill
        );

        return amount - totalGoodwillPortion;
    }

    function _subtractGoodwill(
        address token,
        uint256 amount,
        address affiliate,
        bool enableGoodwill
    ) internal returns (uint256 totalGoodwillPortion) {
        bool whitelisted = feeWhitelist[msg.sender];
        if (enableGoodwill && !whitelisted && goodwill > 0) {
            totalGoodwillPortion = (amount * goodwill) / 10000;

            if (affiliates[affiliate]) {
                if (token == address(0)) {
                    token = ETHAddress;
                }

                uint256 affiliatePortion =
                    (totalGoodwillPortion * affiliateSplit) / 100;
                affiliateBalance[affiliate][token] += affiliatePortion;
                totalAffiliateBalance[token] += affiliatePortion;
            }
        }
    }
}

File 13 of 24 : UniswapV2_ZapIn_General_V5.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//

///@author Zapper
///@notice This contract adds liquidity to Uniswap V2 pools using ETH or any ERC20 Token.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../_base/ZapInBaseV3.sol";

// import "@uniswap/lib/contracts/libraries/Babylonian.sol";
library Babylonian {
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
        // else z = 0
    }
}

interface IWETH {
    function deposit() external payable;

    function transfer(address to, uint256 value) external returns (bool);

    function withdraw(uint256) external;
}

interface IUniswapV2Factory {
    function getPair(address tokenA, address tokenB)
        external
        view
        returns (address);
}

interface IUniswapV2Router02 {
    function factory() external pure returns (address);

    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (
            uint256 amountToken,
            uint256 amountETH,
            uint256 liquidity
        );

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);

    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETHWithPermit(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountToken, uint256 amountETH);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountETH);

    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;

    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;

    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) external pure returns (uint256 amountB);

    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountOut);

    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountIn);

    function getAmountsOut(uint256 amountIn, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);

    function getAmountsIn(uint256 amountOut, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );
}

contract UniswapV2_ZapIn_General_V5 is ZapInBaseV3 {
    using SafeERC20 for IERC20;

    IUniswapV2Factory private constant UniSwapV2FactoryAddress =
        IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);

    IUniswapV2Router02 private constant uniswapRouter =
        IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);

    address private constant wethTokenAddress =
        0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapIn(address sender, address pool, uint256 tokensRec);

    /**
    @notice This function is used to invest in given Uniswap V2 pair through ETH/ERC20 Tokens
    @param _FromTokenContractAddress The ERC20 token used for investment (address(0x00) if ether)
    @param _pairAddress The Uniswap pair address
    @param _amount The amount of fromToken to invest
    @param _minPoolTokens Reverts if less tokens received than this
    @param _swapTarget Excecution target for the first swap
    @param swapData DEX quote data
    @param affiliate Affiliate address
    @param transferResidual Set false to save gas by donating the residual remaining after a Zap
    @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    @return Amount of LP bought
     */
    function ZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        uint256 _minPoolTokens,
        address _swapTarget,
        bytes calldata swapData,
        address affiliate,
        bool transferResidual,
        bool shouldSellEntireBalance
    ) external payable stopInEmergency returns (uint256) {
        uint256 toInvest =
            _pullTokens(
                _FromTokenContractAddress,
                _amount,
                affiliate,
                true,
                shouldSellEntireBalance
            );

        uint256 LPBought =
            _performZapIn(
                _FromTokenContractAddress,
                _pairAddress,
                toInvest,
                _swapTarget,
                swapData,
                transferResidual
            );
        require(LPBought >= _minPoolTokens, "High Slippage");

        emit zapIn(msg.sender, _pairAddress, LPBought);

        IERC20(_pairAddress).safeTransfer(msg.sender, LPBought);
        return LPBought;
    }

    function _getPairTokens(address _pairAddress)
        internal
        pure
        returns (address token0, address token1)
    {
        IUniswapV2Pair uniPair = IUniswapV2Pair(_pairAddress);
        token0 = uniPair.token0();
        token1 = uniPair.token1();
    }

    function _performZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData,
        bool transferResidual
    ) internal returns (uint256) {
        uint256 intermediateAmt;
        address intermediateToken;
        (address _ToUniswapToken0, address _ToUniswapToken1) =
            _getPairTokens(_pairAddress);

        if (
            _FromTokenContractAddress != _ToUniswapToken0 &&
            _FromTokenContractAddress != _ToUniswapToken1
        ) {
            // swap to intermediate
            (intermediateAmt, intermediateToken) = _fillQuote(
                _FromTokenContractAddress,
                _pairAddress,
                _amount,
                _swapTarget,
                swapData
            );
        } else {
            intermediateToken = _FromTokenContractAddress;
            intermediateAmt = _amount;
        }

        // divide intermediate into appropriate amount to add liquidity
        (uint256 token0Bought, uint256 token1Bought) =
            _swapIntermediate(
                intermediateToken,
                _ToUniswapToken0,
                _ToUniswapToken1,
                intermediateAmt
            );

        return
            _uniDeposit(
                _ToUniswapToken0,
                _ToUniswapToken1,
                token0Bought,
                token1Bought,
                transferResidual
            );
    }

    function _uniDeposit(
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 token0Bought,
        uint256 token1Bought,
        bool transferResidual
    ) internal returns (uint256) {
        _approveToken(_ToUnipoolToken0, address(uniswapRouter), token0Bought);
        _approveToken(_ToUnipoolToken1, address(uniswapRouter), token1Bought);

        (uint256 amountA, uint256 amountB, uint256 LP) =
            uniswapRouter.addLiquidity(
                _ToUnipoolToken0,
                _ToUnipoolToken1,
                token0Bought,
                token1Bought,
                1,
                1,
                address(this),
                deadline
            );

        if (transferResidual) {
            //Returning Residue in token0, if any.
            if (token0Bought - amountA > 0) {
                IERC20(_ToUnipoolToken0).safeTransfer(
                    msg.sender,
                    token0Bought - amountA
                );
            }

            //Returning Residue in token1, if any
            if (token1Bought - amountB > 0) {
                IERC20(_ToUnipoolToken1).safeTransfer(
                    msg.sender,
                    token1Bought - amountB
                );
            }
        }

        return LP;
    }

    function _fillQuote(
        address _fromTokenAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData
    ) internal returns (uint256 amountBought, address intermediateToken) {
        if (_swapTarget == wethTokenAddress) {
            IWETH(wethTokenAddress).deposit{ value: _amount }();
            return (_amount, wethTokenAddress);
        }

        uint256 valueToSend;
        if (_fromTokenAddress == address(0)) {
            valueToSend = _amount;
        } else {
            _approveToken(_fromTokenAddress, _swapTarget, _amount);
        }

        (address _token0, address _token1) = _getPairTokens(_pairAddress);
        IERC20 token0 = IERC20(_token0);
        IERC20 token1 = IERC20(_token1);
        uint256 initialBalance0 = token0.balanceOf(address(this));
        uint256 initialBalance1 = token1.balanceOf(address(this));

        require(approvedTargets[_swapTarget], "Target not Authorized");
        (bool success, ) = _swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens 1");

        uint256 finalBalance0 =
            token0.balanceOf(address(this)) - initialBalance0;
        uint256 finalBalance1 =
            token1.balanceOf(address(this)) - initialBalance1;

        if (finalBalance0 > finalBalance1) {
            amountBought = finalBalance0;
            intermediateToken = _token0;
        } else {
            amountBought = finalBalance1;
            intermediateToken = _token1;
        }

        require(amountBought > 0, "Swapped to Invalid Intermediate");
    }

    function _swapIntermediate(
        address _toContractAddress,
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 _amount
    ) internal returns (uint256 token0Bought, uint256 token1Bought) {
        IUniswapV2Pair pair =
            IUniswapV2Pair(
                UniSwapV2FactoryAddress.getPair(
                    _ToUnipoolToken0,
                    _ToUnipoolToken1
                )
            );
        (uint256 res0, uint256 res1, ) = pair.getReserves();
        if (_toContractAddress == _ToUnipoolToken0) {
            uint256 amountToSwap = calculateSwapInAmount(res0, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token1Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken1,
                amountToSwap
            );
            token0Bought = _amount - amountToSwap;
        } else {
            uint256 amountToSwap = calculateSwapInAmount(res1, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token0Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken0,
                amountToSwap
            );
            token1Bought = _amount - amountToSwap;
        }
    }

    function calculateSwapInAmount(uint256 reserveIn, uint256 userIn)
        internal
        pure
        returns (uint256)
    {
        return
            (Babylonian.sqrt(
                reserveIn * ((userIn * 3988000) + (reserveIn * 3988009))
            ) - (reserveIn * 1997)) / 1994;
    }

    /**
    @notice This function is used to swap ERC20 <> ERC20
    @param _FromTokenContractAddress The token address to swap from.
    @param _ToTokenContractAddress The token address to swap to. 
    @param tokens2Trade The amount of tokens to swap
    @return tokenBought The quantity of tokens bought
    */
    function _token2Token(
        address _FromTokenContractAddress,
        address _ToTokenContractAddress,
        uint256 tokens2Trade
    ) internal returns (uint256 tokenBought) {
        if (_FromTokenContractAddress == _ToTokenContractAddress) {
            return tokens2Trade;
        }

        _approveToken(
            _FromTokenContractAddress,
            address(uniswapRouter),
            tokens2Trade
        );

        address pair =
            UniSwapV2FactoryAddress.getPair(
                _FromTokenContractAddress,
                _ToTokenContractAddress
            );
        require(pair != address(0), "No Swap Available");
        address[] memory path = new address[](2);
        path[0] = _FromTokenContractAddress;
        path[1] = _ToTokenContractAddress;

        tokenBought = uniswapRouter.swapExactTokensForTokens(
            tokens2Trade,
            1,
            path,
            address(this),
            deadline
        )[path.length - 1];

        require(tokenBought > 0, "Error Swapping Tokens 2");
    }
}

File 14 of 24 : Sushiswap_ZapIn_V4.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//

///@author Zapper
///@notice This contract adds liquidity to Sushiswap pools using ETH or any ERC20 Token.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../_base/ZapInBaseV3.sol";

// import "@uniswap/lib/contracts/libraries/Babylonian.sol";
library Babylonian {
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
        // else z = 0
    }
}

interface IWETH {
    function deposit() external payable;
}

interface IUniswapV2Factory {
    function getPair(address tokenA, address tokenB)
        external
        view
        returns (address);
}

interface IUniswapV2Router02 {
    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );
}

contract Sushiswap_ZapIn_V4 is ZapInBaseV3 {
    using SafeERC20 for IERC20;

    IUniswapV2Factory private constant sushiSwapFactoryAddress =
        IUniswapV2Factory(0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac);

    IUniswapV2Router02 private constant sushiSwapRouter =
        IUniswapV2Router02(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);

    address private constant wethTokenAddress =
        0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapIn(address sender, address pool, uint256 tokensRec);

    /**
    @notice Add liquidity to Sushiswap pools with ETH/ERC20 Tokens
    @param _FromTokenContractAddress The ERC20 token used (address(0x00) if ether)
    @param _pairAddress The Sushiswap pair address
    @param _amount The amount of fromToken to invest
    @param _minPoolTokens Minimum quantity of pool tokens to receive. Reverts otherwise
    @param _swapTarget Excecution target for the first swap
    @param swapData DEX quote data
    @param affiliate Affiliate address
    @param transferResidual Set false to save gas by donating the residual remaining after a Zap
    @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    @return Amount of LP bought
     */
    function ZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        uint256 _minPoolTokens,
        address _swapTarget,
        bytes calldata swapData,
        address affiliate,
        bool transferResidual,
        bool shouldSellEntireBalance
    ) external payable stopInEmergency returns (uint256) {
        uint256 toInvest =
            _pullTokens(
                _FromTokenContractAddress,
                _amount,
                affiliate,
                true,
                shouldSellEntireBalance
            );

        uint256 LPBought =
            _performZapIn(
                _FromTokenContractAddress,
                _pairAddress,
                toInvest,
                _swapTarget,
                swapData,
                transferResidual
            );
        require(LPBought >= _minPoolTokens, "High Slippage");

        emit zapIn(msg.sender, _pairAddress, LPBought);

        IERC20(_pairAddress).safeTransfer(msg.sender, LPBought);
        return LPBought;
    }

    function _getPairTokens(address _pairAddress)
        internal
        pure
        returns (address token0, address token1)
    {
        IUniswapV2Pair uniPair = IUniswapV2Pair(_pairAddress);
        token0 = uniPair.token0();
        token1 = uniPair.token1();
    }

    function _performZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData,
        bool transferResidual
    ) internal returns (uint256) {
        uint256 intermediateAmt;
        address intermediateToken;
        (address _ToUniswapToken0, address _ToUniswapToken1) =
            _getPairTokens(_pairAddress);

        if (
            _FromTokenContractAddress != _ToUniswapToken0 &&
            _FromTokenContractAddress != _ToUniswapToken1
        ) {
            // swap to intermediate
            (intermediateAmt, intermediateToken) = _fillQuote(
                _FromTokenContractAddress,
                _pairAddress,
                _amount,
                _swapTarget,
                swapData
            );
        } else {
            intermediateToken = _FromTokenContractAddress;
            intermediateAmt = _amount;
        }

        // divide intermediate into appropriate amount to add liquidity
        (uint256 token0Bought, uint256 token1Bought) =
            _swapIntermediate(
                intermediateToken,
                _ToUniswapToken0,
                _ToUniswapToken1,
                intermediateAmt
            );

        return
            _uniDeposit(
                _ToUniswapToken0,
                _ToUniswapToken1,
                token0Bought,
                token1Bought,
                transferResidual
            );
    }

    function _uniDeposit(
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 token0Bought,
        uint256 token1Bought,
        bool transferResidual
    ) internal returns (uint256) {
        _approveToken(_ToUnipoolToken0, address(sushiSwapRouter), token0Bought);
        _approveToken(_ToUnipoolToken1, address(sushiSwapRouter), token1Bought);

        (uint256 amountA, uint256 amountB, uint256 LP) =
            sushiSwapRouter.addLiquidity(
                _ToUnipoolToken0,
                _ToUnipoolToken1,
                token0Bought,
                token1Bought,
                1,
                1,
                address(this),
                deadline
            );

        if (transferResidual) {
            //Returning Residue in token0, if any.
            if (token0Bought - amountA > 0) {
                IERC20(_ToUnipoolToken0).safeTransfer(
                    msg.sender,
                    token0Bought - amountA
                );
            }

            //Returning Residue in token1, if any
            if (token1Bought - amountB > 0) {
                IERC20(_ToUnipoolToken1).safeTransfer(
                    msg.sender,
                    token1Bought - amountB
                );
            }
        }

        return LP;
    }

    function _fillQuote(
        address _fromTokenAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData
    ) internal returns (uint256 amountBought, address intermediateToken) {
        if (_swapTarget == wethTokenAddress) {
            IWETH(wethTokenAddress).deposit{ value: _amount }();
            return (_amount, wethTokenAddress);
        }

        uint256 valueToSend;
        if (_fromTokenAddress == address(0)) {
            valueToSend = _amount;
        } else {
            _approveToken(_fromTokenAddress, _swapTarget, _amount);
        }

        (address _token0, address _token1) = _getPairTokens(_pairAddress);
        IERC20 token0 = IERC20(_token0);
        IERC20 token1 = IERC20(_token1);
        uint256 initialBalance0 = token0.balanceOf(address(this));
        uint256 initialBalance1 = token1.balanceOf(address(this));

        require(approvedTargets[_swapTarget], "Target not Authorized");
        (bool success, ) = _swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens 1");

        uint256 finalBalance0 =
            token0.balanceOf(address(this)) - initialBalance0;
        uint256 finalBalance1 =
            token1.balanceOf(address(this)) - initialBalance1;

        if (finalBalance0 > finalBalance1) {
            amountBought = finalBalance0;
            intermediateToken = _token0;
        } else {
            amountBought = finalBalance1;
            intermediateToken = _token1;
        }

        require(amountBought > 0, "Swapped to Invalid Intermediate");
    }

    function _swapIntermediate(
        address _toContractAddress,
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 _amount
    ) internal returns (uint256 token0Bought, uint256 token1Bought) {
        IUniswapV2Pair pair =
            IUniswapV2Pair(
                sushiSwapFactoryAddress.getPair(
                    _ToUnipoolToken0,
                    _ToUnipoolToken1
                )
            );
        (uint256 res0, uint256 res1, ) = pair.getReserves();
        if (_toContractAddress == _ToUnipoolToken0) {
            uint256 amountToSwap = calculateSwapInAmount(res0, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token1Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken1,
                amountToSwap
            );
            token0Bought = _amount - amountToSwap;
        } else {
            uint256 amountToSwap = calculateSwapInAmount(res1, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token0Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken0,
                amountToSwap
            );
            token1Bought = _amount - amountToSwap;
        }
    }

    function calculateSwapInAmount(uint256 reserveIn, uint256 userIn)
        internal
        pure
        returns (uint256)
    {
        return
            (Babylonian.sqrt(
                reserveIn * ((userIn * 3988000) + (reserveIn * 3988009))
            ) - (reserveIn * 1997)) / 1994;
    }

    /**
    @notice This function is used to swap ERC20 <> ERC20
    @param _FromTokenContractAddress The token address to swap from.
    @param _ToTokenContractAddress The token address to swap to. 
    @param tokens2Trade The amount of tokens to swap
    @return tokenBought The quantity of tokens bought
    */
    function _token2Token(
        address _FromTokenContractAddress,
        address _ToTokenContractAddress,
        uint256 tokens2Trade
    ) internal returns (uint256 tokenBought) {
        if (_FromTokenContractAddress == _ToTokenContractAddress) {
            return tokens2Trade;
        }

        _approveToken(
            _FromTokenContractAddress,
            address(sushiSwapRouter),
            tokens2Trade
        );

        address pair =
            sushiSwapFactoryAddress.getPair(
                _FromTokenContractAddress,
                _ToTokenContractAddress
            );
        require(pair != address(0), "No Swap Available");
        address[] memory path = new address[](2);
        path[0] = _FromTokenContractAddress;
        path[1] = _ToTokenContractAddress;

        tokenBought = sushiSwapRouter.swapExactTokensForTokens(
            tokens2Trade,
            1,
            path,
            address(this),
            deadline
        )[path.length - 1];

        require(tokenBought > 0, "Error Swapping Tokens 2");
    }
}

File 15 of 24 : Sushiswap_ZapIn_Polygon_V3.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//

///@author Zapper
///@notice This contract adds liquidity to Sushiswap pools on Polygon (Matic) using ETH or any ERC20 Token.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../../_base/ZapInBaseV3.sol";

// import "@uniswap/lib/contracts/libraries/Babylonian.sol";
library Babylonian {
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
        // else z = 0
    }
}

interface IWETH {
    function deposit() external payable;
}

interface IUniswapV2Factory {
    function getPair(address tokenA, address tokenB)
        external
        view
        returns (address);
}

interface IUniswapV2Router02 {
    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );
}

contract Sushiswap_ZapIn_Polygon_V3 is ZapInBaseV3 {
    using SafeERC20 for IERC20;

    IUniswapV2Factory private constant sushiSwapFactoryAddress =
        IUniswapV2Factory(0xc35DADB65012eC5796536bD9864eD8773aBc74C4);

    IUniswapV2Router02 private constant sushiSwapRouter =
        IUniswapV2Router02(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506);

    address private constant wmaticTokenAddress =
        address(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270);

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapIn(address sender, address pool, uint256 tokensRec);

    /**
    @notice Add liquidity to Sushiswap pools with ETH/ERC20 Tokens
    @param _FromTokenContractAddress The ERC20 token used (address(0x00) if ether)
    @param _pairAddress The Sushiswap pair address
    @param _amount The amount of fromToken to invest
    @param _minPoolTokens Minimum quantity of pool tokens to receive. Reverts otherwise
    @param _swapTarget Excecution target for the first swap
    @param swapData DEX quote data
    @param affiliate Affiliate address
    @param transferResidual Set false to save gas by donating the residual remaining after a Zap
    @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    @return Amount of LP bought
     */
    function ZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        uint256 _minPoolTokens,
        address _swapTarget,
        bytes calldata swapData,
        address affiliate,
        bool transferResidual,
        bool shouldSellEntireBalance
    ) external payable stopInEmergency returns (uint256) {
        uint256 toInvest =
            _pullTokens(
                _FromTokenContractAddress,
                _amount,
                affiliate,
                true,
                shouldSellEntireBalance
            );

        uint256 LPBought =
            _performZapIn(
                _FromTokenContractAddress,
                _pairAddress,
                toInvest,
                _swapTarget,
                swapData,
                transferResidual
            );
        require(LPBought >= _minPoolTokens, "High Slippage");

        emit zapIn(msg.sender, _pairAddress, LPBought);

        IERC20(_pairAddress).safeTransfer(msg.sender, LPBought);
        return LPBought;
    }

    function _getPairTokens(address _pairAddress)
        internal
        pure
        returns (address token0, address token1)
    {
        IUniswapV2Pair uniPair = IUniswapV2Pair(_pairAddress);
        token0 = uniPair.token0();
        token1 = uniPair.token1();
    }

    function _performZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData,
        bool transferResidual
    ) internal returns (uint256) {
        uint256 intermediateAmt;
        address intermediateToken;
        (address _ToUniswapToken0, address _ToUniswapToken1) =
            _getPairTokens(_pairAddress);

        if (
            _FromTokenContractAddress != _ToUniswapToken0 &&
            _FromTokenContractAddress != _ToUniswapToken1
        ) {
            // swap to intermediate
            (intermediateAmt, intermediateToken) = _fillQuote(
                _FromTokenContractAddress,
                _pairAddress,
                _amount,
                _swapTarget,
                swapData
            );
        } else {
            intermediateToken = _FromTokenContractAddress;
            intermediateAmt = _amount;
        }

        // divide intermediate into appropriate amount to add liquidity
        (uint256 token0Bought, uint256 token1Bought) =
            _swapIntermediate(
                intermediateToken,
                _ToUniswapToken0,
                _ToUniswapToken1,
                intermediateAmt
            );

        return
            _uniDeposit(
                _ToUniswapToken0,
                _ToUniswapToken1,
                token0Bought,
                token1Bought,
                transferResidual
            );
    }

    function _uniDeposit(
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 token0Bought,
        uint256 token1Bought,
        bool transferResidual
    ) internal returns (uint256) {
        _approveToken(_ToUnipoolToken0, address(sushiSwapRouter), token0Bought);
        _approveToken(_ToUnipoolToken1, address(sushiSwapRouter), token1Bought);

        (uint256 amountA, uint256 amountB, uint256 LP) =
            sushiSwapRouter.addLiquidity(
                _ToUnipoolToken0,
                _ToUnipoolToken1,
                token0Bought,
                token1Bought,
                1,
                1,
                address(this),
                deadline
            );

        if (transferResidual) {
            //Returning Residue in token0, if any.
            if (token0Bought - amountA > 0) {
                IERC20(_ToUnipoolToken0).safeTransfer(
                    msg.sender,
                    token0Bought - amountA
                );
            }

            //Returning Residue in token1, if any
            if (token1Bought - amountB > 0) {
                IERC20(_ToUnipoolToken1).safeTransfer(
                    msg.sender,
                    token1Bought - amountB
                );
            }
        }

        return LP;
    }

    function _fillQuote(
        address _fromTokenAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData
    ) internal returns (uint256 amountBought, address intermediateToken) {
        if (_swapTarget == wmaticTokenAddress) {
            IWETH(wmaticTokenAddress).deposit{ value: _amount }();
            return (_amount, wmaticTokenAddress);
        }

        uint256 valueToSend;
        if (_fromTokenAddress == address(0)) {
            valueToSend = _amount;
        } else {
            _approveToken(_fromTokenAddress, _swapTarget, _amount);
        }

        (address _token0, address _token1) = _getPairTokens(_pairAddress);
        IERC20 token0 = IERC20(_token0);
        IERC20 token1 = IERC20(_token1);
        uint256 initialBalance0 = token0.balanceOf(address(this));
        uint256 initialBalance1 = token1.balanceOf(address(this));

        require(approvedTargets[_swapTarget], "Target not Authorized");
        (bool success, ) = _swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens 1");

        uint256 finalBalance0 =
            token0.balanceOf(address(this)) - initialBalance0;
        uint256 finalBalance1 =
            token1.balanceOf(address(this)) - initialBalance1;

        if (finalBalance0 > finalBalance1) {
            amountBought = finalBalance0;
            intermediateToken = _token0;
        } else {
            amountBought = finalBalance1;
            intermediateToken = _token1;
        }

        require(amountBought > 0, "Swapped to Invalid Intermediate");
    }

    function _swapIntermediate(
        address _toContractAddress,
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 _amount
    ) internal returns (uint256 token0Bought, uint256 token1Bought) {
        IUniswapV2Pair pair =
            IUniswapV2Pair(
                sushiSwapFactoryAddress.getPair(
                    _ToUnipoolToken0,
                    _ToUnipoolToken1
                )
            );
        (uint256 res0, uint256 res1, ) = pair.getReserves();
        if (_toContractAddress == _ToUnipoolToken0) {
            uint256 amountToSwap = calculateSwapInAmount(res0, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token1Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken1,
                amountToSwap
            );
            token0Bought = _amount - amountToSwap;
        } else {
            uint256 amountToSwap = calculateSwapInAmount(res1, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token0Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken0,
                amountToSwap
            );
            token1Bought = _amount - amountToSwap;
        }
    }

    function calculateSwapInAmount(uint256 reserveIn, uint256 userIn)
        internal
        pure
        returns (uint256)
    {
        return
            (Babylonian.sqrt(
                reserveIn * ((userIn * 3988000) + (reserveIn * 3988009))
            ) - (reserveIn * 1997)) / 1994;
    }

    /**
    @notice This function is used to swap ERC20 <> ERC20
    @param _FromTokenContractAddress The token address to swap from.
    @param _ToTokenContractAddress The token address to swap to. 
    @param tokens2Trade The amount of tokens to swap
    @return tokenBought The quantity of tokens bought
    */
    function _token2Token(
        address _FromTokenContractAddress,
        address _ToTokenContractAddress,
        uint256 tokens2Trade
    ) internal returns (uint256 tokenBought) {
        if (_FromTokenContractAddress == _ToTokenContractAddress) {
            return tokens2Trade;
        }

        _approveToken(
            _FromTokenContractAddress,
            address(sushiSwapRouter),
            tokens2Trade
        );

        address pair =
            sushiSwapFactoryAddress.getPair(
                _FromTokenContractAddress,
                _ToTokenContractAddress
            );
        require(pair != address(0), "No Swap Available");
        address[] memory path = new address[](2);
        path[0] = _FromTokenContractAddress;
        path[1] = _ToTokenContractAddress;

        tokenBought = sushiSwapRouter.swapExactTokensForTokens(
            tokens2Trade,
            1,
            path,
            address(this),
            deadline
        )[path.length - 1];

        require(tokenBought > 0, "Error Swapping Tokens 2");
    }
}

File 16 of 24 : Quickswap_ZapIn_V2.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//

///@author Zapper
///@notice This contract adds liquidity to Quickswap pools on Polygon (Matic) using ETH or any ERC20 Tokens.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../../_base/ZapInBaseV3.sol";

// import "@uniswap/lib/contracts/libraries/Babylonian.sol";
library Babylonian {
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
        // else z = 0
    }
}

interface IWETH {
    function deposit() external payable;
}

interface IUniswapV2Factory {
    function getPair(address tokenA, address tokenB)
        external
        view
        returns (address);
}

interface IUniswapV2Router02 {
    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

interface IUniswapV2Pair {
    function token0() external pure returns (address);

    function token1() external pure returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );
}

contract Quickswap_ZapIn_V2 is ZapInBaseV3 {
    using SafeERC20 for IERC20;

    IUniswapV2Factory private constant quickswapFactory =
        IUniswapV2Factory(0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32);

    IUniswapV2Router02 private constant quickswapRouter =
        IUniswapV2Router02(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff);

    address private constant wmaticTokenAddress =
        address(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270);

    uint256 private constant deadline =
        0xf000000000000000000000000000000000000000000000000000000000000000;

    constructor(uint256 _goodwill, uint256 _affiliateSplit)
        ZapBaseV2(_goodwill, _affiliateSplit)
    {
        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapIn(address sender, address pool, uint256 tokensRec);

    /**
    @notice Add liquidity to Quickswap pools with ETH/ERC20 Tokens
    @param _FromTokenContractAddress The ERC20 token used (address(0x00) if ether)
    @param _pairAddress The Quickswap pair address
    @param _amount The amount of fromToken to invest
    @param _minPoolTokens Minimum quantity of pool tokens to receive. Reverts otherwise
    @param _swapTarget Excecution target for the first swap
    @param swapData DEX quote data
    @param affiliate Affiliate address
    @param transferResidual Set false to save gas by donating the residual remaining after a Zap
    @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
    @return Amount of LP bought
     */
    function ZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        uint256 _minPoolTokens,
        address _swapTarget,
        bytes calldata swapData,
        address affiliate,
        bool transferResidual,
        bool shouldSellEntireBalance
    ) external payable stopInEmergency returns (uint256) {
        uint256 toInvest =
            _pullTokens(
                _FromTokenContractAddress,
                _amount,
                affiliate,
                true,
                shouldSellEntireBalance
            );

        uint256 LPBought =
            _performZapIn(
                _FromTokenContractAddress,
                _pairAddress,
                toInvest,
                _swapTarget,
                swapData,
                transferResidual
            );
        require(LPBought >= _minPoolTokens, "High Slippage");

        emit zapIn(msg.sender, _pairAddress, LPBought);

        IERC20(_pairAddress).safeTransfer(msg.sender, LPBought);
        return LPBought;
    }

    function _getPairTokens(address _pairAddress)
        internal
        pure
        returns (address token0, address token1)
    {
        IUniswapV2Pair uniPair = IUniswapV2Pair(_pairAddress);
        token0 = uniPair.token0();
        token1 = uniPair.token1();
    }

    function _performZapIn(
        address _FromTokenContractAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData,
        bool transferResidual
    ) internal returns (uint256) {
        uint256 intermediateAmt;
        address intermediateToken;
        (address _ToUniswapToken0, address _ToUniswapToken1) =
            _getPairTokens(_pairAddress);

        if (
            _FromTokenContractAddress != _ToUniswapToken0 &&
            _FromTokenContractAddress != _ToUniswapToken1
        ) {
            // swap to intermediate
            (intermediateAmt, intermediateToken) = _fillQuote(
                _FromTokenContractAddress,
                _pairAddress,
                _amount,
                _swapTarget,
                swapData
            );
        } else {
            intermediateToken = _FromTokenContractAddress;
            intermediateAmt = _amount;
        }

        // divide intermediate into appropriate amount to add liquidity
        (uint256 token0Bought, uint256 token1Bought) =
            _swapIntermediate(
                intermediateToken,
                _ToUniswapToken0,
                _ToUniswapToken1,
                intermediateAmt
            );

        return
            _uniDeposit(
                _ToUniswapToken0,
                _ToUniswapToken1,
                token0Bought,
                token1Bought,
                transferResidual
            );
    }

    function _uniDeposit(
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 token0Bought,
        uint256 token1Bought,
        bool transferResidual
    ) internal returns (uint256) {
        _approveToken(_ToUnipoolToken0, address(quickswapRouter), token0Bought);
        _approveToken(_ToUnipoolToken1, address(quickswapRouter), token1Bought);

        (uint256 amountA, uint256 amountB, uint256 LP) =
            quickswapRouter.addLiquidity(
                _ToUnipoolToken0,
                _ToUnipoolToken1,
                token0Bought,
                token1Bought,
                1,
                1,
                address(this),
                deadline
            );

        if (transferResidual) {
            //Returning Residue in token0, if any.
            if (token0Bought - amountA > 0) {
                IERC20(_ToUnipoolToken0).safeTransfer(
                    msg.sender,
                    token0Bought - amountA
                );
            }

            //Returning Residue in token1, if any
            if (token1Bought - amountB > 0) {
                IERC20(_ToUnipoolToken1).safeTransfer(
                    msg.sender,
                    token1Bought - amountB
                );
            }
        }

        return LP;
    }

    function _fillQuote(
        address _fromTokenAddress,
        address _pairAddress,
        uint256 _amount,
        address _swapTarget,
        bytes memory swapData
    ) internal returns (uint256 amountBought, address intermediateToken) {
        if (_swapTarget == wmaticTokenAddress) {
            IWETH(wmaticTokenAddress).deposit{ value: _amount }();
            return (_amount, wmaticTokenAddress);
        }

        uint256 valueToSend;
        if (_fromTokenAddress == address(0)) {
            valueToSend = _amount;
        } else {
            _approveToken(_fromTokenAddress, _swapTarget, _amount);
        }

        (address _token0, address _token1) = _getPairTokens(_pairAddress);
        IERC20 token0 = IERC20(_token0);
        IERC20 token1 = IERC20(_token1);
        uint256 initialBalance0 = token0.balanceOf(address(this));
        uint256 initialBalance1 = token1.balanceOf(address(this));

        require(approvedTargets[_swapTarget], "Target not Authorized");
        (bool success, ) = _swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens 1");

        uint256 finalBalance0 =
            token0.balanceOf(address(this)) - initialBalance0;
        uint256 finalBalance1 =
            token1.balanceOf(address(this)) - initialBalance1;

        if (finalBalance0 > finalBalance1) {
            amountBought = finalBalance0;
            intermediateToken = _token0;
        } else {
            amountBought = finalBalance1;
            intermediateToken = _token1;
        }

        require(amountBought > 0, "Swapped to Invalid Intermediate");
    }

    function _swapIntermediate(
        address _toContractAddress,
        address _ToUnipoolToken0,
        address _ToUnipoolToken1,
        uint256 _amount
    ) internal returns (uint256 token0Bought, uint256 token1Bought) {
        IUniswapV2Pair pair =
            IUniswapV2Pair(
                quickswapFactory.getPair(_ToUnipoolToken0, _ToUnipoolToken1)
            );
        (uint256 res0, uint256 res1, ) = pair.getReserves();
        if (_toContractAddress == _ToUnipoolToken0) {
            uint256 amountToSwap = calculateSwapInAmount(res0, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token1Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken1,
                amountToSwap
            );
            token0Bought = _amount - amountToSwap;
        } else {
            uint256 amountToSwap = calculateSwapInAmount(res1, _amount);
            //if no reserve or a new pair is created
            if (amountToSwap <= 0) amountToSwap = _amount / 2;
            token0Bought = _token2Token(
                _toContractAddress,
                _ToUnipoolToken0,
                amountToSwap
            );
            token1Bought = _amount - amountToSwap;
        }
    }

    function calculateSwapInAmount(uint256 reserveIn, uint256 userIn)
        internal
        pure
        returns (uint256)
    {
        return
            (Babylonian.sqrt(
                reserveIn * ((userIn * 3988000) + (reserveIn * 3988009))
            ) - (reserveIn * 1997)) / 1994;
    }

    /**
    @notice This function is used to swap ERC20 <> ERC20
    @param _FromTokenContractAddress The token address to swap from.
    @param _ToTokenContractAddress The token address to swap to. 
    @param tokens2Trade The amount of tokens to swap
    @return tokenBought The quantity of tokens bought
    */
    function _token2Token(
        address _FromTokenContractAddress,
        address _ToTokenContractAddress,
        uint256 tokens2Trade
    ) internal returns (uint256 tokenBought) {
        if (_FromTokenContractAddress == _ToTokenContractAddress) {
            return tokens2Trade;
        }

        _approveToken(
            _FromTokenContractAddress,
            address(quickswapRouter),
            tokens2Trade
        );

        address pair =
            quickswapFactory.getPair(
                _FromTokenContractAddress,
                _ToTokenContractAddress
            );
        require(pair != address(0), "No Swap Available");
        address[] memory path = new address[](2);
        path[0] = _FromTokenContractAddress;
        path[1] = _ToTokenContractAddress;

        tokenBought = quickswapRouter.swapExactTokensForTokens(
            tokens2Trade,
            1,
            path,
            address(this),
            deadline
        )[path.length - 1];

        require(tokenBought > 0, "Error Swapping Tokens 2");
    }
}

File 17 of 24 : Curve_ZapIn_General_V4.sol
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2021 zapper

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//

///@author Zapper
///@notice This contract adds liquidity to Curve pools with ETH or ERC tokens.
// SPDX-License-Identifier: GPL-2.0

pragma solidity ^0.8.0;
import "../_base/ZapInBaseV3.sol";

interface IWETH {
    function deposit() external payable;
}

interface ICurveSwap {
    function coins(int128 arg0) external view returns (address);

    function underlying_coins(int128 arg0) external view returns (address);

    function add_liquidity(uint256[4] calldata amounts, uint256 min_mint_amount)
        external;

    function add_liquidity(
        uint256[4] calldata amounts,
        uint256 min_mint_amount,
        bool addUnderlying
    ) external;

    function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount)
        external;

    function add_liquidity(
        uint256[3] calldata amounts,
        uint256 min_mint_amount,
        bool addUnderlying
    ) external;

    function add_liquidity(uint256[2] calldata amounts, uint256 min_mint_amount)
        external;

    function add_liquidity(
        uint256[2] calldata amounts,
        uint256 min_mint_amount,
        bool addUnderlying
    ) external;
}

interface ICurveEthSwap {
    function add_liquidity(uint256[2] calldata amounts, uint256 min_mint_amount)
        external
        payable
        returns (uint256);
}

interface ICurveRegistry {
    function getSwapAddress(address tokenAddress)
        external
        view
        returns (address swapAddress);

    function getTokenAddress(address swapAddress)
        external
        view
        returns (address tokenAddress);

    function getDepositAddress(address swapAddress)
        external
        view
        returns (address depositAddress);

    function getPoolTokens(address swapAddress)
        external
        view
        returns (address[4] memory poolTokens);

    function shouldAddUnderlying(address swapAddress)
        external
        view
        returns (bool);

    function getNumTokens(address swapAddress)
        external
        view
        returns (uint8 numTokens);

    function isBtcPool(address swapAddress) external view returns (bool);

    function isEthPool(address swapAddress) external view returns (bool);

    function isUnderlyingToken(
        address swapAddress,
        address tokenContractAddress
    ) external view returns (bool, uint8);
}

contract Curve_ZapIn_General_V4 is ZapInBaseV3 {
    using SafeERC20 for IERC20;

    ICurveRegistry public curveReg;

    address private constant wethTokenAddress =
        0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    constructor(
        ICurveRegistry _curveRegistry,
        uint256 _goodwill,
        uint256 _affiliateSplit
    ) ZapBaseV2(_goodwill, _affiliateSplit) {
        curveReg = _curveRegistry;

        // 0x exchange
        approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true;
    }

    event zapIn(address sender, address pool, uint256 tokensRec);

    /**
        @notice This function adds liquidity to a Curve pool with ETH or ERC20 tokens
        @param fromTokenAddress The token used for entry (address(0) if ether)
        @param toTokenAddress The intermediate ERC20 token to swap to
        @param swapAddress Curve swap address for the pool
        @param incomingTokenQty The amount of fromTokenAddress to invest
        @param minPoolTokens The minimum acceptable quantity of Curve LP to receive. Reverts otherwise
        @param swapTarget Excecution target for the first swap
        @param swapData DEX quote data
        @param affiliate Affiliate address
        @param shouldSellEntireBalance If True transfers entrire allowable amount from another contract
        @return crvTokensBought Quantity of Curve LP tokens received
    */
    function ZapIn(
        address fromTokenAddress,
        address toTokenAddress,
        address swapAddress,
        uint256 incomingTokenQty,
        uint256 minPoolTokens,
        address swapTarget,
        bytes calldata swapData,
        address affiliate,
        bool shouldSellEntireBalance
    ) external payable stopInEmergency returns (uint256 crvTokensBought) {
        uint256 toInvest =
            _pullTokens(
                fromTokenAddress,
                incomingTokenQty,
                affiliate,
                true,
                shouldSellEntireBalance
            );
        if (fromTokenAddress == address(0)) {
            fromTokenAddress = ETHAddress;
        }

        // perform zapIn
        crvTokensBought = _performZapIn(
            fromTokenAddress,
            toTokenAddress,
            swapAddress,
            toInvest,
            swapTarget,
            swapData
        );

        require(
            crvTokensBought > minPoolTokens,
            "Received less than minPoolTokens"
        );

        address poolTokenAddress = curveReg.getTokenAddress(swapAddress);

        emit zapIn(msg.sender, poolTokenAddress, crvTokensBought);

        IERC20(poolTokenAddress).transfer(msg.sender, crvTokensBought);
    }

    function _performZapIn(
        address fromTokenAddress,
        address toTokenAddress,
        address swapAddress,
        uint256 toInvest,
        address swapTarget,
        bytes memory swapData
    ) internal returns (uint256 crvTokensBought) {
        (bool isUnderlying, uint8 underlyingIndex) =
            curveReg.isUnderlyingToken(swapAddress, fromTokenAddress);

        if (isUnderlying) {
            crvTokensBought = _enterCurve(
                swapAddress,
                toInvest,
                underlyingIndex
            );
        } else {
            //swap tokens using 0x swap
            uint256 tokensBought =
                _fillQuote(
                    fromTokenAddress,
                    toTokenAddress,
                    toInvest,
                    swapTarget,
                    swapData
                );
            if (toTokenAddress == address(0)) toTokenAddress = ETHAddress;

            //get underlying token index
            (isUnderlying, underlyingIndex) = curveReg.isUnderlyingToken(
                swapAddress,
                toTokenAddress
            );

            if (isUnderlying) {
                crvTokensBought = _enterCurve(
                    swapAddress,
                    tokensBought,
                    underlyingIndex
                );
            } else {
                (uint256 tokens, uint8 metaIndex) =
                    _enterMetaPool(swapAddress, toTokenAddress, tokensBought);

                crvTokensBought = _enterCurve(swapAddress, tokens, metaIndex);
            }
        }
    }

    /**
        @notice This function gets adds the liquidity for meta pools and returns the token index and swap tokens
        @param swapAddress Curve swap address for the pool
        @param toTokenAddress The ERC20 token to which from token to be convert
        @param swapTokens quantity of toToken to invest
        @return tokensBought quantity of curve LP acquired
        @return index index of LP token in swapAddress whose pool tokens were acquired
     */
    function _enterMetaPool(
        address swapAddress,
        address toTokenAddress,
        uint256 swapTokens
    ) internal returns (uint256 tokensBought, uint8 index) {
        address[4] memory poolTokens = curveReg.getPoolTokens(swapAddress);
        for (uint8 i = 0; i < 4; i++) {
            address intermediateSwapAddress =
                curveReg.getSwapAddress(poolTokens[i]);
            if (intermediateSwapAddress != address(0)) {
                (, index) = curveReg.isUnderlyingToken(
                    intermediateSwapAddress,
                    toTokenAddress
                );

                tokensBought = _enterCurve(
                    intermediateSwapAddress,
                    swapTokens,
                    index
                );

                return (tokensBought, i);
            }
        }
    }

    function _fillQuote(
        address fromTokenAddress,
        address toTokenAddress,
        uint256 amount,
        address swapTarget,
        bytes memory swapData
    ) internal returns (uint256 amountBought) {
        if (fromTokenAddress == toTokenAddress) {
            return amount;
        }

        if (swapTarget == wethTokenAddress) {
            IWETH(wethTokenAddress).deposit{ value: amount }();
            return amount;
        }

        uint256 valueToSend;
        if (fromTokenAddress == ETHAddress) {
            valueToSend = amount;
        } else {
            _approveToken(fromTokenAddress, swapTarget, amount);
        }

        uint256 initialBalance = _getBalance(toTokenAddress);

        require(approvedTargets[swapTarget], "Target not Authorized");
        (bool success, ) = swapTarget.call{ value: valueToSend }(swapData);
        require(success, "Error Swapping Tokens");

        amountBought = _getBalance(toTokenAddress) - initialBalance;

        require(amountBought > 0, "Swapped To Invalid Intermediate");
    }

    /**
        @notice This function adds liquidity to a curve pool
        @param swapAddress Curve swap address for the pool
        @param amount The quantity of tokens being added as liquidity
        @param index The token index for the add_liquidity call
        @return crvTokensBought the quantity of curve LP tokens received
    */
    function _enterCurve(
        address swapAddress,
        uint256 amount,
        uint8 index
    ) internal returns (uint256 crvTokensBought) {
        address tokenAddress = curveReg.getTokenAddress(swapAddress);
        address depositAddress = curveReg.getDepositAddress(swapAddress);
        uint256 initialBalance = _getBalance(tokenAddress);
        address entryToken = curveReg.getPoolTokens(swapAddress)[index];
        if (entryToken != ETHAddress) {
            IERC20(entryToken).safeIncreaseAllowance(
                address(depositAddress),
                amount
            );
        }

        uint256 numTokens = curveReg.getNumTokens(swapAddress);
        bool addUnderlying = curveReg.shouldAddUnderlying(swapAddress);

        if (numTokens == 4) {
            uint256[4] memory amounts;
            amounts[index] = amount;
            if (addUnderlying) {
                ICurveSwap(depositAddress).add_liquidity(amounts, 0, true);
            } else {
                ICurveSwap(depositAddress).add_liquidity(amounts, 0);
            }
        } else if (numTokens == 3) {
            uint256[3] memory amounts;
            amounts[index] = amount;
            if (addUnderlying) {
                ICurveSwap(depositAddress).add_liquidity(amounts, 0, true);
            } else {
                ICurveSwap(depositAddress).add_liquidity(amounts, 0);
            }
        } else {
            uint256[2] memory amounts;
            amounts[index] = amount;
            if (curveReg.isEthPool(depositAddress)) {
                ICurveEthSwap(depositAddress).add_liquidity{ value: amount }(
                    amounts,
                    0
                );
            } else if (addUnderlying) {
                ICurveSwap(depositAddress).add_liquidity(amounts, 0, true);
            } else {
                ICurveSwap(depositAddress).add_liquidity(amounts, 0);
            }
        }
        crvTokensBought = _getBalance(tokenAddress) - initialBalance;
    }

    function updateCurveRegistry(ICurveRegistry newCurveRegistry)
        external
        onlyOwner
    {
        require(newCurveRegistry != curveReg, "Already using this Registry");
        curveReg = newCurveRegistry;
    }
}

File 18 of 24 : TokenTimelock.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./SafeERC20.sol";

/**
 * @dev A token holder contract that will allow a beneficiary to extract the
 * tokens after a given release time.
 *
 * Useful for simple vesting schedules like "advisors get all of their tokens
 * after 1 year".
 */
contract TokenTimelock {
    using SafeERC20 for IERC20;

    // ERC20 basic token contract being held
    IERC20 private immutable _token;

    // beneficiary of tokens after they are released
    address private immutable _beneficiary;

    // timestamp when token release is enabled
    uint256 private immutable _releaseTime;

    constructor(
        IERC20 token_,
        address beneficiary_,
        uint256 releaseTime_
    ) {
        // solhint-disable-next-line not-rely-on-time
        require(
            releaseTime_ > block.timestamp,
            "TokenTimelock: release time is before current time"
        );
        _token = token_;
        _beneficiary = beneficiary_;
        _releaseTime = releaseTime_;
    }

    /**
     * @return the token being held.
     */
    function token() public view virtual returns (IERC20) {
        return _token;
    }

    /**
     * @return the beneficiary of the tokens.
     */
    function beneficiary() public view virtual returns (address) {
        return _beneficiary;
    }

    /**
     * @return the time when the tokens are released.
     */
    function releaseTime() public view virtual returns (uint256) {
        return _releaseTime;
    }

    /**
     * @notice Transfers tokens held by timelock to beneficiary.
     */
    function release() public virtual {
        // solhint-disable-next-line not-rely-on-time
        require(
            block.timestamp >= releaseTime(),
            "TokenTimelock: current time is before release time"
        );

        uint256 amount = token().balanceOf(address(this));
        require(amount > 0, "TokenTimelock: no tokens to release");

        token().safeTransfer(beneficiary(), amount);
    }
}

File 19 of 24 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 20 of 24 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The defaut value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account)
        public
        view
        virtual
        override
        returns (uint256)
    {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender)
        public
        view
        virtual
        override
        returns (uint256)
    {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(
            currentAllowance >= amount,
            "ERC20: transfer amount exceeds allowance"
        );
        _approve(sender, _msgSender(), currentAllowance - amount);

        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue)
        public
        virtual
        returns (bool)
    {
        _approve(
            _msgSender(),
            spender,
            _allowances[_msgSender()][spender] + addedValue
        );
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue)
        public
        virtual
        returns (bool)
    {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(
            currentAllowance >= subtractedValue,
            "ERC20: decreased allowance below zero"
        );
        _approve(_msgSender(), spender, currentAllowance - subtractedValue);

        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(
            senderBalance >= amount,
            "ERC20: transfer amount exceeds balance"
        );
        _balances[sender] = senderBalance - amount;
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        _balances[account] = accountBalance - amount;
        _totalSupply -= amount;

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

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

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

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 21 of 24 : AccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    function hasRole(bytes32 role, address account)
        external
        view
        returns (bool);

    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    function grantRole(bytes32 role, address account) external;

    function revokeRole(bytes32 role, address account) external;

    function renounceRole(bytes32 role, address account) external;
}

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(
        bytes32 indexed role,
        bytes32 indexed previousAdminRole,
        bytes32 indexed newAdminRole
    );

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {_setupRole}.
     */
    event RoleGranted(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override
        returns (bool)
    {
        return
            interfaceId == type(IAccessControl).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account)
        public
        view
        override
        returns (bool)
    {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
     */
    function _checkRole(bytes32 role, address account) internal view {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account)
        public
        virtual
        override
        onlyRole(getRoleAdmin(role))
    {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account)
        public
        virtual
        override
        onlyRole(getRoleAdmin(role))
    {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account)
        public
        virtual
        override
    {
        require(
            account == _msgSender(),
            "AccessControl: can only renounce roles for self"
        );

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        emit RoleAdminChanged(role, getRoleAdmin(role), adminRole);
        _roles[role].adminRole = adminRole;
    }

    function _grantRole(bytes32 role, address account) private {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    function _revokeRole(bytes32 role, address account) private {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 22 of 24 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant alphabet = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length)
        internal
        pure
        returns (string memory)
    {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = alphabet[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

File 23 of 24 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override
        returns (bool)
    {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 24 of 24 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"uint256","name":"_goodwill","type":"uint256"},{"internalType":"uint256","name":"_affiliateSplit","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokensRec","type":"uint256"}],"name":"zapIn","type":"event"},{"inputs":[{"internalType":"address","name":"_FromTokenContractAddress","type":"address"},{"internalType":"address","name":"_pairAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_minPoolTokens","type":"uint256"},{"internalType":"address","name":"_swapTarget","type":"address"},{"internalType":"bytes","name":"swapData","type":"bytes"},{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"bool","name":"transferResidual","type":"bool"},{"internalType":"bool","name":"shouldSellEntireBalance","type":"bool"}],"name":"ZapIn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"affiliateBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"affiliates","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"affilliateWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvedTargets","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"feeWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"goodwill","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"bool[]","name":"isApproved","type":"bool[]"}],"name":"setApprovedTargets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_affiliate","type":"address"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"set_affiliate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"zapAddress","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"set_feeWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_new_affiliateSplit","type":"uint256"}],"name":"set_new_affiliateSplit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_new_goodwill","type":"uint256"}],"name":"set_new_goodwill","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stopped","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleContractActive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalAffiliateBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040526000805460ff60a01b191690553480156200001e57600080fd5b5060405162002c2738038062002c278339810160408190526200004191620000e0565b600080546001600160a01b03191633908117825560405184928492918291907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350600291909155600355505073def1c0ded9bec7f1a1670819833240f027b25eff60005260076020527ff6019cd1944dc466e824190b288e5a63528dd4c9a6d8cbd707956fd30d2f1e0d805460ff1916600117905562000104565b60008060408385031215620000f3578182fd5b505080516020909101519092909150565b612b1380620001146000396000f3fe6080604052600436106101185760003560e01c80635ecb16cd116100a05780639779d1a6116100645780639779d1a61461037a5780639ca37a0b146103aa578063d408f657146103bd578063f2fde38b146103ed578063fbec27bf1461040d57600080fd5b80635ecb16cd146102dc578063715018a6146102fc57806375f12b21146103115780638da5cb5b146103325780639735a6341461035a57600080fd5b806318b135e3116100e757806318b135e3146102195780633ff428c7146102465780634f51e29414610266578063550bfa56146102a65780635de0398e146102c657600080fd5b806301e980d4146101795780630dc9de85146101995780631385d24c146101b95780631781261f146101ce57600080fd5b3661017457333214156101725760405162461bcd60e51b815260206004820152601860248201527f446f206e6f742073656e6420455448206469726563746c79000000000000000060448201526064015b60405180910390fd5b005b600080fd5b34801561018557600080fd5b50610172610194366004612885565b61042d565b3480156101a557600080fd5b506101726101b4366004612696565b6104b7565b3480156101c557600080fd5b50610172610712565b3480156101da57600080fd5b506102066101e9366004612545565b600560209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b34801561022557600080fd5b5061020661023436600461250d565b60066020526000908152604090205481565b34801561025257600080fd5b50610172610261366004612669565b61075d565b34801561027257600080fd5b5061029661028136600461250d565b60046020526000908152604090205460ff1681565b6040519015158152602001610210565b3480156102b257600080fd5b506101726102c1366004612885565b6107b2565b3480156102d257600080fd5b5061020660025481565b3480156102e857600080fd5b506101726102f7366004612696565b610832565b34801561030857600080fd5b50610172610aa3565b34801561031d57600080fd5b5060005461029690600160a01b900460ff1681565b34801561033e57600080fd5b506000546040516001600160a01b039091168152602001610210565b34801561036657600080fd5b506101726103753660046126d6565b610b17565b34801561038657600080fd5b5061029661039536600461250d565b60076020526000908152604090205460ff1681565b6102066103b836600461257d565b610c41565b3480156103c957600080fd5b506102966103d836600461250d565b60016020526000908152604090205460ff1681565b3480156103f957600080fd5b5061017261040836600461250d565b610d99565b34801561041957600080fd5b50610172610428366004612669565b610e83565b6000546001600160a01b031633146104575760405162461bcd60e51b815260040161016990612931565b60648111156104b25760405162461bcd60e51b815260206004820152602160248201527f416666696c696174652053706c69742056616c7565206e6f7420616c6c6f77656044820152601960fa1b6064820152608401610169565b600355565b6000805b8281101561070c57336000908152600560205260408120908585848181106104f357634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610508919061250d565b6001600160a01b0316815260208082019290925260409081016000908120543382526005909352908120919350908186868581811061055757634e487b7160e01b600052603260045260246000fd5b905060200201602081019061056c919061250d565b6001600160a01b03166001600160a01b031681526020019081526020016000208190555081600660008686858181106105b557634e487b7160e01b600052603260045260246000fd5b90506020020160208101906105ca919061250d565b6001600160a01b03166001600160a01b03168152602001908152602001600020546105f59190612a2d565b6006600086868581811061061957634e487b7160e01b600052603260045260246000fd5b905060200201602081019061062e919061250d565b6001600160a01b0316815260208101919091526040016000205573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee84848381811061067d57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610692919061250d565b6001600160a01b031614156106b0576106ab3383610ed8565b6106fa565b6106fa33838686858181106106d557634e487b7160e01b600052603260045260246000fd5b90506020020160208101906106ea919061250d565b6001600160a01b03169190610ff1565b8061070481612a70565b9150506104bb565b50505050565b6000546001600160a01b0316331461073c5760405162461bcd60e51b815260040161016990612931565b6000805460ff60a01b198116600160a01b9182900460ff1615909102179055565b6000546001600160a01b031633146107875760405162461bcd60e51b815260040161016990612931565b6001600160a01b03919091166000908152600460205260409020805460ff1916911515919091179055565b6000546001600160a01b031633146107dc5760405162461bcd60e51b815260040161016990612931565b606481111561082d5760405162461bcd60e51b815260206004820152601a60248201527f476f6f6457696c6c2056616c7565206e6f7420616c6c6f7765640000000000006044820152606401610169565b600255565b6000546001600160a01b0316331461085c5760405162461bcd60e51b815260040161016990612931565b60005b81811015610a9e57600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee84848481811061089e57634e487b7160e01b600052603260045260246000fd5b90506020020160208101906108b3919061250d565b6001600160a01b0316141561094157600660008585858181106108e657634e487b7160e01b600052603260045260246000fd5b90506020020160208101906108fb919061250d565b6001600160a01b0316815260208101919091526040016000205461091f9047612a2d565b905061093c6109366000546001600160a01b031690565b82610ed8565b610a8b565b6006600085858581811061096557634e487b7160e01b600052603260045260246000fd5b905060200201602081019061097a919061250d565b6001600160a01b03166001600160a01b03168152602001908152602001600020548484848181106109bb57634e487b7160e01b600052603260045260246000fd5b90506020020160208101906109d0919061250d565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a082319060240160206040518083038186803b158015610a1157600080fd5b505afa158015610a25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a49919061289d565b610a539190612a2d565b9050610a8b610a6a6000546001600160a01b031690565b828686868181106106d557634e487b7160e01b600052603260045260246000fd5b5080610a9681612a70565b91505061085f565b505050565b6000546001600160a01b03163314610acd5760405162461bcd60e51b815260040161016990612931565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b03163314610b415760405162461bcd60e51b815260040161016990612931565b828114610b875760405162461bcd60e51b8152602060048201526014602482015273092dcecc2d8d2c84092dce0eae840d8cadccee8d60631b6044820152606401610169565b60005b83811015610c3a57828282818110610bb257634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610bc791906127ff565b60076000878785818110610beb57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610c00919061250d565b6001600160a01b031681526020810191909152604001600020805460ff191691151591909117905580610c3281612a70565b915050610b8a565b5050505050565b60008054600160a01b900460ff1615610c915760405162461bcd60e51b815260206004820152601260248201527115195b5c1bdc985c9a5b1e4814185d5cd95960721b6044820152606401610169565b6000610ca18c8b87600187611054565b90506000610cea8d8d848c8c8c8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508d9250611285915050565b905089811015610d2c5760405162461bcd60e51b815260206004820152600d60248201526c4869676820536c69707061676560981b6044820152606401610169565b604080513381526001600160a01b038e1660208201529081018290527f7f31d76771556dce5ab39ba5b60664743da2629a75c474e9445734b7ad34087d9060600160405180910390a1610d896001600160a01b038d163383610ff1565b9c9b505050505050505050505050565b6000546001600160a01b03163314610dc35760405162461bcd60e51b815260040161016990612931565b6001600160a01b038116610e285760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610169565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610ead5760405162461bcd60e51b815260040161016990612931565b6001600160a01b03919091166000908152600160205260409020805460ff1916911515919091179055565b80471015610f285760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610169565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114610f75576040519150601f19603f3d011682016040523d82523d6000602084013e610f7a565b606091505b5050905080610a9e5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610169565b6040516001600160a01b038316602482015260448101829052610a9e90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611322565b6000806001600160a01b0387166110d757600034116110a35760405162461bcd60e51b815260206004820152600b60248201526a139bc8195d1a081cd95b9d60aa1b6044820152606401610169565b6110c373eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee3487876113f4565b90506110cf8134612a2d565b91505061127c565b6000861161111e5760405162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081d1bdad95b88185b5bdd5b9d60621b6044820152606401610169565b34156111625760405162461bcd60e51b815260206004820152601360248201527222ba341039b2b73a103bb4ba34103a37b5b2b760691b6044820152606401610169565b821561124b57333b6111cb5760405162461bcd60e51b815260206004820152602c60248201527f4552523a2073686f756c6453656c6c456e7469726542616c616e63652069732060448201526b7472756520666f7220454f4160a01b6064820152608401610169565b604051636eb1769f60e11b81523360048201523060248201526001600160a01b0388169063dd62ed3e9060440160206040518083038186803b15801561121057600080fd5b505afa158015611224573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611248919061289d565b95505b6112606001600160a01b03881633308961151f565b61126c878787876113f4565b90506112788187612a2d565b9150505b95945050505050565b60008060008060006112968a611557565b91509150816001600160a01b03168b6001600160a01b0316141580156112ce5750806001600160a01b03168b6001600160a01b031614155b156112ea576112e08b8b8b8b8b61164b565b90945092506112f1565b8a92508893505b60008061130085858589611ac9565b91509150611311848484848c611c98565b9d9c50505050505050505050505050565b6000611377826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611e1a9092919063ffffffff16565b805190915015610a9e5780806020019051810190611395919061281b565b610a9e5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610169565b3360009081526001602052604081205460ff16828015611412575080155b801561142057506000600254115b1561151657612710600254866114369190612a0e565b61144091906129ee565b6001600160a01b03851660009081526004602052604090205490925060ff1615611516576001600160a01b03861661148a5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee95505b600060646003548461149c9190612a0e565b6114a691906129ee565b6001600160a01b038087166000908152600560209081526040808320938c168352929052908120805492935083929091906114e29084906129d6565b90915550506001600160a01b0387166000908152600660205260408120805483929061150f9084906129d6565b9091555050505b50949350505050565b6040516001600160a01b038085166024830152831660448201526064810182905261070c9085906323b872dd60e01b9060840161101d565b6000806000839050806001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561159857600080fd5b505afa1580156115ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115d09190612529565b9250806001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561160b57600080fd5b505afa15801561161f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116439190612529565b915050915091565b6000806001600160a01b038416730d500b1d8e8ef31e21c99d1db9a6444d3adf127014156116fa57730d500b1d8e8ef31e21c99d1db9a6444d3adf12706001600160a01b031663d0e30db0866040518263ffffffff1660e01b81526004016000604051808303818588803b1580156116c257600080fd5b505af11580156116d6573d6000803e3d6000fd5b505050505084730d500b1d8e8ef31e21c99d1db9a6444d3adf127091509150611abf565b60006001600160a01b03881661171157508461171c565b61171c888688611e33565b60008061172889611557565b6040516370a0823160e01b81523060048201529193509150829082906000906001600160a01b038416906370a082319060240160206040518083038186803b15801561177357600080fd5b505afa158015611787573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ab919061289d565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a082319060240160206040518083038186803b1580156117f057600080fd5b505afa158015611804573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611828919061289d565b6001600160a01b038c1660009081526007602052604090205490915060ff1661188b5760405162461bcd60e51b815260206004820152601560248201527415185c99d95d081b9bdd08105d5d1a1bdc9a5e9959605a1b6044820152606401610169565b60008b6001600160a01b0316888c6040516118a691906128e2565b60006040518083038185875af1925050503d80600081146118e3576040519150601f19603f3d011682016040523d82523d6000602084013e6118e8565b606091505b50509050806119395760405162461bcd60e51b815260206004820152601760248201527f4572726f72205377617070696e6720546f6b656e7320310000000000000000006044820152606401610169565b6040516370a0823160e01b815230600482015260009084906001600160a01b038816906370a082319060240160206040518083038186803b15801561197d57600080fd5b505afa158015611991573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119b5919061289d565b6119bf9190612a2d565b6040516370a0823160e01b815230600482015290915060009084906001600160a01b038816906370a082319060240160206040518083038186803b158015611a0657600080fd5b505afa158015611a1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a3e919061289d565b611a489190612a2d565b905080821115611a5d57819b50889a50611a64565b809b50879a505b60008c11611ab45760405162461bcd60e51b815260206004820152601f60248201527f5377617070656420746f20496e76616c696420496e7465726d656469617465006044820152606401610169565b505050505050505050505b9550959350505050565b60405163e6a4390560e01b81526001600160a01b038085166004830152831660248201526000908190819073c35dadb65012ec5796536bd9864ed8773abc74c49063e6a439059060440160206040518083038186803b158015611b2b57600080fd5b505afa158015611b3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b639190612529565b9050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611ba157600080fd5b505afa158015611bb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bd99190612837565b506001600160701b031691506001600160701b03169150876001600160a01b0316896001600160a01b03161415611c4d576000611c168388611e5c565b905060008111611c2e57611c2b6002886129ee565b90505b611c398a8983611eb7565b9450611c458188612a2d565b955050611c8c565b6000611c598288611e5c565b905060008111611c7157611c6e6002886129ee565b90505b611c7c8a8a83611eb7565b9550611c888188612a2d565b9450505b50505094509492505050565b6000611cb986731b02da8cb0d097eb8d57a175b88c7d8b4799750686611e33565b611cd885731b02da8cb0d097eb8d57a175b88c7d8b4799750685611e33565b60405162e8e33760e81b81526001600160a01b03808816600483015286166024820152604481018590526064810184905260016084820181905260a48201523060c4820152600f60fc1b60e482015260009081908190731b02da8cb0d097eb8d57a175b88c7d8b479975069063e8e337009061010401606060405180830381600087803b158015611d6857600080fd5b505af1158015611d7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611da091906128b5565b9250925092508415611e0e576000611db88489612a2d565b1115611ddd57611ddd33611dcc858a612a2d565b6001600160a01b038c169190610ff1565b6000611de98388612a2d565b1115611e0e57611e0e33611dfd8489612a2d565b6001600160a01b038b169190610ff1565b98975050505050505050565b6060611e2984846000856121a1565b90505b9392505050565b611e486001600160a01b0384168360006122c9565b610a9e6001600160a01b03841683836122c9565b60006107ca611e6d846107cd612a0e565b611ea3611e7d86623cda29612a0e565b611e8a86623cda20612a0e565b611e9491906129d6565b611e9e9087612a0e565b6123ed565b611ead9190612a2d565b611e2c91906129ee565b6000826001600160a01b0316846001600160a01b03161415611eda575080611e2c565b611ef984731b02da8cb0d097eb8d57a175b88c7d8b4799750684611e33565b60405163e6a4390560e01b81526001600160a01b0380861660048301528416602482015260009073c35dadb65012ec5796536bd9864ed8773abc74c49063e6a439059060440160206040518083038186803b158015611f5757600080fd5b505afa158015611f6b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f8f9190612529565b90506001600160a01b038116611fdb5760405162461bcd60e51b81526020600482015260116024820152704e6f205377617020417661696c61626c6560781b6044820152606401610169565b604080516002808252606082018352600092602083019080368337019050509050858160008151811061201e57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b031681525050848160018151811061206057634e487b7160e01b600052603260045260246000fd5b6001600160a01b03909216602092830291909101909101526040516338ed173960e01b8152731b02da8cb0d097eb8d57a175b88c7d8b47997506906338ed1739906120bc90879060019086903090600f60fc1b90600401612966565b600060405180830381600087803b1580156120d657600080fd5b505af11580156120ea573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612112919081019061273f565b600182516121209190612a2d565b8151811061213e57634e487b7160e01b600052603260045260246000fd5b60200260200101519250600083116121985760405162461bcd60e51b815260206004820152601760248201527f4572726f72205377617070696e6720546f6b656e7320320000000000000000006044820152606401610169565b50509392505050565b6060824710156122025760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610169565b843b6122505760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610169565b600080866001600160a01b0316858760405161226c91906128e2565b60006040518083038185875af1925050503d80600081146122a9576040519150601f19603f3d011682016040523d82523d6000602084013e6122ae565b606091505b50915091506122be82828661245d565b979650505050505050565b8015806123525750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b15801561231857600080fd5b505afa15801561232c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612350919061289d565b155b6123bd5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610169565b6040516001600160a01b038316602482015260448101829052610a9e90849063095ea7b360e01b9060640161101d565b6000600382111561244e57508060006124076002836129ee565b6124129060016129d6565b90505b818110156124485790508060028161242d81866129ee565b61243791906129d6565b61244191906129ee565b9050612415565b50919050565b8115612458575060015b919050565b6060831561246c575081611e2c565b82511561247c5782518084602001fd5b8160405162461bcd60e51b815260040161016991906128fe565b803561245881612ab7565b60008083601f8401126124b2578081fd5b50813567ffffffffffffffff8111156124c9578182fd5b6020830191508360208260051b85010111156124e457600080fd5b9250929050565b803561245881612acf565b80516001600160701b038116811461245857600080fd5b60006020828403121561251e578081fd5b8135611e2c81612ab7565b60006020828403121561253a578081fd5b8151611e2c81612ab7565b60008060408385031215612557578081fd5b823561256281612ab7565b9150602083013561257281612ab7565b809150509250929050565b6000806000806000806000806000806101208b8d03121561259c578586fd5b8a356125a781612ab7565b995060208b01356125b781612ab7565b985060408b0135975060608b0135965060808b01356125d581612ab7565b955060a08b013567ffffffffffffffff808211156125f1578687fd5b818d0191508d601f830112612604578687fd5b813581811115612612578788fd5b8e6020828501011115612623578788fd5b60208301975080965050505061263b60c08c01612496565b925061264960e08c016124eb565b91506126586101008c016124eb565b90509295989b9194979a5092959850565b6000806040838503121561267b578182fd5b823561268681612ab7565b9150602083013561257281612acf565b600080602083850312156126a8578182fd5b823567ffffffffffffffff8111156126be578283fd5b6126ca858286016124a1565b90969095509350505050565b600080600080604085870312156126eb578384fd5b843567ffffffffffffffff80821115612702578586fd5b61270e888389016124a1565b90965094506020870135915080821115612726578384fd5b50612733878288016124a1565b95989497509550505050565b60006020808385031215612751578182fd5b825167ffffffffffffffff80821115612768578384fd5b818501915085601f83011261277b578384fd5b81518181111561278d5761278d612aa1565b8060051b604051601f19603f830116810181811085821117156127b2576127b2612aa1565b604052828152858101935084860182860187018a10156127d0578788fd5b8795505b838610156127f25780518552600195909501949386019386016127d4565b5098975050505050505050565b600060208284031215612810578081fd5b8135611e2c81612acf565b60006020828403121561282c578081fd5b8151611e2c81612acf565b60008060006060848603121561284b578283fd5b612854846124f6565b9250612862602085016124f6565b9150604084015163ffffffff8116811461287a578182fd5b809150509250925092565b600060208284031215612896578081fd5b5035919050565b6000602082840312156128ae578081fd5b5051919050565b6000806000606084860312156128c9578081fd5b8351925060208401519150604084015190509250925092565b600082516128f4818460208701612a44565b9190910192915050565b602081526000825180602084015261291d816040850160208701612a44565b601f01601f19169190910160400192915050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156129b55784516001600160a01b031683529383019391830191600101612990565b50506001600160a01b03969096166060850152505050608001529392505050565b600082198211156129e9576129e9612a8b565b500190565b600082612a0957634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615612a2857612a28612a8b565b500290565b600082821015612a3f57612a3f612a8b565b500390565b60005b83811015612a5f578181015183820152602001612a47565b8381111561070c5750506000910152565b6000600019821415612a8457612a84612a8b565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114612acc57600080fd5b50565b8015158114612acc57600080fdfea264697066735822122093a216e290171f480c3473d6e0c0dc0a80bed08403202d7e7e4560faccd45aa364736f6c6343000804003300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _goodwill (uint256): 0
Arg [1] : _affiliateSplit (uint256): 0

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000000


Deployed ByteCode Sourcemap

3501:10430:3:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4685:10:9;4699:9;4685:23;;4677:60;;;;-1:-1:-1;;;4677:60:9;;11319:2:24;4677:60:9;;;11301:21:24;11358:2;11338:18;;;11331:30;11397:26;11377:18;;;11370:54;11441:18;;4677:60:9;;;;;;;;;3501:10430:3;;;;;2521:269:9;;;;;;;;;;-1:-1:-1;2521:269:9;;;;;:::i;:::-;;:::i;3674:621::-;;;;;;;;;;-1:-1:-1;3674:621:9;;;;;:::i;:::-;;:::i;2039:84::-;;;;;;;;;;;;;:::i;565:71::-;;;;;;;;;;-1:-1:-1;565:71:9;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;19423:25:24;;;19411:2;19396:18;565:71:9;;;;;;;;665:56;;;;;;;;;;-1:-1:-1;665:56:9;;;;;:::i;:::-;;;;;;;;;;;;;;2796:145;;;;;;;;;;-1:-1:-1;2796:145:9;;;;;:::i;:::-;;:::i;481:42::-;;;;;;;;;;-1:-1:-1;481:42:9;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;10352:14:24;;10345:22;10327:41;;10315:2;10300:18;481:42:9;10282:92:24;2283:232:9;;;;;;;;;;-1:-1:-1;2283:232:9;;;;;:::i;:::-;;:::i;360:23::-;;;;;;;;;;;;;;;;3014:587;;;;;;;;;;-1:-1:-1;3014:587:9;;;;;:::i;:::-;;:::i;1722:145:13:-;;;;;;;;;;;;;:::i;234:27:9:-;;;;;;;;;;-1:-1:-1;234:27:9;;;;-1:-1:-1;;;234:27:9;;;;;;1090:85:13;;;;;;;;;;-1:-1:-1;1136:7:13;1162:6;1090:85;;-1:-1:-1;;;;;1162:6:13;;;8392:51:24;;8380:2;8365:18;1090:85:13;8347:102:24;4301:333:9;;;;;;;;;;-1:-1:-1;4301:333:9;;;;;:::i;:::-;;:::i;764:47::-;;;;;;;;;;-1:-1:-1;764:47:9;;;;;:::i;:::-;;;;;;;;;;;;;;;;5094:1058:3;;;;;;:::i;:::-;;:::i;309:44:9:-;;;;;;;;;;-1:-1:-1;309:44:9;;;;;:::i;:::-;;;;;;;;;;;;;;;;2016:274:13;;;;;;;;;;-1:-1:-1;2016:274:13;;;;;:::i;:::-;;:::i;2129:148:9:-;;;;;;;;;;-1:-1:-1;2129:148:9;;;;;:::i;:::-;;:::i;2521:269::-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;2675:3:9::1;2652:19;:26;;2631:106;;;::::0;-1:-1:-1;;;2631:106:9;;15701:2:24;2631:106:9::1;::::0;::::1;15683:21:24::0;15740:2;15720:18;;;15713:30;15779:34;15759:18;;;15752:62;-1:-1:-1;;;15830:18:24;;;15823:31;15871:19;;2631:106:9::1;15673:223:24::0;2631:106:9::1;2747:14;:36:::0;2521:269::o;3674:621::-;3748:16;;3774:515;3794:17;;;3774:515;;;3860:10;3843:28;;;;:16;:28;;;;;;3872:6;;3879:1;3872:9;;;;;-1:-1:-1;;;3872:9:9;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;3843:39:9;;;;;;;;;;;;;;;-1:-1:-1;3843:39:9;;;;3913:10;3896:28;;:16;:28;;;;;;3843:39;;-1:-1:-1;;;3925:6:9;;3932:1;3925:9;;;;;-1:-1:-1;;;3925:9:9;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;3896:39:9;-1:-1:-1;;;;;3896:39:9;;;;;;;;;;;;:43;;;;4055:8;4004:21;:32;4026:6;;4033:1;4026:9;;;;;-1:-1:-1;;;4026:9:9;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;4004:32:9;-1:-1:-1;;;;;4004:32:9;;;;;;;;;;;;;:59;;;;:::i;:::-;3953:21;:32;3975:6;;3982:1;3975:9;;;;;-1:-1:-1;;;3975:9:9;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;3953:32:9;;;;;;;;;;;;-1:-1:-1;3953:32:9;:110;865:42;4082:6;;4089:1;4082:9;;;;;-1:-1:-1;;;4082:9:9;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;4082:23:9;;4078:201;;;4125:48;4151:10;4164:8;4125:17;:48::i;:::-;4078:201;;;4212:52;4243:10;4255:8;4219:6;;4226:1;4219:9;;;;;-1:-1:-1;;;4219:9:9;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;4212:30:9;;:52;:30;:52::i;:::-;3813:3;;;;:::i;:::-;;;;3774:515;;;;3674:621;;;:::o;2039:84::-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;2109:7:9::1;::::0;;-1:-1:-1;;;;2098:18:9;::::1;-1:-1:-1::0;;;2109:7:9;;;::::1;;;2108:8;2098:18:::0;;::::1;;::::0;;2039:84::o;2796:145::-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;-1:-1:-1;;;;;2902:22:9;;;::::1;;::::0;;;:10:::1;:22;::::0;;;;:32;;-1:-1:-1;;2902:32:9::1;::::0;::::1;;::::0;;;::::1;::::0;;2796:145::o;2283:232::-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;2419:3:9::1;2402:13;:20;;2359:115;;;::::0;-1:-1:-1;;;2359:115:9;;14657:2:24;2359:115:9::1;::::0;::::1;14639:21:24::0;14696:2;14676:18;;;14669:30;14735:28;14715:18;;;14708:56;14781:18;;2359:115:9::1;14629:176:24::0;2359:115:9::1;2484:8;:24:::0;2283:232::o;3014:587::-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;3099:9:9::1;3094:501;3114:17:::0;;::::1;3094:501;;;3152:11;865:42;3182:6:::0;;3189:1;3182:9;;::::1;;;-1:-1:-1::0;;;3182:9:9::1;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;3182:23:9::1;;3178:407;;;3255:21;:32;3277:6;;3284:1;3277:9;;;;;-1:-1:-1::0;;;3277:9:9::1;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;3255:32:9::1;::::0;;::::1;::::0;::::1;::::0;;;;;;-1:-1:-1;3255:32:9;;3231:56:::1;::::0;:21:::1;:56;:::i;:::-;3225:62;;3306:40;3332:7;1136::13::0;1162:6;-1:-1:-1;;;;;1162:6:13;;1090:85;3332:7:9::1;3342:3;3306:17;:40::i;:::-;3178:407;;;3476:21;:32;3498:6;;3505:1;3498:9;;;;;-1:-1:-1::0;;;3498:9:9::1;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;3476:32:9::1;-1:-1:-1::0;;;;;3476:32:9::1;;;;;;;;;;;;;3418:6;;3425:1;3418:9;;;;;-1:-1:-1::0;;;3418:9:9::1;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;3411:42;::::0;-1:-1:-1;;;3411:42:9;;3447:4:::1;3411:42;::::0;::::1;8392:51:24::0;-1:-1:-1;;;;;3411:27:9;;;::::1;::::0;::::1;::::0;8365:18:24;;3411:42:9::1;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:97;;;;:::i;:::-;3385:123;;3526:44;3557:7;1136::13::0;1162:6;-1:-1:-1;;;;;1162:6:13;;1090:85;3557:7:9::1;3566:3;3533:6;;3540:1;3533:9;;;;;-1:-1:-1::0;;;3533:9:9::1;;;;;;;;3526:44;-1:-1:-1::0;3133:3:9;::::1;::::0;::::1;:::i;:::-;;;;3094:501;;;;3014:587:::0;;:::o;1722:145:13:-;1136:7;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;1828:1:::1;1812:6:::0;;1791:40:::1;::::0;-1:-1:-1;;;;;1812:6:13;;::::1;::::0;1791:40:::1;::::0;1828:1;;1791:40:::1;1858:1;1841:19:::0;;-1:-1:-1;;;;;;1841:19:13::1;::::0;;1722:145::o;4301:333:9:-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;4444:35:9;;::::1;4436:68;;;::::0;-1:-1:-1;;;4436:68:9;;15352:2:24;4436:68:9::1;::::0;::::1;15334:21:24::0;15391:2;15371:18;;;15364:30;-1:-1:-1;;;15410:18:24;;;15403:50;15470:18;;4436:68:9::1;15324:170:24::0;4436:68:9::1;4520:9;4515:113;4535:18:::0;;::::1;4515:113;;;4604:10;;4615:1;4604:13;;;;;-1:-1:-1::0;;;4604:13:9::1;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4574:15;:27;4590:7;;4598:1;4590:10;;;;;-1:-1:-1::0;;;4590:10:9::1;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;4574:27:9::1;::::0;;::::1;::::0;::::1;::::0;;;;;;-1:-1:-1;4574:27:9;:43;;-1:-1:-1;;4574:43:9::1;::::0;::::1;;::::0;;;::::1;::::0;;4555:3;::::1;::::0;::::1;:::i;:::-;;;;4515:113;;;;4301:333:::0;;;;:::o;5094:1058:3:-;5445:7;1127::9;;-1:-1:-1;;;1127:7:9;;;;1123:98;;;1150:28;;-1:-1:-1;;;1150:28:9;;13545:2:24;1150:28:9;;;13527:21:24;13584:2;13564:18;;;13557:30;-1:-1:-1;;;13603:18:24;;;13596:48;13661:18;;1150:28:9;13517:168:24;1123:98:9;5464:16:3::1;5495:183;5524:25;5567:7;5592:9;5619:4;5641:23;5495:11;:183::i;:::-;5464:214;;5689:16;5720:215;5751:25;5794:12;5824:8;5850:11;5879:8;;5720:215;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;::::0;;;;-1:-1:-1;5905:16:3;;-1:-1:-1;5720:13:3::1;::::0;-1:-1:-1;;5720:215:3:i:1;:::-;5689:246;;5965:14;5953:8;:26;;5945:52;;;::::0;-1:-1:-1;;;5945:52:3;;11672:2:24;5945:52:3::1;::::0;::::1;11654:21:24::0;11711:2;11691:18;;;11684:30;-1:-1:-1;;;11730:18:24;;;11723:43;11783:18;;5945:52:3::1;11644:163:24::0;5945:52:3::1;6013:41;::::0;;6019:10:::1;9003:34:24::0;;-1:-1:-1;;;;;9073:15:24;;9068:2;9053:18;;9046:43;9105:18;;;9098:34;;;6013:41:3::1;::::0;8953:2:24;8938:18;6013:41:3::1;;;;;;;6065:55;-1:-1:-1::0;;;;;6065:33:3;::::1;6099:10;6111:8:::0;6065:33:::1;:55::i;:::-;6137:8:::0;5094:1058;-1:-1:-1;;;;;;;;;;;;5094:1058:3:o;2016:274:13:-;1136:7;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;-1:-1:-1;;;;;2117:22:13;::::1;2096:107;;;::::0;-1:-1:-1;;;2096:107:13;;12014:2:24;2096:107:13::1;::::0;::::1;11996:21:24::0;12053:2;12033:18;;;12026:30;12092:34;12072:18;;;12065:62;-1:-1:-1;;;12143:18:24;;;12136:36;12189:19;;2096:107:13::1;11986:228:24::0;2096:107:13::1;2239:6;::::0;;2218:38:::1;::::0;-1:-1:-1;;;;;2218:38:13;;::::1;::::0;2239:6;::::1;::::0;2218:38:::1;::::0;::::1;2266:6;:17:::0;;-1:-1:-1;;;;;;2266:17:13::1;-1:-1:-1::0;;;;;2266:17:13;;;::::1;::::0;;;::::1;::::0;;2016:274::o;2129:148:9:-;1136:7:13;1162:6;-1:-1:-1;;;;;1162:6:13;665:10:20;1302:23:13;1294:68;;;;-1:-1:-1;;;1294:68:13;;;;;;;:::i;:::-;-1:-1:-1;;;;;2237:24:9;;;::::1;;::::0;;;:12:::1;:24;::::0;;;;:33;;-1:-1:-1;;2237:33:9::1;::::0;::::1;;::::0;;;::::1;::::0;;2129:148::o;2068:459:19:-;2195:6;2170:21;:31;;2149:107;;;;-1:-1:-1;;;2149:107:19;;13892:2:24;2149:107:19;;;13874:21:24;13931:2;13911:18;;;13904:30;13970:31;13950:18;;;13943:59;14019:18;;2149:107:19;13864:179:24;2149:107:19;2345:12;2363:9;-1:-1:-1;;;;;2363:14:19;2386:6;2363:35;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2344:54;;;2429:7;2408:112;;;;-1:-1:-1;;;2408:112:19;;12421:2:24;2408:112:19;;;12403:21:24;12460:2;12440:18;;;12433:30;12499:34;12479:18;;;12472:62;12570:28;12550:18;;;12543:56;12616:19;;2408:112:19;12393:248:24;634:239:17;798:58;;-1:-1:-1;;;;;10100:32:24;;798:58:17;;;10082:51:24;10149:18;;;10142:34;;;746:120:17;;779:5;;-1:-1:-1;;;821:23:17;10055:18:24;;798:58:17;;;;-1:-1:-1;;798:58:17;;;;;;;;;;;;;;-1:-1:-1;;;;;798:58:17;-1:-1:-1;;;;;;798:58:17;;;;;;;;;;746:19;:120::i;170:1319:10:-;356:13;;-1:-1:-1;;;;;424:19:10;;420:357;;479:1;467:9;:13;459:37;;;;-1:-1:-1;;;459:37:10;;15012:2:24;459:37:10;;;14994:21:24;15051:2;15031:18;;;15024:30;-1:-1:-1;;;15070:18:24;;;15063:41;15121:18;;459:37:10;14984:161:24;459:37:10;567:145;865:42:9;630:9:10;657;684:14;567:17;:145::i;:::-;544:168;-1:-1:-1;734:32:10;544:168;734:9;:32;:::i;:::-;727:39;;;;;420:357;803:1;794:6;:10;786:43;;;;-1:-1:-1;;;786:43:10;;12848:2:24;786:43:10;;;12830:21:24;12887:2;12867:18;;;12860:30;-1:-1:-1;;;12906:18:24;;;12899:50;12966:18;;786:43:10;12820:170:24;786:43:10;847:9;:14;839:46;;;;-1:-1:-1;;;839:46:10;;13197:2:24;839:46:10;;;13179:21:24;13236:2;13216:18;;;13209:30;-1:-1:-1;;;13255:18:24;;;13248:49;13314:18;;839:46:10;13169:169:24;839:46:10;925:23;921:260;;;1008:10;1090:20:19;964:133:10;;;;-1:-1:-1;;;964:133:10;;16816:2:24;964:133:10;;;16798:21:24;16855:2;16835:18;;;16828:30;16894:34;16874:18;;;16867:62;-1:-1:-1;;;16945:18:24;;;16938:42;16997:19;;964:133:10;16788:234:24;964:133:10;1120:50;;-1:-1:-1;;;1120:50:10;;1144:10;1120:50;;;8666:34:24;1164:4:10;8716:18:24;;;8709:43;-1:-1:-1;;;;;1120:23:10;;;;;8601:18:24;;1120:50:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1111:59;;921:260;1190:65;-1:-1:-1;;;;;1190:30:10;;1221:10;1241:4;1248:6;1190:30;:65::i;:::-;1318:117;1349:5;1368:6;1388:9;1411:14;1318:17;:117::i;:::-;1295:140;-1:-1:-1;1453:29:10;1295:140;1453:6;:29;:::i;:::-;1446:36;;;170:1319;;;;;;;;:::o;6433:1487:3:-;6669:7;6688:23;6721:25;6757:24;6783;6823:28;6838:12;6823:14;:28::i;:::-;6756:95;;;;6908:16;-1:-1:-1;;;;;6879:45:3;:25;-1:-1:-1;;;;;6879:45:3;;;:106;;;;;6969:16;-1:-1:-1;;;;;6940:45:3;:25;-1:-1:-1;;;;;6940:45:3;;;6879:106;6862:526;;;7085:177;7113:25;7156:12;7186:7;7211:11;7240:8;7085:10;:177::i;:::-;7046:216;;-1:-1:-1;7046:216:3;-1:-1:-1;6862:526:3;;;7313:25;7293:45;;7370:7;7352:25;;6862:526;7471:20;7493;7529:167;7564:17;7599:16;7633;7667:15;7529:17;:167::i;:::-;7470:226;;;;7726:187;7755:16;7789;7823:12;7853;7883:16;7726:11;:187::i;:::-;7707:206;6433:1487;-1:-1:-1;;;;;;;;;;;;;6433:1487:3:o;3561:867:17:-;3980:23;4018:115;4063:4;4018:115;;;;;;;;;;;;;;;;;4026:5;-1:-1:-1;;;;;4018:27:17;;;:115;;;;;:::i;:::-;4147:17;;3980:153;;-1:-1:-1;4147:21:17;4143:279;;4316:10;4305:30;;;;;;;;;;;;:::i;:::-;4280:131;;;;-1:-1:-1;;;4280:131:17;;18645:2:24;4280:131:17;;;18627:21:24;18684:2;18664:18;;;18657:30;18723:34;18703:18;;;18696:62;-1:-1:-1;;;18774:18:24;;;18767:40;18824:19;;4280:131:17;18617:232:24;1495:786:10;1721:10;1649:28;1708:24;;;:12;:24;;;;;;;;1746:14;:30;;;;;1765:11;1764:12;1746:30;:46;;;;;1791:1;1780:8;;:12;1746:46;1742:533;;;1853:5;1841:8;;1832:6;:17;;;;:::i;:::-;1831:27;;;;:::i;:::-;-1:-1:-1;;;;;1877:21:10;;;;;;:10;:21;;;;;;1808:50;;-1:-1:-1;1877:21:10;;1873:392;;;-1:-1:-1;;;;;1922:19:10;;1918:84;;865:42:9;1965:18:10;;1918:84;2020:24;2109:3;2091:14;;2068:20;:37;;;;:::i;:::-;2067:45;;;;:::i;:::-;-1:-1:-1;;;;;2130:27:10;;;;;;;:16;:27;;;;;;;;:34;;;;;;;;;;;:54;;2020:92;;-1:-1:-1;2020:92:10;;2130:34;;:27;:54;;2020:92;;2130:54;:::i;:::-;;;;-1:-1:-1;;;;;;;2202:28:10;;;;;;:21;:28;;;;;:48;;2234:16;;2202:28;:48;;2234:16;;2202:48;:::i;:::-;;;;-1:-1:-1;;;1873:392:10;1495:786;;;;;;;:::o;879:275:17:-;1069:68;;-1:-1:-1;;;;;9021:15:24;;;1069:68:17;;;9003:34:24;9073:15;;9053:18;;;9046:43;9105:18;;;9098:34;;;1017:130:17;;1050:5;;-1:-1:-1;;;1092:27:17;8938:18:24;;1069:68:17;8920:218:24;6158:269:3;6251:14;6267;6297:22;6337:12;6297:53;;6369:7;-1:-1:-1;;;;;6369:14:3;;:16;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6360:25;;6404:7;-1:-1:-1;;;;;6404:14:3;;:16;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6395:25;;6158:269;;;;:::o;9234:1629::-;9428:20;;-1:-1:-1;;;;;9491:33:3;;3921:42;9491:33;9487:167;;;3921:42;-1:-1:-1;;;;;9540:33:3;;9582:7;9540:53;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9615:7;3921:42;9607:36;;;;;;9487:167;9664:19;-1:-1:-1;;;;;9697:31:3;;9693:168;;-1:-1:-1;9758:7:3;9693:168;;;9796:54;9810:17;9829:11;9842:7;9796:13;:54::i;:::-;9872:15;9889;9908:28;9923:12;9908:14;:28::i;:::-;10054:31;;-1:-1:-1;;;10054:31:3;;10079:4;10054:31;;;8392:51:24;9871:65:3;;-1:-1:-1;9871:65:3;-1:-1:-1;9871:65:3;;;;9946:13;;-1:-1:-1;;;;;10054:16:3;;;;;8365:18:24;;10054:31:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;10121;;-1:-1:-1;;;10121:31:3;;10146:4;10121:31;;;8392:51:24;10028:57:3;;-1:-1:-1;10095:23:3;;-1:-1:-1;;;;;10121:16:3;;;;;8365:18:24;;10121:31:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;10171:28:3;;;;;;:15;:28;;;;;;10095:57;;-1:-1:-1;10171:28:3;;10163:62;;;;-1:-1:-1;;;10163:62:3;;10969:2:24;10163:62:3;;;10951:21:24;11008:2;10988:18;;;10981:30;-1:-1:-1;;;11027:18:24;;;11020:51;11088:18;;10163:62:3;10941:171:24;10163:62:3;10236:12;10254:11;-1:-1:-1;;;;;10254:16:3;10279:11;10293:8;10254:48;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;10235:67;;;10320:7;10312:43;;;;-1:-1:-1;;;10312:43:3;;17229:2:24;10312:43:3;;;17211:21:24;17268:2;17248:18;;;17241:30;17307:25;17287:18;;;17280:53;17350:18;;10312:43:3;17201:173:24;10312:43:3;10402:31;;-1:-1:-1;;;10402:31:3;;10427:4;10402:31;;;8392:51:24;10366:21:3;;10436:15;;-1:-1:-1;;;;;10402:16:3;;;;;8365:18:24;;10402:31:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:49;;;;:::i;:::-;10497:31;;-1:-1:-1;;;10497:31:3;;10522:4;10497:31;;;8392:51:24;10366:85:3;;-1:-1:-1;10461:21:3;;10531:15;;-1:-1:-1;;;;;10497:16:3;;;;;8365:18:24;;10497:31:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:49;;;;:::i;:::-;10461:85;;10577:13;10561;:29;10557:229;;;10621:13;10606:28;;10668:7;10648:27;;10557:229;;;10721:13;10706:28;;10768:7;10748:27;;10557:229;10819:1;10804:12;:16;10796:60;;;;-1:-1:-1;;;10796:60:3;;17581:2:24;10796:60:3;;;17563:21:24;17620:2;17600:18;;;17593:30;17659:33;17639:18;;;17632:61;17710:18;;10796:60:3;17553:181:24;10796:60:3;9234:1629;;;;;;;;;;;;;;;;;;;:::o;10869:1378::-;11169:125;;-1:-1:-1;;;11169:125:3;;-1:-1:-1;;;;;8684:15:24;;;11169:125:3;;;8666:34:24;8736:15;;8716:18;;;8709:43;11049:20:3;;;;;;3678:42;;11169:31;;8601:18:24;;11169:125:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;11103:205;;11319:12;11333;11351:4;-1:-1:-1;;;;;11351:16:3;;:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;11318:51;-1:-1:-1;;;;;11318:51:3;;;-1:-1:-1;;;;;11318:51:3;;;11405:16;-1:-1:-1;;;;;11383:38:3;:18;-1:-1:-1;;;;;11383:38:3;;11379:862;;;11437:20;11460:36;11482:4;11488:7;11460:21;:36::i;:::-;11437:59;;11583:1;11567:12;:17;11563:49;;11601:11;11611:1;11601:7;:11;:::i;:::-;11586:26;;11563:49;11641:126;11671:18;11707:16;11741:12;11641;:126::i;:::-;11626:141;-1:-1:-1;11796:22:3;11806:12;11796:7;:22;:::i;:::-;11781:37;;11379:862;;;;11849:20;11872:36;11894:4;11900:7;11872:21;:36::i;:::-;11849:59;;11995:1;11979:12;:17;11975:49;;12013:11;12023:1;12013:7;:11;:::i;:::-;11998:26;;11975:49;12053:126;12083:18;12119:16;12153:12;12053;:126::i;:::-;12038:141;-1:-1:-1;12208:22:3;12218:12;12208:7;:22;:::i;:::-;12193:37;;11379:862;;10869:1378;;;;;;;;;;:::o;7926:1302::-;8130:7;8149:71;8163:16;3809:42;8207:12;8149:13;:71::i;:::-;8230;8244:16;3809:42;8288:12;8230:13;:71::i;:::-;8373:265;;-1:-1:-1;;;8373:265:3;;-1:-1:-1;;;;;9558:15:24;;;8373:265:3;;;9540:34:24;9610:15;;9590:18;;;9583:43;9642:18;;;9635:34;;;9685:18;;;9678:34;;;8547:1:3;9728:19:24;;;9721:35;;;9772:19;;;9765:35;8593:4:3;9816:19:24;;;9809:44;-1:-1:-1;;;9869:19:24;;;9862:35;8313:15:3;;;;;;3809:42;;8373:28;;9474:19:24;;8373:265:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8312:326;;;;;;8653:16;8649:553;;;8765:1;8740:22;8755:7;8740:12;:22;:::i;:::-;:26;8736:196;;;8786:131;8845:10;8877:22;8892:7;8877:12;:22;:::i;:::-;-1:-1:-1;;;;;8786:37:3;;;:131;:37;:131::i;:::-;9025:1;9000:22;9015:7;9000:12;:22;:::i;:::-;:26;8996:196;;;9046:131;9105:10;9137:22;9152:7;9137:12;:22;:::i;:::-;-1:-1:-1;;;;;9046:37:3;;;:131;:37;:131::i;:::-;9219:2;7926:1302;-1:-1:-1;;;;;;;;7926:1302:3:o;3683:223:19:-;3816:12;3847:52;3869:6;3877:4;3883:1;3886:12;3847:21;:52::i;:::-;3840:59;;3683:223;;;;;;:::o;1786:216:9:-;1906:37;-1:-1:-1;;;;;1906:25:9;;1932:7;1941:1;1906:25;:37::i;:::-;1953:42;-1:-1:-1;;;;;1953:25:9;;1979:7;1988:6;1953:25;:42::i;12253:295:3:-;12366:7;12537:4;12516:16;:9;12528:4;12516:16;:::i;:::-;12409:103;12477:19;:9;12489:7;12477:19;:::i;:::-;12456:16;:6;12465:7;12456:16;:::i;:::-;12455:42;;;;:::i;:::-;12442:56;;:9;:56;:::i;:::-;12409:15;:103::i;:::-;:124;;;;:::i;:::-;12408:133;;;;:::i;12868:1061::-;13028:19;13092:23;-1:-1:-1;;;;;13063:52:3;:25;-1:-1:-1;;;;;13063:52:3;;13059:102;;;-1:-1:-1;13138:12:3;13131:19;;13059:102;13171:126;13198:25;3809:42;13275:12;13171:13;:126::i;:::-;13335:129;;-1:-1:-1;;;13335:129:3;;-1:-1:-1;;;;;8684:15:24;;;13335:129:3;;;8666:34:24;8736:15;;8716:18;;;8709:43;13308:12:3;;3678:42;;13335:31;;8601:18:24;;13335:129:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;13308:156;-1:-1:-1;;;;;;13482:18:3;;13474:48;;;;-1:-1:-1;;;13474:48:3;;18299:2:24;13474:48:3;;;18281:21:24;18338:2;18318:18;;;18311:30;-1:-1:-1;;;18357:18:24;;;18350:47;18414:18;;13474:48:3;18271:167:24;13474:48:3;13556:16;;;13570:1;13556:16;;;;;;;;13532:21;;13556:16;;;;;;;;;;-1:-1:-1;13556:16:3;13532:40;;13592:25;13582:4;13587:1;13582:7;;;;;;-1:-1:-1;;;13582:7:3;;;;;;;;;;;;;;:35;-1:-1:-1;;;;;13582:35:3;;;-1:-1:-1;;;;;13582:35:3;;;;;13637:23;13627:4;13632:1;13627:7;;;;;;-1:-1:-1;;;13627:7:3;;;;;;;;;-1:-1:-1;;;;;13627:33:3;;;:7;;;;;;;;;;;:33;13685:158;;-1:-1:-1;;;13685:158:3;;3809:42;;13685:40;;:158;;13739:12;;13765:1;;13780:4;;13806;;-1:-1:-1;;;4015:66:3;13685:158;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;13685:158:3;;;;;;;;;;;;:::i;:::-;13858:1;13844:4;:11;:15;;;;:::i;:::-;13685:175;;;;;;-1:-1:-1;;;13685:175:3;;;;;;;;;;;;;;;13671:189;;13893:1;13879:11;:15;13871:51;;;;-1:-1:-1;;;13871:51:3;;16464:2:24;13871:51:3;;;16446:21:24;16503:2;16483:18;;;16476:30;16542:25;16522:18;;;16515:53;16585:18;;13871:51:3;16436:173:24;13871:51:3;12868:1061;;;;;;;:::o;4860:607:19:-;5025:12;5095:5;5070:21;:30;;5049:115;;;;-1:-1:-1;;;5049:115:19;;14250:2:24;5049:115:19;;;14232:21:24;14289:2;14269:18;;;14262:30;14328:34;14308:18;;;14301:62;-1:-1:-1;;;14379:18:24;;;14372:36;14425:19;;5049:115:19;14222:228:24;5049:115:19;1090:20;;5174:60;;;;-1:-1:-1;;;5174:60:19;;17941:2:24;5174:60:19;;;17923:21:24;17980:2;17960:18;;;17953:30;18019:31;17999:18;;;17992:59;18068:18;;5174:60:19;17913:179:24;5174:60:19;5305:12;5319:23;5358:6;-1:-1:-1;;;;;5358:11:19;5378:5;5386:4;5358:33;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5304:87;;;;5408:52;5426:7;5435:10;5447:12;5408:17;:52::i;:::-;5401:59;4860:607;-1:-1:-1;;;;;;;4860:607:19:o;1414:690:17:-;1822:10;;;1821:62;;-1:-1:-1;1838:39:17;;-1:-1:-1;;;1838:39:17;;1862:4;1838:39;;;8666:34:24;-1:-1:-1;;;;;8736:15:24;;;8716:18;;;8709:43;1838:15:17;;;;;8601:18:24;;1838:39:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:44;1821:62;1800:163;;;;-1:-1:-1;;;1800:163:17;;19056:2:24;1800:163:17;;;19038:21:24;19095:2;19075:18;;;19068:30;19134:34;19114:18;;;19107:62;-1:-1:-1;;;19185:18:24;;;19178:52;19247:19;;1800:163:17;19028:244:24;1800:163:17;2025:62;;-1:-1:-1;;;;;10100:32:24;;2025:62:17;;;10082:51:24;10149:18;;;10142:34;;;1973:124:17;;2006:5;;-1:-1:-1;;;2048:22:17;10055:18:24;;2025:62:17;10037:145:24;2001:323:3;2049:9;2078:1;2074;:5;2070:226;;;-1:-1:-1;2099:1:3;2114:9;2126:5;2130:1;2099;2126:5;:::i;:::-;:9;;2134:1;2126:9;:::i;:::-;2114:21;;2149:89;2160:1;2156;:5;2149:89;;;2185:1;-1:-1:-1;2185:1:3;2222;2185;2209:5;2185:1;2209;:5;:::i;:::-;:9;;;;:::i;:::-;2208:15;;;;:::i;:::-;2204:19;;2149:89;;;2070:226;2001:323;;;:::o;2070:226::-;2258:6;;2254:42;;-1:-1:-1;2284:1:3;2254:42;2001:323;;;:::o;7683:756:19:-;7829:12;7857:7;7853:580;;;-1:-1:-1;7887:10:19;7880:17;;7853:580;7998:17;;:21;7994:429;;8256:10;8250:17;8316:15;8303:10;8299:2;8295:19;8288:44;8205:145;8395:12;8388:20;;-1:-1:-1;;;8388:20:19;;;;;;;;:::i;14:134:24:-;82:20;;111:31;82:20;111:31;:::i;153:391::-;216:8;226:6;280:3;273:4;265:6;261:17;257:27;247:2;;303:6;295;288:22;247:2;-1:-1:-1;331:20:24;;374:18;363:30;;360:2;;;413:8;403;396:26;360:2;457:4;449:6;445:17;433:29;;517:3;510:4;500:6;497:1;493:14;485:6;481:27;477:38;474:47;471:2;;;534:1;531;524:12;471:2;237:307;;;;;:::o;549:128::-;614:20;;643:28;614:20;643:28;:::i;682:188::-;761:13;;-1:-1:-1;;;;;803:42:24;;793:53;;783:2;;860:1;857;850:12;875:257;934:6;987:2;975:9;966:7;962:23;958:32;955:2;;;1008:6;1000;993:22;955:2;1052:9;1039:23;1071:31;1096:5;1071:31;:::i;1137:261::-;1207:6;1260:2;1248:9;1239:7;1235:23;1231:32;1228:2;;;1281:6;1273;1266:22;1228:2;1318:9;1312:16;1337:31;1362:5;1337:31;:::i;1403:398::-;1471:6;1479;1532:2;1520:9;1511:7;1507:23;1503:32;1500:2;;;1553:6;1545;1538:22;1500:2;1597:9;1584:23;1616:31;1641:5;1616:31;:::i;:::-;1666:5;-1:-1:-1;1723:2:24;1708:18;;1695:32;1736:33;1695:32;1736:33;:::i;:::-;1788:7;1778:17;;;1490:311;;;;;:::o;1806:1410::-;1942:6;1950;1958;1966;1974;1982;1990;1998;2006;2014;2067:3;2055:9;2046:7;2042:23;2038:33;2035:2;;;2089:6;2081;2074:22;2035:2;2133:9;2120:23;2152:31;2177:5;2152:31;:::i;:::-;2202:5;-1:-1:-1;2259:2:24;2244:18;;2231:32;2272:33;2231:32;2272:33;:::i;:::-;2324:7;-1:-1:-1;2378:2:24;2363:18;;2350:32;;-1:-1:-1;2429:2:24;2414:18;;2401:32;;-1:-1:-1;2485:3:24;2470:19;;2457:33;2499;2457;2499;:::i;:::-;2551:7;-1:-1:-1;2609:3:24;2594:19;;2581:33;2633:18;2663:14;;;2660:2;;;2695:6;2687;2680:22;2660:2;2738:6;2727:9;2723:22;2713:32;;2783:7;2776:4;2772:2;2768:13;2764:27;2754:2;;2810:6;2802;2795:22;2754:2;2855;2842:16;2881:2;2873:6;2870:14;2867:2;;;2902:6;2894;2887:22;2867:2;2952:7;2947:2;2938:6;2934:2;2930:15;2926:24;2923:37;2920:2;;;2978:6;2970;2963:22;2920:2;3014;3010;3006:11;2996:21;;3036:6;3026:16;;;;;3061:39;3095:3;3084:9;3080:19;3061:39;:::i;:::-;3051:49;;3119:36;3150:3;3139:9;3135:19;3119:36;:::i;:::-;3109:46;;3174:36;3205:3;3194:9;3190:19;3174:36;:::i;:::-;3164:46;;2025:1191;;;;;;;;;;;;;:::o;3221:392::-;3286:6;3294;3347:2;3335:9;3326:7;3322:23;3318:32;3315:2;;;3368:6;3360;3353:22;3315:2;3412:9;3399:23;3431:31;3456:5;3431:31;:::i;:::-;3481:5;-1:-1:-1;3538:2:24;3523:18;;3510:32;3551:30;3510:32;3551:30;:::i;3618:457::-;3704:6;3712;3765:2;3753:9;3744:7;3740:23;3736:32;3733:2;;;3786:6;3778;3771:22;3733:2;3831:9;3818:23;3864:18;3856:6;3853:30;3850:2;;;3901:6;3893;3886:22;3850:2;3945:70;4007:7;3998:6;3987:9;3983:22;3945:70;:::i;:::-;4034:8;;3919:96;;-1:-1:-1;3723:352:24;-1:-1:-1;;;;3723:352:24:o;4080:800::-;4199:6;4207;4215;4223;4276:2;4264:9;4255:7;4251:23;4247:32;4244:2;;;4297:6;4289;4282:22;4244:2;4342:9;4329:23;4371:18;4412:2;4404:6;4401:14;4398:2;;;4433:6;4425;4418:22;4398:2;4477:70;4539:7;4530:6;4519:9;4515:22;4477:70;:::i;:::-;4566:8;;-1:-1:-1;4451:96:24;-1:-1:-1;4654:2:24;4639:18;;4626:32;;-1:-1:-1;4670:16:24;;;4667:2;;;4704:6;4696;4689:22;4667:2;;4748:72;4812:7;4801:8;4790:9;4786:24;4748:72;:::i;:::-;4234:646;;;;-1:-1:-1;4839:8:24;-1:-1:-1;;;;4234:646:24:o;4885:1161::-;4980:6;5011:2;5054;5042:9;5033:7;5029:23;5025:32;5022:2;;;5075:6;5067;5060:22;5022:2;5113:9;5107:16;5142:18;5183:2;5175:6;5172:14;5169:2;;;5204:6;5196;5189:22;5169:2;5247:6;5236:9;5232:22;5222:32;;5292:7;5285:4;5281:2;5277:13;5273:27;5263:2;;5319:6;5311;5304:22;5263:2;5353;5347:9;5375:2;5371;5368:10;5365:2;;;5381:18;;:::i;:::-;5427:2;5424:1;5420:10;5459:2;5453:9;5522:2;5518:7;5513:2;5509;5505:11;5501:25;5493:6;5489:38;5577:6;5565:10;5562:22;5557:2;5545:10;5542:18;5539:46;5536:2;;;5588:18;;:::i;:::-;5624:2;5617:22;5674:18;;;5708:15;;;;-1:-1:-1;5743:11:24;;;5773;;;5769:20;;5766:33;-1:-1:-1;5763:2:24;;;5817:6;5809;5802:22;5763:2;5844:6;5835:15;;5859:156;5873:2;5870:1;5867:9;5859:156;;;5930:10;;5918:23;;5891:1;5884:9;;;;;5961:12;;;;5993;;5859:156;;;-1:-1:-1;6034:6:24;4991:1055;-1:-1:-1;;;;;;;;4991:1055:24:o;6051:251::-;6107:6;6160:2;6148:9;6139:7;6135:23;6131:32;6128:2;;;6181:6;6173;6166:22;6128:2;6225:9;6212:23;6244:28;6266:5;6244:28;:::i;6307:255::-;6374:6;6427:2;6415:9;6406:7;6402:23;6398:32;6395:2;;;6448:6;6440;6433:22;6395:2;6485:9;6479:16;6504:28;6526:5;6504:28;:::i;6567:470::-;6654:6;6662;6670;6723:2;6711:9;6702:7;6698:23;6694:32;6691:2;;;6744:6;6736;6729:22;6691:2;6772:40;6802:9;6772:40;:::i;:::-;6762:50;;6831:49;6876:2;6865:9;6861:18;6831:49;:::i;:::-;6821:59;;6923:2;6912:9;6908:18;6902:25;6967:10;6960:5;6956:22;6949:5;6946:33;6936:2;;6998:6;6990;6983:22;6936:2;7026:5;7016:15;;;6681:356;;;;;:::o;7042:190::-;7101:6;7154:2;7142:9;7133:7;7129:23;7125:32;7122:2;;;7175:6;7167;7160:22;7122:2;-1:-1:-1;7203:23:24;;7112:120;-1:-1:-1;7112:120:24:o;7237:194::-;7307:6;7360:2;7348:9;7339:7;7335:23;7331:32;7328:2;;;7381:6;7373;7366:22;7328:2;-1:-1:-1;7409:16:24;;7318:113;-1:-1:-1;7318:113:24:o;7436:316::-;7524:6;7532;7540;7593:2;7581:9;7572:7;7568:23;7564:32;7561:2;;;7614:6;7606;7599:22;7561:2;7648:9;7642:16;7632:26;;7698:2;7687:9;7683:18;7677:25;7667:35;;7742:2;7731:9;7727:18;7721:25;7711:35;;7551:201;;;;;:::o;7757:274::-;7886:3;7924:6;7918:13;7940:53;7986:6;7981:3;7974:4;7966:6;7962:17;7940:53;:::i;:::-;8009:16;;;;;7894:137;-1:-1:-1;;7894:137:24:o;10379:383::-;10528:2;10517:9;10510:21;10491:4;10560:6;10554:13;10603:6;10598:2;10587:9;10583:18;10576:34;10619:66;10678:6;10673:2;10662:9;10658:18;10653:2;10645:6;10641:15;10619:66;:::i;:::-;10746:2;10725:15;-1:-1:-1;;10721:29:24;10706:45;;;;10753:2;10702:54;;10500:262;-1:-1:-1;;10500:262:24:o;15901:356::-;16103:2;16085:21;;;16122:18;;;16115:30;16181:34;16176:2;16161:18;;16154:62;16248:2;16233:18;;16075:182::o;19459:983::-;19721:4;19769:3;19758:9;19754:19;19800:6;19789:9;19782:25;19826:2;19864:6;19859:2;19848:9;19844:18;19837:34;19907:3;19902:2;19891:9;19887:18;19880:31;19931:6;19966;19960:13;19997:6;19989;19982:22;20035:3;20024:9;20020:19;20013:26;;20074:2;20066:6;20062:15;20048:29;;20095:4;20108:195;20122:6;20119:1;20116:13;20108:195;;;20187:13;;-1:-1:-1;;;;;20183:39:24;20171:52;;20278:15;;;;20243:12;;;;20219:1;20137:9;20108:195;;;-1:-1:-1;;;;;;;20359:32:24;;;;20354:2;20339:18;;20332:60;-1:-1:-1;;;20423:3:24;20408:19;20401:35;20320:3;19730:712;-1:-1:-1;;;19730:712:24:o;20447:128::-;20487:3;20518:1;20514:6;20511:1;20508:13;20505:2;;;20524:18;;:::i;:::-;-1:-1:-1;20560:9:24;;20495:80::o;20580:217::-;20620:1;20646;20636:2;;-1:-1:-1;;;20671:31:24;;20725:4;20722:1;20715:15;20753:4;20678:1;20743:15;20636:2;-1:-1:-1;20782:9:24;;20626:171::o;20802:168::-;20842:7;20908:1;20904;20900:6;20896:14;20893:1;20890:21;20885:1;20878:9;20871:17;20867:45;20864:2;;;20915:18;;:::i;:::-;-1:-1:-1;20955:9:24;;20854:116::o;20975:125::-;21015:4;21043:1;21040;21037:8;21034:2;;;21048:18;;:::i;:::-;-1:-1:-1;21085:9:24;;21024:76::o;21105:258::-;21177:1;21187:113;21201:6;21198:1;21195:13;21187:113;;;21277:11;;;21271:18;21258:11;;;21251:39;21223:2;21216:10;21187:113;;;21318:6;21315:1;21312:13;21309:2;;;-1:-1:-1;;21353:1:24;21335:16;;21328:27;21158:205::o;21368:135::-;21407:3;-1:-1:-1;;21428:17:24;;21425:2;;;21448:18;;:::i;:::-;-1:-1:-1;21495:1:24;21484:13;;21415:88::o;21508:127::-;21569:10;21564:3;21560:20;21557:1;21550:31;21600:4;21597:1;21590:15;21624:4;21621:1;21614:15;21640:127;21701:10;21696:3;21692:20;21689:1;21682:31;21732:4;21729:1;21722:15;21756:4;21753:1;21746:15;21772:131;-1:-1:-1;;;;;21847:31:24;;21837:42;;21827:2;;21893:1;21890;21883:12;21827:2;21817:86;:::o;21908:118::-;21994:5;21987:13;21980:21;21973:5;21970:32;21960:2;;22016:1;22013;22006:12

Swarm Source

ipfs://93a216e290171f480c3473d6e0c0dc0a80bed08403202d7e7e4560faccd45aa3
Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.