ETH Price: $2,380.59 (-1.14%)

Contract

0xf12a2f510cB9F970ee21207c9A72C2Ef560f42E5
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Set Contract Pau...159937462022-11-18 1:54:35667 days ago1668736475IN
0xf12a2f51...f560f42E5
0 ETH0.0005557811.75569275
Proxy Swap With ...159146122022-11-07 0:38:35678 days ago1667781515IN
0xf12a2f51...f560f42E5
0 ETH0.0015283711.6519531
Proxy Swap With ...159140692022-11-06 22:49:11678 days ago1667774951IN
0xf12a2f51...f560f42E5
0 ETH0.0043969612.47978827
Proxy Swap With ...159140672022-11-06 22:48:47678 days ago1667774927IN
0xf12a2f51...f560f42E5
0 ETH0.0042126212.56192068
Proxy Swap With ...158870302022-11-03 4:12:47682 days ago1667448767IN
0xf12a2f51...f560f42E5
0 ETH0.0030545216.41768519
Proxy Swap With ...158870012022-11-03 4:06:59682 days ago1667448419IN
0xf12a2f51...f560f42E5
0 ETH0.0027685514.88350087
Proxy Swap With ...158769932022-11-01 18:33:23683 days ago1667327603IN
0xf12a2f51...f560f42E5
0.009 ETH0.0052142715.13992012
Proxy Swap With ...158768482022-11-01 18:04:23684 days ago1667325863IN
0xf12a2f51...f560f42E5
0 ETH0.0034618.3027459
Proxy Swap With ...158768292022-11-01 18:00:35684 days ago1667325635IN
0xf12a2f51...f560f42E5
0 ETH0.0077065819.69317095
Proxy Swap With ...158767622022-11-01 17:46:59684 days ago1667324819IN
0xf12a2f51...f560f42E5
0.016 ETH0.0059791120.50197867
Proxy Swap With ...158724602022-11-01 3:17:23684 days ago1667272643IN
0xf12a2f51...f560f42E5
0.019 ETH0.0032025411.78007469
Proxy Swap With ...158723872022-11-01 3:02:35684 days ago1667271755IN
0xf12a2f51...f560f42E5
0 ETH0.0025385115.15856203
Proxy Swap With ...158646552022-10-31 1:07:35685 days ago1667178455IN
0xf12a2f51...f560f42E5
0.003 ETH0.002203138.27701868
Proxy Swap With ...156783962022-10-05 0:40:47711 days ago1664930447IN
0xf12a2f51...f560f42E5
0 ETH0.0036043611.70918622
Proxy Swap With ...156782462022-10-05 0:10:23711 days ago1664928623IN
0xf12a2f51...f560f42E5
0 ETH0.0035213911.18401622
Grant Role156782072022-10-05 0:02:23711 days ago1664928143IN
0xf12a2f51...f560f42E5
0 ETH0.001114111.05698499
Proxy Swap With ...156160202022-09-26 7:20:59720 days ago1664176859IN
0xf12a2f51...f560f42E5
0 ETH0.00090065.38508261
Proxy Swap With ...156158132022-09-26 6:39:23720 days ago1664174363IN
0xf12a2f51...f560f42E5
0.016 ETH0.0029774512.5291445
Proxy Swap With ...156137762022-09-25 23:49:47720 days ago1664149787IN
0xf12a2f51...f560f42E5
0 ETH0.001958476.11874179
Proxy Swap With ...156136362022-09-25 23:21:35720 days ago1664148095IN
0xf12a2f51...f560f42E5
0 ETH0.001972526.75170278
Proxy Swap With ...155941122022-09-23 5:59:35723 days ago1663912775IN
0xf12a2f51...f560f42E5
0 ETH0.001028276.1477929
Proxy Swap With ...155938402022-09-23 5:04:59723 days ago1663909499IN
0xf12a2f51...f560f42E5
0.01847561 ETH0.003508112.90219322
Proxy Swap With ...155937952022-09-23 4:55:59723 days ago1663908959IN
0xf12a2f51...f560f42E5
0 ETH0.0042673412.36755159
Proxy Swap With ...155937512022-09-23 4:47:11723 days ago1663908431IN
0xf12a2f51...f560f42E5
0.02229398 ETH0.001858986.83702712
Proxy Swap With ...155779952022-09-20 23:35:11725 days ago1663716911IN
0xf12a2f51...f560f42E5
0 ETH0.0020139810.75907282
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
159146122022-11-07 0:38:35678 days ago1667781515
0xf12a2f51...f560f42E5
0.00038761 ETH
159146122022-11-07 0:38:35678 days ago1667781515
0xf12a2f51...f560f42E5
0.00736475 ETH
159146122022-11-07 0:38:35678 days ago1667781515
0xf12a2f51...f560f42E5
0.00775237 ETH
159140692022-11-06 22:49:11678 days ago1667774951
0xf12a2f51...f560f42E5
0.00029745 ETH
159140672022-11-06 22:48:47678 days ago1667774927
0xf12a2f51...f560f42E5
0.01034052 ETH
159140672022-11-06 22:48:47678 days ago1667774927
0xf12a2f51...f560f42E5
0.01034052 ETH
158870302022-11-03 4:12:47682 days ago1667448767
0xf12a2f51...f560f42E5
0.01354167 ETH
158870302022-11-03 4:12:47682 days ago1667448767
0xf12a2f51...f560f42E5
0.00574659 ETH
158870302022-11-03 4:12:47682 days ago1667448767
0xf12a2f51...f560f42E5
0.01928826 ETH
158870012022-11-03 4:06:59682 days ago1667448419
0xf12a2f51...f560f42E5
0.00096418 ETH
158870012022-11-03 4:06:59682 days ago1667448419
0xf12a2f51...f560f42E5
0.01831945 ETH
158870012022-11-03 4:06:59682 days ago1667448419
0xf12a2f51...f560f42E5
0.01928363 ETH
158769932022-11-01 18:33:23683 days ago1667327603
0xf12a2f51...f560f42E5
0.0004504 ETH
158769932022-11-01 18:33:23683 days ago1667327603
0xf12a2f51...f560f42E5
0.009 ETH
158768482022-11-01 18:04:23684 days ago1667325863
0xf12a2f51...f560f42E5
0.00047488 ETH
158768482022-11-01 18:04:23684 days ago1667325863
0xf12a2f51...f560f42E5
0.00902285 ETH
158768482022-11-01 18:04:23684 days ago1667325863
0xf12a2f51...f560f42E5
0.00949774 ETH
158768292022-11-01 18:00:35684 days ago1667325635
0xf12a2f51...f560f42E5
0.0001487 ETH
158768292022-11-01 18:00:35684 days ago1667325635
0xf12a2f51...f560f42E5
0.0001487 ETH
158767622022-11-01 17:46:59684 days ago1667324819
0xf12a2f51...f560f42E5
0.01545072 ETH
158767622022-11-01 17:46:59684 days ago1667324819
0xf12a2f51...f560f42E5
0.01545072 ETH
158767622022-11-01 17:46:59684 days ago1667324819
0xf12a2f51...f560f42E5
0.016 ETH
158724602022-11-01 3:17:23684 days ago1667272643
0xf12a2f51...f560f42E5
0.01826261 ETH
158724602022-11-01 3:17:23684 days ago1667272643
0xf12a2f51...f560f42E5
0.01826261 ETH
158724602022-11-01 3:17:23684 days ago1667272643
0xf12a2f51...f560f42E5
0.019 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ForwardingSwapProxy

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 1000 runs

Other Settings:
default evmVersion
File 1 of 35 : ForwardingSwapProxy.sol
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

import "prb-math/contracts/PRBMathSD59x18.sol";
import "prb-math/contracts/PRBMathUD60x18.sol";

import "./interfaces/IERC20Extension.sol";
import "./interfaces/IForwardingSwapProxy.sol";

import "./BaseSwapProxy.sol";
import "./Whitelist.sol";

/// @title ForwardingSwapProxy
contract ForwardingSwapProxy is
    AccessControlEnumerable,
    Pausable,
    ReentrancyGuard,
    BaseSwapProxy,
    Whitelist,
    IForwardingSwapProxy
{
    // Using Fixed point calculations for these types
    using PRBMathSD59x18 for int256;
    using PRBMathUD60x18 for uint256;

    using UniswapV2Helpers for IUniswapV2Router02;

    constructor(address _admin) BaseSwapProxy(_admin) Whitelist(_admin) {}

    function _swapTokensWithChecks(
        IERC20Extension _fromToken,
        IERC20Extension _toToken,
        SwapParams calldata _swapParams,
        uint256 _minimumReturnAmount
    ) internal returns (uint256 amountReturned) {
        require(isWhitelisted(_swapParams.to), "Not whitelisted");

        if (isEth(_fromToken)) {
            require(msg.value >= _swapParams.value, "Not enough ETH provided");
        } else {
            _fromToken.transferFrom(
                _msgSender(),
                address(this),
                _swapParams.amount
            );

            _handleApprovalFromThis(
                _fromToken,
                _swapParams.to,
                _swapParams.amount
            );
        }

        // Taking the balance of _toToken before and after, this ensures compatibility with all swap services. Some might return the value within the data response, but inconsistent across swap providers
        uint256 beforeBalanceToToken = returnTokenBalance(
            _toToken,
            address(this)
        );

        // Execute the swap
        (bool success, ) = _swapParams.to.call{value: msg.value}(
            _swapParams.data
        );
        require(success, "Proxied Swap Failed");

        uint256 afterBalanceToToken = returnTokenBalance(
            _toToken,
            address(this)
        );

        amountReturned = afterBalanceToToken - beforeBalanceToToken;

        require(
            amountReturned > _minimumReturnAmount,
            "Not enough tokens returned"
        );
    }

    function proxySwapWithFee(
        IERC20Extension _fromToken,
        IERC20Extension _toToken,
        SwapParams calldata _swapParams,
        uint256 _gasRefund,
        uint256 _minimumReturnAmount
    ) external payable override whenNotPaused nonReentrant {
        require(_fromToken != _toToken, "_fromToken equal to _toToken");

        uint256 amountReturned = _swapTokensWithChecks(
            _fromToken,
            _toToken,
            _swapParams,
            _minimumReturnAmount
        );

        (uint256 feeTotalInETH, ) = calculatePercentageFeeInETH(
            _toToken,
            amountReturned,
            _gasRefund
        );

        if (isEth(_toToken)) {
            amountReturned -= feeTotalInETH;

            require(
                amountReturned > _minimumReturnAmount,
                "Not enough tokens returned"
            );

            payable(_msgSender()).transfer(amountReturned);
        } else {
            uint256 swappedAmountIn;

            if (feeTotalInETH > 0) {
                _handleApprovalFromThis(
                    _toToken,
                    address(uniswapV2Router),
                    amountReturned
                );

                (swappedAmountIn, ) = uniswapV2Router._swapTokensForExactETH(
                    _toToken,
                    feeTotalInETH,
                    amountReturned,
                    address(this)
                );
            }

            amountReturned -= swappedAmountIn;

            require(
                amountReturned > _minimumReturnAmount,
                "Not enough tokens returned"
            );

            _toToken.transfer(_msgSender(), amountReturned);
        }

        if (feeTotalInETH > 0) {
            // Transfer the vault the fees paid
            vault.paidFees{value: feeTotalInETH}(_msgSender(), feeTotalInETH);
        }
    }
}

File 2 of 35 : AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

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

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }
}

File 3 of 35 : Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 4 of 35 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 5 of 35 : IUniswapV2Router02.sol
pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

File 6 of 35 : PRBMathSD59x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

import "./PRBMath.sol";

/// @title PRBMathSD59x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with int256 numbers considered to have 18
/// trailing decimals. We call this number representation signed 59.18-decimal fixed-point, since the numbers can have
/// a sign and there can be up to 59 digits in the integer part and up to 18 decimals in the fractional part. The numbers
/// are bound by the minimum and the maximum values permitted by the Solidity type int256.
library PRBMathSD59x18 {
    /// @dev log2(e) as a signed 59.18-decimal fixed-point number.
    int256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev Half the SCALE number.
    int256 internal constant HALF_SCALE = 5e17;

    /// @dev The maximum value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MAX_SD59x18 =
        57896044618658097711785492504343953926634992332820282019728_792003956564819967;

    /// @dev The maximum whole value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MAX_WHOLE_SD59x18 =
        57896044618658097711785492504343953926634992332820282019728_000000000000000000;

    /// @dev The minimum value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MIN_SD59x18 =
        -57896044618658097711785492504343953926634992332820282019728_792003956564819968;

    /// @dev The minimum whole value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MIN_WHOLE_SD59x18 =
        -57896044618658097711785492504343953926634992332820282019728_000000000000000000;

    /// @dev How many trailing decimals can be represented.
    int256 internal constant SCALE = 1e18;

    /// INTERNAL FUNCTIONS ///

    /// @notice Calculate the absolute value of x.
    ///
    /// @dev Requirements:
    /// - x must be greater than MIN_SD59x18.
    ///
    /// @param x The number to calculate the absolute value for.
    /// @param result The absolute value of x.
    function abs(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x == MIN_SD59x18) {
                revert PRBMathSD59x18__AbsInputTooSmall();
            }
            result = x < 0 ? -x : x;
        }
    }

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as a signed 59.18-decimal fixed-point number.
    /// @param y The second operand as a signed 59.18-decimal fixed-point number.
    /// @return result The arithmetic average as a signed 59.18-decimal fixed-point number.
    function avg(int256 x, int256 y) internal pure returns (int256 result) {
        // The operations can never overflow.
        unchecked {
            int256 sum = (x >> 1) + (y >> 1);
            if (sum < 0) {
                // If at least one of x and y is odd, we add 1 to the result. This is because shifting negative numbers to the
                // right rounds down to infinity.
                assembly {
                    result := add(sum, and(or(x, y), 1))
                }
            } else {
                // If both x and y are odd, we add 1 to the result. This is because if both numbers are odd, the 0.5
                // remainder gets truncated twice.
                result = sum + (x & y & 1);
            }
        }
    }

    /// @notice Yields the least greatest signed 59.18 decimal fixed-point number greater than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be less than or equal to MAX_WHOLE_SD59x18.
    ///
    /// @param x The signed 59.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as a signed 58.18-decimal fixed-point number.
    function ceil(int256 x) internal pure returns (int256 result) {
        if (x > MAX_WHOLE_SD59x18) {
            revert PRBMathSD59x18__CeilOverflow(x);
        }
        unchecked {
            int256 remainder = x % SCALE;
            if (remainder == 0) {
                result = x;
            } else {
                // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                result = x - remainder;
                if (x > 0) {
                    result += SCALE;
                }
            }
        }
    }

    /// @notice Divides two signed 59.18-decimal fixed-point numbers, returning a new signed 59.18-decimal fixed-point number.
    ///
    /// @dev Variant of "mulDiv" that works with signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - All from "PRBMath.mulDiv".
    /// - None of the inputs can be MIN_SD59x18.
    /// - The denominator cannot be zero.
    /// - The result must fit within int256.
    ///
    /// Caveats:
    /// - All from "PRBMath.mulDiv".
    ///
    /// @param x The numerator as a signed 59.18-decimal fixed-point number.
    /// @param y The denominator as a signed 59.18-decimal fixed-point number.
    /// @param result The quotient as a signed 59.18-decimal fixed-point number.
    function div(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == MIN_SD59x18 || y == MIN_SD59x18) {
            revert PRBMathSD59x18__DivInputTooSmall();
        }

        // Get hold of the absolute values of x and y.
        uint256 ax;
        uint256 ay;
        unchecked {
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);
        }

        // Compute the absolute value of (x*SCALE)÷y. The result must fit within int256.
        uint256 rAbs = PRBMath.mulDiv(ax, uint256(SCALE), ay);
        if (rAbs > uint256(MAX_SD59x18)) {
            revert PRBMathSD59x18__DivOverflow(rAbs);
        }

        // Get the signs of x and y.
        uint256 sx;
        uint256 sy;
        assembly {
            sx := sgt(x, sub(0, 1))
            sy := sgt(y, sub(0, 1))
        }

        // XOR over sx and sy. This is basically checking whether the inputs have the same sign. If yes, the result
        // should be positive. Otherwise, it should be negative.
        result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Returns Euler's number as a signed 59.18-decimal fixed-point number.
    /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant).
    function e() internal pure returns (int256 result) {
        result = 2_718281828459045235;
    }

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// Caveats:
    /// - All from "exp2".
    /// - For any x less than -41.446531673892822322, the result is zero.
    ///
    /// @param x The exponent as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function exp(int256 x) internal pure returns (int256 result) {
        // Without this check, the value passed to "exp2" would be less than -59.794705707972522261.
        if (x < -41_446531673892822322) {
            return 0;
        }

        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathSD59x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            int256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - For any x less than -59.794705707972522261, the result is zero.
    ///
    /// @param x The exponent as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function exp2(int256 x) internal pure returns (int256 result) {
        // This works because 2^(-x) = 1/2^x.
        if (x < 0) {
            // 2^59.794705707972522262 is the maximum number whose inverse does not truncate down to zero.
            if (x < -59_794705707972522261) {
                return 0;
            }

            // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE.
            unchecked {
                result = 1e36 / exp2(-x);
            }
        } else {
            // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
            if (x >= 192e18) {
                revert PRBMathSD59x18__Exp2InputTooBig(x);
            }

            unchecked {
                // Convert x to the 192.64-bit fixed-point format.
                uint256 x192x64 = (uint256(x) << 64) / uint256(SCALE);

                // Safe to convert the result to int256 directly because the maximum input allowed is 192.
                result = int256(PRBMath.exp2(x192x64));
            }
        }
    }

    /// @notice Yields the greatest signed 59.18 decimal fixed-point number less than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be greater than or equal to MIN_WHOLE_SD59x18.
    ///
    /// @param x The signed 59.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as a signed 58.18-decimal fixed-point number.
    function floor(int256 x) internal pure returns (int256 result) {
        if (x < MIN_WHOLE_SD59x18) {
            revert PRBMathSD59x18__FloorUnderflow(x);
        }
        unchecked {
            int256 remainder = x % SCALE;
            if (remainder == 0) {
                result = x;
            } else {
                // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                result = x - remainder;
                if (x < 0) {
                    result -= SCALE;
                }
            }
        }
    }

    /// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right
    /// of the radix point for negative numbers.
    /// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
    /// @param x The signed 59.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as a signed 59.18-decimal fixed-point number.
    function frac(int256 x) internal pure returns (int256 result) {
        unchecked {
            result = x % SCALE;
        }
    }

    /// @notice Converts a number from basic integer form to signed 59.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be greater than or equal to MIN_SD59x18 divided by SCALE.
    /// - x must be less than or equal to MAX_SD59x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in signed 59.18-decimal fixed-point representation.
    function fromInt(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x < MIN_SD59x18 / SCALE) {
                revert PRBMathSD59x18__FromIntUnderflow(x);
            }
            if (x > MAX_SD59x18 / SCALE) {
                revert PRBMathSD59x18__FromIntOverflow(x);
            }
            result = x * SCALE;
        }
    }

    /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
    ///
    /// @dev Requirements:
    /// - x * y must fit within MAX_SD59x18, lest it overflows.
    /// - x * y cannot be negative.
    ///
    /// @param x The first operand as a signed 59.18-decimal fixed-point number.
    /// @param y The second operand as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function gm(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            int256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathSD59x18__GmOverflow(x, y);
            }

            // The product cannot be negative.
            if (xy < 0) {
                revert PRBMathSD59x18__GmNegativeProduct(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = int256(PRBMath.sqrt(uint256(xy)));
        }
    }

    /// @notice Calculates 1 / x, rounding toward zero.
    ///
    /// @dev Requirements:
    /// - x cannot be zero.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the inverse.
    /// @return result The inverse as a signed 59.18-decimal fixed-point number.
    function inv(int256 x) internal pure returns (int256 result) {
        unchecked {
            // 1e36 is SCALE * SCALE.
            result = 1e36 / x;
        }
    }

    /// @notice Calculates the natural logarithm of x.
    ///
    /// @dev Based on the insight that ln(x) = log2(x) / log2(e).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    /// - This doesn't return exactly 1 for 2718281828459045235, for that we would need more fine-grained precision.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the natural logarithm.
    /// @return result The natural logarithm as a signed 59.18-decimal fixed-point number.
    function ln(int256 x) internal pure returns (int256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 195205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }

    /// @notice Calculates the common logarithm of x.
    ///
    /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common
    /// logarithm based on the insight that log10(x) = log2(x) / log2(10).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the common logarithm.
    /// @return result The common logarithm as a signed 59.18-decimal fixed-point number.
    function log10(int256 x) internal pure returns (int256 result) {
        if (x <= 0) {
            revert PRBMathSD59x18__LogInputTooSmall(x);
        }

        // Note that the "mul" in this block is the assembly mul operation, not the "mul" function defined in this contract.
        // prettier-ignore
        assembly {
            switch x
            case 1 { result := mul(SCALE, sub(0, 18)) }
            case 10 { result := mul(SCALE, sub(1, 18)) }
            case 100 { result := mul(SCALE, sub(2, 18)) }
            case 1000 { result := mul(SCALE, sub(3, 18)) }
            case 10000 { result := mul(SCALE, sub(4, 18)) }
            case 100000 { result := mul(SCALE, sub(5, 18)) }
            case 1000000 { result := mul(SCALE, sub(6, 18)) }
            case 10000000 { result := mul(SCALE, sub(7, 18)) }
            case 100000000 { result := mul(SCALE, sub(8, 18)) }
            case 1000000000 { result := mul(SCALE, sub(9, 18)) }
            case 10000000000 { result := mul(SCALE, sub(10, 18)) }
            case 100000000000 { result := mul(SCALE, sub(11, 18)) }
            case 1000000000000 { result := mul(SCALE, sub(12, 18)) }
            case 10000000000000 { result := mul(SCALE, sub(13, 18)) }
            case 100000000000000 { result := mul(SCALE, sub(14, 18)) }
            case 1000000000000000 { result := mul(SCALE, sub(15, 18)) }
            case 10000000000000000 { result := mul(SCALE, sub(16, 18)) }
            case 100000000000000000 { result := mul(SCALE, sub(17, 18)) }
            case 1000000000000000000 { result := 0 }
            case 10000000000000000000 { result := SCALE }
            case 100000000000000000000 { result := mul(SCALE, 2) }
            case 1000000000000000000000 { result := mul(SCALE, 3) }
            case 10000000000000000000000 { result := mul(SCALE, 4) }
            case 100000000000000000000000 { result := mul(SCALE, 5) }
            case 1000000000000000000000000 { result := mul(SCALE, 6) }
            case 10000000000000000000000000 { result := mul(SCALE, 7) }
            case 100000000000000000000000000 { result := mul(SCALE, 8) }
            case 1000000000000000000000000000 { result := mul(SCALE, 9) }
            case 10000000000000000000000000000 { result := mul(SCALE, 10) }
            case 100000000000000000000000000000 { result := mul(SCALE, 11) }
            case 1000000000000000000000000000000 { result := mul(SCALE, 12) }
            case 10000000000000000000000000000000 { result := mul(SCALE, 13) }
            case 100000000000000000000000000000000 { result := mul(SCALE, 14) }
            case 1000000000000000000000000000000000 { result := mul(SCALE, 15) }
            case 10000000000000000000000000000000000 { result := mul(SCALE, 16) }
            case 100000000000000000000000000000000000 { result := mul(SCALE, 17) }
            case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) }
            case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) }
            case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) }
            case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) }
            case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) }
            case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) }
            case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) }
            case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) }
            case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) }
            case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) }
            case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) }
            case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) }
            case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) }
            case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) }
            case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) }
            case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) }
            case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) }
            case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) }
            case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) }
            case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) }
            case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) }
            case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) }
            case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) }
            case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) }
            case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) }
            case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) }
            case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) }
            case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) }
            case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) }
            case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) }
            case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) }
            case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) }
            case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) }
            default {
                result := MAX_SD59x18
            }
        }

        if (result == MAX_SD59x18) {
            // Do the fixed-point division inline to save gas. The denominator is log2(10).
            unchecked {
                result = (log2(x) * SCALE) / 3_321928094887362347;
            }
        }
    }

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than zero.
    ///
    /// Caveats:
    /// - The results are not perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as a signed 59.18-decimal fixed-point number.
    function log2(int256 x) internal pure returns (int256 result) {
        if (x <= 0) {
            revert PRBMathSD59x18__LogInputTooSmall(x);
        }
        unchecked {
            // This works because log2(x) = -log2(1/x).
            int256 sign;
            if (x >= SCALE) {
                sign = 1;
            } else {
                sign = -1;
                // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE.
                assembly {
                    x := div(1000000000000000000000000000000000000, x)
                }
            }

            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(uint256(x / SCALE));

            // The integer part of the logarithm as a signed 59.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255, SCALE is 1e18 and sign is either 1 or -1.
            result = int256(n) * SCALE;

            // This is y = x * 2^(-n).
            int256 y = x >> n;

            // If y = 1, the fractional part is zero.
            if (y == SCALE) {
                return result * sign;
            }

            // Calculate the fractional part via the iterative approximation.
            // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster.
            for (int256 delta = int256(HALF_SCALE); delta > 0; delta >>= 1) {
                y = (y * y) / SCALE;

                // Is y^2 > 2 and so in the range [2,4)?
                if (y >= 2 * SCALE) {
                    // Add the 2^(-m) factor to the logarithm.
                    result += delta;

                    // Corresponds to z/2 on Wikipedia.
                    y >>= 1;
                }
            }
            result *= sign;
        }
    }

    /// @notice Multiplies two signed 59.18-decimal fixed-point numbers together, returning a new signed 59.18-decimal
    /// fixed-point number.
    ///
    /// @dev Variant of "mulDiv" that works with signed numbers and employs constant folding, i.e. the denominator is
    /// always 1e18.
    ///
    /// Requirements:
    /// - All from "PRBMath.mulDivFixedPoint".
    /// - None of the inputs can be MIN_SD59x18
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    ///
    /// @param x The multiplicand as a signed 59.18-decimal fixed-point number.
    /// @param y The multiplier as a signed 59.18-decimal fixed-point number.
    /// @return result The product as a signed 59.18-decimal fixed-point number.
    function mul(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == MIN_SD59x18 || y == MIN_SD59x18) {
            revert PRBMathSD59x18__MulInputTooSmall();
        }

        unchecked {
            uint256 ax;
            uint256 ay;
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);

            uint256 rAbs = PRBMath.mulDivFixedPoint(ax, ay);
            if (rAbs > uint256(MAX_SD59x18)) {
                revert PRBMathSD59x18__MulOverflow(rAbs);
            }

            uint256 sx;
            uint256 sy;
            assembly {
                sx := sgt(x, sub(0, 1))
                sy := sgt(y, sub(0, 1))
            }
            result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs);
        }
    }

    /// @notice Returns PI as a signed 59.18-decimal fixed-point number.
    function pi() internal pure returns (int256 result) {
        result = 3_141592653589793238;
    }

    /// @notice Raises x to the power of y.
    ///
    /// @dev Based on the insight that x^y = 2^(log2(x) * y).
    ///
    /// Requirements:
    /// - All from "exp2", "log2" and "mul".
    /// - z cannot be zero.
    ///
    /// Caveats:
    /// - All from "exp2", "log2" and "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x Number to raise to given power y, as a signed 59.18-decimal fixed-point number.
    /// @param y Exponent to raise x to, as a signed 59.18-decimal fixed-point number.
    /// @return result x raised to power y, as a signed 59.18-decimal fixed-point number.
    function pow(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : int256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }

    /// @notice Raises x (signed 59.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - All from "abs" and "PRBMath.mulDivFixedPoint".
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - All from "PRBMath.mulDivFixedPoint".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as a signed 59.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function powu(int256 x, uint256 y) internal pure returns (int256 result) {
        uint256 xAbs = uint256(abs(x));

        // Calculate the first iteration of the loop in advance.
        uint256 rAbs = y & 1 > 0 ? xAbs : uint256(SCALE);

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        uint256 yAux = y;
        for (yAux >>= 1; yAux > 0; yAux >>= 1) {
            xAbs = PRBMath.mulDivFixedPoint(xAbs, xAbs);

            // Equivalent to "y % 2 == 1" but faster.
            if (yAux & 1 > 0) {
                rAbs = PRBMath.mulDivFixedPoint(rAbs, xAbs);
            }
        }

        // The result must fit within the 59.18-decimal fixed-point representation.
        if (rAbs > uint256(MAX_SD59x18)) {
            revert PRBMathSD59x18__PowuOverflow(rAbs);
        }

        // Is the base negative and the exponent an odd number?
        bool isNegative = x < 0 && y & 1 == 1;
        result = isNegative ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Returns 1 as a signed 59.18-decimal fixed-point number.
    function scale() internal pure returns (int256 result) {
        result = SCALE;
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Requirements:
    /// - x cannot be negative.
    /// - x must be less than MAX_SD59x18 / SCALE.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the square root.
    /// @return result The result as a signed 59.18-decimal fixed-point .
    function sqrt(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x < 0) {
                revert PRBMathSD59x18__SqrtNegativeInput(x);
            }
            if (x > MAX_SD59x18 / SCALE) {
                revert PRBMathSD59x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two signed
            // 59.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = int256(PRBMath.sqrt(uint256(x * SCALE)));
        }
    }

    /// @notice Converts a signed 59.18-decimal fixed-point number to basic integer form, rounding down in the process.
    /// @param x The signed 59.18-decimal fixed-point number to convert.
    /// @return result The same number in basic integer form.
    function toInt(int256 x) internal pure returns (int256 result) {
        unchecked {
            result = x / SCALE;
        }
    }
}

File 7 of 35 : PRBMathUD60x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

import "./PRBMath.sol";

/// @title PRBMathUD60x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18
/// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60
/// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the
/// maximum values permitted by the Solidity type uint256.
library PRBMathUD60x18 {
    /// @dev Half the SCALE number.
    uint256 internal constant HALF_SCALE = 5e17;

    /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number.
    uint256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_584007913129639935;

    /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_WHOLE_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_000000000000000000;

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // The operations can never overflow.
        unchecked {
            // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need
            // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice.
            result = (x >> 1) + (y >> 1) + (x & y & 1);
        }
    }

    /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be less than or equal to MAX_WHOLE_UD60x18.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function ceil(uint256 x) internal pure returns (uint256 result) {
        if (x > MAX_WHOLE_UD60x18) {
            revert PRBMathUD60x18__CeilOverflow(x);
        }
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "SCALE - remainder" but faster.
            let delta := sub(SCALE, remainder)

            // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster.
            result := add(x, mul(delta, gt(remainder, 0)))
        }
    }

    /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number.
    ///
    /// @dev Uses mulDiv to enable overflow-safe multiplication and division.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    ///
    /// @param x The numerator as an unsigned 60.18-decimal fixed-point number.
    /// @param y The denominator as an unsigned 60.18-decimal fixed-point number.
    /// @param result The quotient as an unsigned 60.18-decimal fixed-point number.
    function div(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDiv(x, SCALE, y);
    }

    /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number.
    /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant).
    function e() internal pure returns (uint256 result) {
        result = 2_718281828459045235;
    }

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp(uint256 x) internal pure returns (uint256 result) {
        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathUD60x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            uint256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_UD60x18.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
        if (x >= 192e18) {
            revert PRBMathUD60x18__Exp2InputTooBig(x);
        }

        unchecked {
            // Convert x to the 192.64-bit fixed-point format.
            uint256 x192x64 = (x << 64) / SCALE;

            // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation.
            result = PRBMath.exp2(x192x64);
        }
    }

    /// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x.
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    /// @param x The unsigned 60.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function floor(uint256 x) internal pure returns (uint256 result) {
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster.
            result := sub(x, mul(remainder, gt(remainder, 0)))
        }
    }

    /// @notice Yields the excess beyond the floor of x.
    /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part.
    /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number.
    function frac(uint256 x) internal pure returns (uint256 result) {
        assembly {
            result := mod(x, SCALE)
        }
    }

    /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be less than or equal to MAX_UD60x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in unsigned 60.18-decimal fixed-point representation.
    function fromUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__FromUintOverflow(x);
            }
            result = x * SCALE;
        }
    }

    /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
    ///
    /// @dev Requirements:
    /// - x * y must fit within MAX_UD60x18, lest it overflows.
    ///
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function gm(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            uint256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathUD60x18__GmOverflow(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = PRBMath.sqrt(xy);
        }
    }

    /// @notice Calculates 1 / x, rounding toward zero.
    ///
    /// @dev Requirements:
    /// - x cannot be zero.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse.
    /// @return result The inverse as an unsigned 60.18-decimal fixed-point number.
    function inv(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // 1e36 is SCALE * SCALE.
            result = 1e36 / x;
        }
    }

    /// @notice Calculates the natural logarithm of x.
    ///
    /// @dev Based on the insight that ln(x) = log2(x) / log2(e).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm.
    /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number.
    function ln(uint256 x) internal pure returns (uint256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 196205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }

    /// @notice Calculates the common logarithm of x.
    ///
    /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common
    /// logarithm based on the insight that log10(x) = log2(x) / log2(10).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm.
    /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number.
    function log10(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }

        // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined
        // in this contract.
        // prettier-ignore
        assembly {
            switch x
            case 1 { result := mul(SCALE, sub(0, 18)) }
            case 10 { result := mul(SCALE, sub(1, 18)) }
            case 100 { result := mul(SCALE, sub(2, 18)) }
            case 1000 { result := mul(SCALE, sub(3, 18)) }
            case 10000 { result := mul(SCALE, sub(4, 18)) }
            case 100000 { result := mul(SCALE, sub(5, 18)) }
            case 1000000 { result := mul(SCALE, sub(6, 18)) }
            case 10000000 { result := mul(SCALE, sub(7, 18)) }
            case 100000000 { result := mul(SCALE, sub(8, 18)) }
            case 1000000000 { result := mul(SCALE, sub(9, 18)) }
            case 10000000000 { result := mul(SCALE, sub(10, 18)) }
            case 100000000000 { result := mul(SCALE, sub(11, 18)) }
            case 1000000000000 { result := mul(SCALE, sub(12, 18)) }
            case 10000000000000 { result := mul(SCALE, sub(13, 18)) }
            case 100000000000000 { result := mul(SCALE, sub(14, 18)) }
            case 1000000000000000 { result := mul(SCALE, sub(15, 18)) }
            case 10000000000000000 { result := mul(SCALE, sub(16, 18)) }
            case 100000000000000000 { result := mul(SCALE, sub(17, 18)) }
            case 1000000000000000000 { result := 0 }
            case 10000000000000000000 { result := SCALE }
            case 100000000000000000000 { result := mul(SCALE, 2) }
            case 1000000000000000000000 { result := mul(SCALE, 3) }
            case 10000000000000000000000 { result := mul(SCALE, 4) }
            case 100000000000000000000000 { result := mul(SCALE, 5) }
            case 1000000000000000000000000 { result := mul(SCALE, 6) }
            case 10000000000000000000000000 { result := mul(SCALE, 7) }
            case 100000000000000000000000000 { result := mul(SCALE, 8) }
            case 1000000000000000000000000000 { result := mul(SCALE, 9) }
            case 10000000000000000000000000000 { result := mul(SCALE, 10) }
            case 100000000000000000000000000000 { result := mul(SCALE, 11) }
            case 1000000000000000000000000000000 { result := mul(SCALE, 12) }
            case 10000000000000000000000000000000 { result := mul(SCALE, 13) }
            case 100000000000000000000000000000000 { result := mul(SCALE, 14) }
            case 1000000000000000000000000000000000 { result := mul(SCALE, 15) }
            case 10000000000000000000000000000000000 { result := mul(SCALE, 16) }
            case 100000000000000000000000000000000000 { result := mul(SCALE, 17) }
            case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) }
            case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) }
            case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) }
            case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) }
            case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) }
            case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) }
            case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) }
            case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) }
            case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) }
            case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) }
            case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) }
            case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) }
            case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) }
            case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) }
            case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) }
            case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) }
            case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) }
            case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) }
            case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) }
            case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) }
            case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) }
            case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) }
            case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) }
            case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) }
            case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) }
            case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) }
            case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) }
            case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) }
            case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) }
            case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) }
            case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) }
            case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) }
            case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) }
            default {
                result := MAX_UD60x18
            }
        }

        if (result == MAX_UD60x18) {
            // Do the fixed-point division inline to save gas. The denominator is log2(10).
            unchecked {
                result = (log2(x) * SCALE) / 3_321928094887362347;
            }
        }
    }

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than or equal to SCALE, otherwise the result would be negative.
    ///
    /// Caveats:
    /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number.
    function log2(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }
        unchecked {
            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(x / SCALE);

            // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255 and SCALE is 1e18.
            result = n * SCALE;

            // This is y = x * 2^(-n).
            uint256 y = x >> n;

            // If y = 1, the fractional part is zero.
            if (y == SCALE) {
                return result;
            }

            // Calculate the fractional part via the iterative approximation.
            // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster.
            for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) {
                y = (y * y) / SCALE;

                // Is y^2 > 2 and so in the range [2,4)?
                if (y >= 2 * SCALE) {
                    // Add the 2^(-m) factor to the logarithm.
                    result += delta;

                    // Corresponds to z/2 on Wikipedia.
                    y >>= 1;
                }
            }
        }
    }

    /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal
    /// fixed-point number.
    /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function.
    /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
    /// @return result The product as an unsigned 60.18-decimal fixed-point number.
    function mul(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDivFixedPoint(x, y);
    }

    /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number.
    function pi() internal pure returns (uint256 result) {
        result = 3_141592653589793238;
    }

    /// @notice Raises x to the power of y.
    ///
    /// @dev Based on the insight that x^y = 2^(log2(x) * y).
    ///
    /// Requirements:
    /// - All from "exp2", "log2" and "mul".
    ///
    /// Caveats:
    /// - All from "exp2", "log2" and "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number.
    /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number.
    /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number.
    function pow(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : uint256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }

    /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - The result must fit within MAX_UD60x18.
    ///
    /// Caveats:
    /// - All from "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as an unsigned 60.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function powu(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // Calculate the first iteration of the loop in advance.
        result = y & 1 > 0 ? x : SCALE;

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        for (y >>= 1; y > 0; y >>= 1) {
            x = PRBMath.mulDivFixedPoint(x, x);

            // Equivalent to "y % 2 == 1" but faster.
            if (y & 1 > 0) {
                result = PRBMath.mulDivFixedPoint(result, x);
            }
        }
    }

    /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number.
    function scale() internal pure returns (uint256 result) {
        result = SCALE;
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Requirements:
    /// - x must be less than MAX_UD60x18 / SCALE.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root.
    /// @return result The result as an unsigned 60.18-decimal fixed-point .
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned
            // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = PRBMath.sqrt(x * SCALE);
        }
    }

    /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process.
    /// @param x The unsigned 60.18-decimal fixed-point number to convert.
    /// @return result The same number in basic integer form.
    function toUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            result = x / SCALE;
        }
    }
}

File 8 of 35 : IERC20Extension.sol
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC20Extension is IERC20 {
    function decimals() external view returns (uint8);
}

File 9 of 35 : IForwardingSwapProxy.sol
import "./IERC20Extension.sol";

/// @title IForwardingSwapProxy
/// @notice This swap proxy contract is for forwarding swaps, meaning the user will provide a data field and a destination contract and this contract will then execute it on the users behalf. Other parameters are provided to this contract to allow for safe validation of the users request.
interface IForwardingSwapProxy {
    /// @notice Struct containing the required fields to forward a swap transaction
    /// @param to The address of where to execute the proxy swap
    /// @param amount The amount to swap, this is 0 if the user is swapping ETH otherwise its the amount of tokens
    /// @param value The value in ETH if the user is swapping from ETH. Amount will be 0 in this case
    /// @param data The data field of the swap transaction
    struct SwapParams {
        address to;
        uint256 amount;
        uint256 value;
        bytes data;
    }

    /// @notice This method will forward a swap for a user, the user provides the swap parameters and this method will execute them on the users behalf.
    /// @param _fromToken The token the user is swapping from
    /// @param _toToken The toke the user wants to swap to
    /// @param _swapParams The required fields to execute the proxy swap
    /// @param _gasRefund The amount in ETH to refund Aurox for proxying the swap
    /// @param _minimumReturnAmount The minimum amount of _toToken's to receive for the swap. This is the final return amount for the user, after the fee has been deducted
    function proxySwapWithFee(
        IERC20Extension _fromToken,
        IERC20Extension _toToken,
        SwapParams calldata _swapParams,
        uint256 _gasRefund,
        uint256 _minimumReturnAmount
    ) external payable;
}

File 10 of 35 : BaseSwapProxy.sol
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

import "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol";

import "prb-math/contracts/PRBMathSD59x18.sol";
import "prb-math/contracts/PRBMathUD60x18.sol";

import "./libraries/UniswapHelpers.sol";

import "./interfaces/IERC20Extension.sol";
import "./interfaces/IBaseSwapProxy.sol";
import "./interfaces/IVault.sol";

/// @title BaseSwapProxy
contract BaseSwapProxy is
    IBaseSwapProxy,
    AccessControlEnumerable,
    Pausable,
    ReentrancyGuard
{
    // Using Fixed point calculations for these types
    using PRBMathSD59x18 for int256;
    using PRBMathUD60x18 for uint256;
    using UniswapV2Helpers for IUniswapV2Router02;

    IERC20Extension public constant WETH =
        IERC20Extension(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    // The ETH address according to 1inch API
    IERC20Extension public constant ethContract =
        IERC20Extension(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);

    // Chainlink feedRegistry
    FeedRegistryInterface public constant feedRegistry =
        FeedRegistryInterface(0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf);

    IUniswapV2Router02 public constant uniswapV2Router =
        IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);

    IVault public vault;

    // Percentage in the form: 100% = 1e18, 1% = 1e16
    uint256 public feePercentage;

    // Need a receive fallback function so that we can swap _fromToken for ETH to recover the _gasRefund and transfer the refund to the vault
    receive() external payable {}

    constructor(address _admin) {
        _setupRole(DEFAULT_ADMIN_ROLE, _admin);
    }

    /// @dev Simple helper for determing if the token is ETH
    function isEth(IERC20Extension _token) public pure returns (bool) {
        return _token == ethContract;
    }

    /// @dev Allows the admin to update the vault contract
    function setVault(IVault _vault) external onlyRole(DEFAULT_ADMIN_ROLE) {
        vault = _vault;

        emit VaultSet(_vault, _msgSender());
    }

    /// @dev Allows the admin to update the paused status of the contract
    function setContractPaused(bool _pauseContract)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        if (_pauseContract) {
            _pause();
        } else {
            _unpause();
        }
    }

    /// @dev Allows the admin to withdraw any ETH or ERC20 tokens that might've accidentally been locked in the contract
    function withdrawERC20(IERC20Extension _token)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        if (_token == ethContract) {
            uint256 balance = address(this).balance;
            require(balance > 0, "Nothing to withdraw");

            payable(_msgSender()).transfer(balance);
        } else {
            uint256 balance = _token.balanceOf(address(this));
            require(balance > 0, "Nothing to withdraw");

            _token.transfer(_msgSender(), balance);
        }
    }

    /// @dev Allows the admin to update the percentage fee applied to trades
    function setFee(uint256 _fee) external onlyRole(DEFAULT_ADMIN_ROLE) {
        feePercentage = _fee;

        emit SetFee(_msgSender(), _fee);
    }

    /// @dev Simplifies the logic of getting decimals for a given token. This function will revert if the given token doesn't have the decimals function, but it seems like a safe assumption that valid tokens will
    function _getDecimals(IERC20Extension _token)
        internal
        view
        returns (uint8 decimals)
    {
        if (_token == ethContract) {
            return 18;
        }

        return _token.decimals();
    }

    function returnTokenBalance(IERC20Extension _token, address _address)
        internal
        view
        returns (uint256)
    {
        if (!isEth(_token)) {
            return _token.balanceOf(_address);
        }

        return _address.balance;
    }

    /// @dev A wrapper around the chainlink rate fetching to prevent reverts in the case of missing exchange rates.
    function tryGetChainlinkRate(IERC20 _fromToken, IERC20 _toToken)
        internal
        view
        returns (uint256)
    {
        // Because of how chainlink rates work, they never provide rates from ETH -> _toToken, they always go _fromToken -> ETH. So the rate needs to be inverted if the request is in the wrong direction
        bool invertRate = _fromToken == ethContract;

        if (invertRate) {
            _fromToken = _toToken;
            _toToken = ethContract;
        }

        try
            feedRegistry.latestRoundData(address(_fromToken), address(_toToken))
        returns (
            // TODO when should this request be expired? Should I invalidate if the timestamp is too old?
            uint80,
            int256 chainlinkPrice,
            uint256,
            uint256,
            uint80
        ) {
            // Un-invert the returned rate
            if (invertRate) {
                return uint256(1 ether).div(uint256(chainlinkPrice));
            }

            return uint256(chainlinkPrice);
        } catch {
            return 0;
        }
    }

    /// @dev This function scales the _amount up or down depending on the difference between the _inputDecimals and _outputDecimals
    function scaleAmountFromDecimals(
        uint256 _amount,
        uint8 _inputDecimals,
        uint8 _outputDecimals
    ) public pure returns (uint256) {
        // Scale the price up if there isn't enough decimals
        if (_inputDecimals < _outputDecimals) {
            return
                _amount *
                uint256(10**uint256(_outputDecimals - _inputDecimals));
            // Similarly scale the price down if there are too many decimals
        } else if (_inputDecimals > _outputDecimals) {
            return
                _amount /
                uint256(10**uint256(_inputDecimals - _outputDecimals));
        }

        // Otherwise if the same decimals return
        return _amount;
    }

    /// @dev Function simply gets the decimals for the provided _token parameter and then scales the _amount accordingly
    function scaleAmountFromTokenDecimals(
        IERC20Extension _token,
        uint256 _amount,
        uint8 _inputDecimals
    ) public view returns (uint256 amount) {
        uint8 decimals = _getDecimals(_token);

        return scaleAmountFromDecimals(_amount, _inputDecimals, decimals);
    }

    function getChainlinkRate(
        IERC20Extension _fromToken,
        IERC20Extension _toToken
    ) public view override returns (uint256 exchangeRate) {
        // Chainlink doesn't handle WETH, which seems a bit silly, so modify it to use the 0xeee "ETH" contract
        if (_fromToken == WETH) {
            _fromToken = ethContract;
        }
        if (_toToken == WETH) {
            _toToken = ethContract;
        }

        // Try to get a direct rate for the provided pair
        uint256 directRate = tryGetChainlinkRate(_fromToken, _toToken);

        if (directRate != 0) {
            // Provide 18 as the current decimals as this is how chainlink returns its price data
            return scaleAmountFromTokenDecimals(_toToken, directRate, 18);
        }

        // If no direct rate exists and either token is ETH, return now
        if (_fromToken == ethContract || _toToken == ethContract) {
            return 0;
        }

        // Otherwise try and get a rate by going: _fromToken -> ETH -> _toToken
        uint256 toETHRate = tryGetChainlinkRate(_fromToken, ethContract);
        uint256 fromETHRate = tryGetChainlinkRate(ethContract, _toToken);

        // If both rates returned, calculate the ratio between the two, then scale it to the correct decimals
        if (toETHRate != 0 && fromETHRate != 0) {
            uint256 derivedRate = toETHRate.mul(fromETHRate);
            return scaleAmountFromTokenDecimals(_toToken, derivedRate, 18);
        }

        return 0;
    }

    function getUniswapV2Rate(
        IERC20Extension _fromToken,
        IERC20Extension _toToken
    ) public view override returns (uint256) {
        // Uniswap doesn't handle the ETH contract (0xeee), so update to WETH address for rate fetching
        if (_fromToken == ethContract) {
            _fromToken = WETH;
        }

        if (_toToken == ethContract) {
            _toToken = WETH;
        }

        // The rate fetching path
        address[] memory path = UniswapV2Helpers._returnUniswapV2Path(
            _fromToken,
            _toToken
        );

        // The return path function will return an array of 0x0 addresses if it can't find a valid path
        if (path.length == 0) return 0;

        // To calculate the amount we need to provide an amountIn. This needs to be normalised based on the amount of decimals in the given _fromToken.
        uint8 inputDecimals = _getDecimals(_fromToken);

        // Apply the decimals to the amount
        uint256 amountIn = 1 * 10**inputDecimals;

        // Safely call the method
        try uniswapV2Router.getAmountsOut(amountIn, path) returns (
            uint256[] memory rate
        ) {
            return rate[path.length - 1];
        } catch {
            return 0;
        }
    }

    function getExchangeRate(
        IERC20Extension _fromToken,
        IERC20Extension _toToken
    ) public view override returns (uint256) {
        // If both tokens are either ETH or WETH, then return 1 ether as they are equivalent in value
        if (
            (isEth(_fromToken) || _fromToken == WETH) &&
            (isEth(_toToken) || _toToken == WETH)
        ) {
            return 1 ether;
        }

        // Try and get a rate from chainlink first
        uint256 chainlinkRate = getChainlinkRate(_fromToken, _toToken);
        if (chainlinkRate != 0) return chainlinkRate;

        // Fallback to uniswap V2 if needed
        uint256 uniswapV2Rate = getUniswapV2Rate(_fromToken, _toToken);
        if (uniswapV2Rate != 0) return uniswapV2Rate;

        revert("No Rate Found");
    }

    function calculatePercentageFeeInETH(
        IERC20Extension _token,
        uint256 _amount,
        uint256 _gasRefund
    )
        public
        view
        override
        returns (uint256 feeTotalInETH, uint256 feeTotalInToken)
    {
        uint256 exchangeRateToETH = getExchangeRate(_token, WETH);

        uint8 tokenDecimals = _getDecimals(_token);

        // To calculate the correct value here we must scale the value, either up or down depending on the decimals in _fromToken
        uint256 amountInETH = scaleAmountFromDecimals(
            _amount.mul(exchangeRateToETH),
            tokenDecimals,
            18
        );

        require(
            amountInETH > _gasRefund,
            "Not swapping enough to recover the gas refund"
        );

        // Deducting _gasRefund from the amountInETH, because the _gasRefund is already being added on-top of the percentageFeeInETH and we don't want to double-charge
        uint256 percentageFeeInETH = (amountInETH - _gasRefund).mul(
            feePercentage
        );

        feeTotalInETH = percentageFeeInETH + _gasRefund;

        uint256 scaledFeeTotalFromToken = scaleAmountFromDecimals(
            feeTotalInETH,
            18,
            tokenDecimals
        );
        uint256 scaledExchangeRate = uint256(1 ether).div(exchangeRateToETH);

        feeTotalInToken = scaledFeeTotalFromToken.mul(scaledExchangeRate);
    }

    /// @notice This method simplifies handling approvals, it also contains logic to detect if the approval balance is greater than the supplied amount (in-case of tokens that decrement the approval balance when the balance is MAX uint256)
    /// @param _token The token to do unlimited approvals for
    /// @param _token The token to handle approvals for
    /// @param _amount The amount to validate the approval balance for
    function _handleApprovalFromThis(
        IERC20Extension _token,
        address _spender,
        uint256 _amount
    ) internal {
        if (isEth(_token)) return;
        else if (_token.allowance(address(this), _spender) < _amount) {
            _token.approve(_spender, type(uint256).max);
        }
    }
}

File 11 of 35 : Whitelist.sol
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./interfaces/IWhitelist.sol";

contract Whitelist is IWhitelist, AccessControlEnumerable {
    mapping(address => bool) whitelist;

    constructor(address _admin) {
        _setupRole(DEFAULT_ADMIN_ROLE, _admin);
    }

    function isWhitelisted(address _address)
        public
        view
        override
        returns (bool)
    {
        return whitelist[_address];
    }

    function addToWhitelist(address _address)
        public
        override
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(
            _address != address(0),
            "Can't add the 0x address to the whitelist"
        );
        whitelist[_address] = true;

        emit AddedToWhitelist(_address);
    }

    function removeFromWhitelist(address _address)
        public
        override
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(
            isWhitelisted(_address),
            "Address is missing from the whitelist"
        );
        delete whitelist[_address];

        emit RemovedFromWhitelist(_address);
    }
}

File 12 of 35 : IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable is IAccessControl {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 13 of 35 : AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

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

/**
 * @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 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]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _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 virtual 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]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        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 virtual 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 revoked `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}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    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 {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 14 of 35 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastvalue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastvalue;
                // Update the index for the moved value
                set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        assembly {
            result := store
        }

        return result;
    }
}

File 15 of 35 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @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 {AccessControl-_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 Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @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) external;

    /**
     * @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) external;

    /**
     * @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) external;
}

File 16 of 35 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

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) {
        return msg.data;
    }
}

File 17 of 35 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "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] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

File 18 of 35 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

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 19 of 35 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

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

File 20 of 35 : IUniswapV2Router01.sol
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

File 21 of 35 : PRBMath.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivFixedPointOverflow(uint256 prod1);

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator);

/// @notice Emitted when one of the inputs is type(int256).min.
error PRBMath__MulDivSignedInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows int256.
error PRBMath__MulDivSignedOverflow(uint256 rAbs);

/// @notice Emitted when the input is MIN_SD59x18.
error PRBMathSD59x18__AbsInputTooSmall();

/// @notice Emitted when ceiling a number overflows SD59x18.
error PRBMathSD59x18__CeilOverflow(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__DivInputTooSmall();

/// @notice Emitted when one of the intermediary unsigned results overflows SD59x18.
error PRBMathSD59x18__DivOverflow(uint256 rAbs);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathSD59x18__ExpInputTooBig(int256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathSD59x18__Exp2InputTooBig(int256 x);

/// @notice Emitted when flooring a number underflows SD59x18.
error PRBMathSD59x18__FloorUnderflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMathSD59x18__FromIntOverflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMathSD59x18__FromIntUnderflow(int256 x);

/// @notice Emitted when the product of the inputs is negative.
error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y);

/// @notice Emitted when multiplying the inputs overflows SD59x18.
error PRBMathSD59x18__GmOverflow(int256 x, int256 y);

/// @notice Emitted when the input is less than or equal to zero.
error PRBMathSD59x18__LogInputTooSmall(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__MulInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__MulOverflow(uint256 rAbs);

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__PowuOverflow(uint256 rAbs);

/// @notice Emitted when the input is negative.
error PRBMathSD59x18__SqrtNegativeInput(int256 x);

/// @notice Emitted when the calculating the square root overflows SD59x18.
error PRBMathSD59x18__SqrtOverflow(int256 x);

/// @notice Emitted when addition overflows UD60x18.
error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y);

/// @notice Emitted when ceiling a number overflows UD60x18.
error PRBMathUD60x18__CeilOverflow(uint256 x);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathUD60x18__ExpInputTooBig(uint256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathUD60x18__Exp2InputTooBig(uint256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18.
error PRBMathUD60x18__FromUintOverflow(uint256 x);

/// @notice Emitted when multiplying the inputs overflows UD60x18.
error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y);

/// @notice Emitted when the input is less than 1.
error PRBMathUD60x18__LogInputTooSmall(uint256 x);

/// @notice Emitted when the calculating the square root overflows UD60x18.
error PRBMathUD60x18__SqrtOverflow(uint256 x);

/// @notice Emitted when subtraction underflows UD60x18.
error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y);

/// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library
/// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point
/// representation. When it does not, it is explicitly mentioned in the NatSpec documentation.
library PRBMath {
    /// STRUCTS ///

    struct SD59x18 {
        int256 value;
    }

    struct UD60x18 {
        uint256 value;
    }

    /// STORAGE ///

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @dev Largest power of two divisor of SCALE.
    uint256 internal constant SCALE_LPOTD = 262144;

    /// @dev SCALE inverted mod 2^256.
    uint256 internal constant SCALE_INVERSE =
        78156646155174841979727994598816262306175212592076161876661_508869554232690281;

    /// FUNCTIONS ///

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    /// @dev Has to use 192.64-bit fixed-point numbers.
    /// See https://ethereum.stackexchange.com/a/96594/24693.
    /// @param x The exponent as an unsigned 192.64-bit fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // Start from 0.5 in the 192.64-bit fixed-point format.
            result = 0x800000000000000000000000000000000000000000000000;

            // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows
            // because the initial result is 2^191 and all magic factors are less than 2^65.
            if (x & 0x8000000000000000 > 0) {
                result = (result * 0x16A09E667F3BCC909) >> 64;
            }
            if (x & 0x4000000000000000 > 0) {
                result = (result * 0x1306FE0A31B7152DF) >> 64;
            }
            if (x & 0x2000000000000000 > 0) {
                result = (result * 0x1172B83C7D517ADCE) >> 64;
            }
            if (x & 0x1000000000000000 > 0) {
                result = (result * 0x10B5586CF9890F62A) >> 64;
            }
            if (x & 0x800000000000000 > 0) {
                result = (result * 0x1059B0D31585743AE) >> 64;
            }
            if (x & 0x400000000000000 > 0) {
                result = (result * 0x102C9A3E778060EE7) >> 64;
            }
            if (x & 0x200000000000000 > 0) {
                result = (result * 0x10163DA9FB33356D8) >> 64;
            }
            if (x & 0x100000000000000 > 0) {
                result = (result * 0x100B1AFA5ABCBED61) >> 64;
            }
            if (x & 0x80000000000000 > 0) {
                result = (result * 0x10058C86DA1C09EA2) >> 64;
            }
            if (x & 0x40000000000000 > 0) {
                result = (result * 0x1002C605E2E8CEC50) >> 64;
            }
            if (x & 0x20000000000000 > 0) {
                result = (result * 0x100162F3904051FA1) >> 64;
            }
            if (x & 0x10000000000000 > 0) {
                result = (result * 0x1000B175EFFDC76BA) >> 64;
            }
            if (x & 0x8000000000000 > 0) {
                result = (result * 0x100058BA01FB9F96D) >> 64;
            }
            if (x & 0x4000000000000 > 0) {
                result = (result * 0x10002C5CC37DA9492) >> 64;
            }
            if (x & 0x2000000000000 > 0) {
                result = (result * 0x1000162E525EE0547) >> 64;
            }
            if (x & 0x1000000000000 > 0) {
                result = (result * 0x10000B17255775C04) >> 64;
            }
            if (x & 0x800000000000 > 0) {
                result = (result * 0x1000058B91B5BC9AE) >> 64;
            }
            if (x & 0x400000000000 > 0) {
                result = (result * 0x100002C5C89D5EC6D) >> 64;
            }
            if (x & 0x200000000000 > 0) {
                result = (result * 0x10000162E43F4F831) >> 64;
            }
            if (x & 0x100000000000 > 0) {
                result = (result * 0x100000B1721BCFC9A) >> 64;
            }
            if (x & 0x80000000000 > 0) {
                result = (result * 0x10000058B90CF1E6E) >> 64;
            }
            if (x & 0x40000000000 > 0) {
                result = (result * 0x1000002C5C863B73F) >> 64;
            }
            if (x & 0x20000000000 > 0) {
                result = (result * 0x100000162E430E5A2) >> 64;
            }
            if (x & 0x10000000000 > 0) {
                result = (result * 0x1000000B172183551) >> 64;
            }
            if (x & 0x8000000000 > 0) {
                result = (result * 0x100000058B90C0B49) >> 64;
            }
            if (x & 0x4000000000 > 0) {
                result = (result * 0x10000002C5C8601CC) >> 64;
            }
            if (x & 0x2000000000 > 0) {
                result = (result * 0x1000000162E42FFF0) >> 64;
            }
            if (x & 0x1000000000 > 0) {
                result = (result * 0x10000000B17217FBB) >> 64;
            }
            if (x & 0x800000000 > 0) {
                result = (result * 0x1000000058B90BFCE) >> 64;
            }
            if (x & 0x400000000 > 0) {
                result = (result * 0x100000002C5C85FE3) >> 64;
            }
            if (x & 0x200000000 > 0) {
                result = (result * 0x10000000162E42FF1) >> 64;
            }
            if (x & 0x100000000 > 0) {
                result = (result * 0x100000000B17217F8) >> 64;
            }
            if (x & 0x80000000 > 0) {
                result = (result * 0x10000000058B90BFC) >> 64;
            }
            if (x & 0x40000000 > 0) {
                result = (result * 0x1000000002C5C85FE) >> 64;
            }
            if (x & 0x20000000 > 0) {
                result = (result * 0x100000000162E42FF) >> 64;
            }
            if (x & 0x10000000 > 0) {
                result = (result * 0x1000000000B17217F) >> 64;
            }
            if (x & 0x8000000 > 0) {
                result = (result * 0x100000000058B90C0) >> 64;
            }
            if (x & 0x4000000 > 0) {
                result = (result * 0x10000000002C5C860) >> 64;
            }
            if (x & 0x2000000 > 0) {
                result = (result * 0x1000000000162E430) >> 64;
            }
            if (x & 0x1000000 > 0) {
                result = (result * 0x10000000000B17218) >> 64;
            }
            if (x & 0x800000 > 0) {
                result = (result * 0x1000000000058B90C) >> 64;
            }
            if (x & 0x400000 > 0) {
                result = (result * 0x100000000002C5C86) >> 64;
            }
            if (x & 0x200000 > 0) {
                result = (result * 0x10000000000162E43) >> 64;
            }
            if (x & 0x100000 > 0) {
                result = (result * 0x100000000000B1721) >> 64;
            }
            if (x & 0x80000 > 0) {
                result = (result * 0x10000000000058B91) >> 64;
            }
            if (x & 0x40000 > 0) {
                result = (result * 0x1000000000002C5C8) >> 64;
            }
            if (x & 0x20000 > 0) {
                result = (result * 0x100000000000162E4) >> 64;
            }
            if (x & 0x10000 > 0) {
                result = (result * 0x1000000000000B172) >> 64;
            }
            if (x & 0x8000 > 0) {
                result = (result * 0x100000000000058B9) >> 64;
            }
            if (x & 0x4000 > 0) {
                result = (result * 0x10000000000002C5D) >> 64;
            }
            if (x & 0x2000 > 0) {
                result = (result * 0x1000000000000162E) >> 64;
            }
            if (x & 0x1000 > 0) {
                result = (result * 0x10000000000000B17) >> 64;
            }
            if (x & 0x800 > 0) {
                result = (result * 0x1000000000000058C) >> 64;
            }
            if (x & 0x400 > 0) {
                result = (result * 0x100000000000002C6) >> 64;
            }
            if (x & 0x200 > 0) {
                result = (result * 0x10000000000000163) >> 64;
            }
            if (x & 0x100 > 0) {
                result = (result * 0x100000000000000B1) >> 64;
            }
            if (x & 0x80 > 0) {
                result = (result * 0x10000000000000059) >> 64;
            }
            if (x & 0x40 > 0) {
                result = (result * 0x1000000000000002C) >> 64;
            }
            if (x & 0x20 > 0) {
                result = (result * 0x10000000000000016) >> 64;
            }
            if (x & 0x10 > 0) {
                result = (result * 0x1000000000000000B) >> 64;
            }
            if (x & 0x8 > 0) {
                result = (result * 0x10000000000000006) >> 64;
            }
            if (x & 0x4 > 0) {
                result = (result * 0x10000000000000003) >> 64;
            }
            if (x & 0x2 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }
            if (x & 0x1 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }

            // We're doing two things at the same time:
            //
            //   1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for
            //      the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191
            //      rather than 192.
            //   2. Convert the result to the unsigned 60.18-decimal fixed-point format.
            //
            // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n".
            result *= SCALE;
            result >>= (191 - (x >> 64));
        }
    }

    /// @notice Finds the zero-based index of the first one in the binary representation of x.
    /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set
    /// @param x The uint256 number for which to find the index of the most significant bit.
    /// @return msb The index of the most significant bit as an uint256.
    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {
        if (x >= 2**128) {
            x >>= 128;
            msb += 128;
        }
        if (x >= 2**64) {
            x >>= 64;
            msb += 64;
        }
        if (x >= 2**32) {
            x >>= 32;
            msb += 32;
        }
        if (x >= 2**16) {
            x >>= 16;
            msb += 16;
        }
        if (x >= 2**8) {
            x >>= 8;
            msb += 8;
        }
        if (x >= 2**4) {
            x >>= 4;
            msb += 4;
        }
        if (x >= 2**2) {
            x >>= 2;
            msb += 2;
        }
        if (x >= 2**1) {
            // No need to shift x any more.
            msb += 1;
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The multiplicand as an uint256.
    /// @param y The multiplier as an uint256.
    /// @param denominator The divisor as an uint256.
    /// @return result The result as an uint256.
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
        // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
        // variables such that product = prod1 * 2^256 + prod0.
        uint256 prod0; // Least significant 256 bits of the product
        uint256 prod1; // Most significant 256 bits of the product
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        // Handle non-overflow cases, 256 by 256 division.
        if (prod1 == 0) {
            unchecked {
                result = prod0 / denominator;
            }
            return result;
        }

        // Make sure the result is less than 2^256. Also prevents denominator == 0.
        if (prod1 >= denominator) {
            revert PRBMath__MulDivOverflow(prod1, denominator);
        }

        ///////////////////////////////////////////////
        // 512 by 256 division.
        ///////////////////////////////////////////////

        // Make division exact by subtracting the remainder from [prod1 prod0].
        uint256 remainder;
        assembly {
            // Compute remainder using mulmod.
            remainder := mulmod(x, y, denominator)

            // Subtract 256 bit number from 512 bit number.
            prod1 := sub(prod1, gt(remainder, prod0))
            prod0 := sub(prod0, remainder)
        }

        // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
        // See https://cs.stackexchange.com/q/138556/92363.
        unchecked {
            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 lpotdod = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by lpotdod.
                denominator := div(denominator, lpotdod)

                // Divide [prod1 prod0] by lpotdod.
                prod0 := div(prod0, lpotdod)

                // Flip lpotdod such that it is 2^256 / lpotdod. If lpotdod is zero, then it becomes one.
                lpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * lpotdod;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /// @notice Calculates floor(x*y÷1e18) with full precision.
    ///
    /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the
    /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of
    /// being rounded to 1e-18.  See "Listing 6" and text above it at https://accu.org/index.php/journals/1717.
    ///
    /// Requirements:
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations:
    ///     1. x * y = type(uint256).max * SCALE
    ///     2. (x * y) % SCALE >= SCALE / 2
    ///
    /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function mulDivFixedPoint(uint256 x, uint256 y) internal pure returns (uint256 result) {
        uint256 prod0;
        uint256 prod1;
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        if (prod1 >= SCALE) {
            revert PRBMath__MulDivFixedPointOverflow(prod1);
        }

        uint256 remainder;
        uint256 roundUpUnit;
        assembly {
            remainder := mulmod(x, y, SCALE)
            roundUpUnit := gt(remainder, 499999999999999999)
        }

        if (prod1 == 0) {
            unchecked {
                result = (prod0 / SCALE) + roundUpUnit;
                return result;
            }
        }

        assembly {
            result := add(
                mul(
                    or(
                        div(sub(prod0, remainder), SCALE_LPOTD),
                        mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1))
                    ),
                    SCALE_INVERSE
                ),
                roundUpUnit
            )
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - None of the inputs can be type(int256).min.
    /// - The result must fit within int256.
    ///
    /// @param x The multiplicand as an int256.
    /// @param y The multiplier as an int256.
    /// @param denominator The divisor as an int256.
    /// @return result The result as an int256.
    function mulDivSigned(
        int256 x,
        int256 y,
        int256 denominator
    ) internal pure returns (int256 result) {
        if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
            revert PRBMath__MulDivSignedInputTooSmall();
        }

        // Get hold of the absolute values of x, y and the denominator.
        uint256 ax;
        uint256 ay;
        uint256 ad;
        unchecked {
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);
            ad = denominator < 0 ? uint256(-denominator) : uint256(denominator);
        }

        // Compute the absolute value of (x*y)÷denominator. The result must fit within int256.
        uint256 rAbs = mulDiv(ax, ay, ad);
        if (rAbs > uint256(type(int256).max)) {
            revert PRBMath__MulDivSignedOverflow(rAbs);
        }

        // Get the signs of x, y and the denominator.
        uint256 sx;
        uint256 sy;
        uint256 sd;
        assembly {
            sx := sgt(x, sub(0, 1))
            sy := sgt(y, sub(0, 1))
            sd := sgt(denominator, sub(0, 1))
        }

        // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs.
        // If yes, the result should be negative.
        result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The uint256 number for which to calculate the square root.
    /// @return result The result as an uint256.
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        // Set the initial guess to the least power of two that is greater than or equal to sqrt(x).
        uint256 xAux = uint256(x);
        result = 1;
        if (xAux >= 0x100000000000000000000000000000000) {
            xAux >>= 128;
            result <<= 64;
        }
        if (xAux >= 0x10000000000000000) {
            xAux >>= 64;
            result <<= 32;
        }
        if (xAux >= 0x100000000) {
            xAux >>= 32;
            result <<= 16;
        }
        if (xAux >= 0x10000) {
            xAux >>= 16;
            result <<= 8;
        }
        if (xAux >= 0x100) {
            xAux >>= 8;
            result <<= 4;
        }
        if (xAux >= 0x10) {
            xAux >>= 4;
            result <<= 2;
        }
        if (xAux >= 0x8) {
            result <<= 1;
        }

        // The operations can never overflow because the result is max 2^127 when it enters this block.
        unchecked {
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1; // Seven iterations should be enough
            uint256 roundedDownResult = x / result;
            return result >= roundedDownResult ? roundedDownResult : result;
        }
    }
}

File 22 of 35 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        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 23 of 35 : FeedRegistryInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;

import "./AggregatorV2V3Interface.sol";

interface FeedRegistryInterface {
  struct Phase {
    uint16 phaseId;
    uint80 startingAggregatorRoundId;
    uint80 endingAggregatorRoundId;
  }

  event FeedProposed(
    address indexed asset,
    address indexed denomination,
    address indexed proposedAggregator,
    address currentAggregator,
    address sender
  );
  event FeedConfirmed(
    address indexed asset,
    address indexed denomination,
    address indexed latestAggregator,
    address previousAggregator,
    uint16 nextPhaseId,
    address sender
  );

  // V3 AggregatorV3Interface

  function decimals(address base, address quote) external view returns (uint8);

  function description(address base, address quote) external view returns (string memory);

  function version(address base, address quote) external view returns (uint256);

  function latestRoundData(address base, address quote)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function getRoundData(
    address base,
    address quote,
    uint80 _roundId
  )
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  // V2 AggregatorInterface

  function latestAnswer(address base, address quote) external view returns (int256 answer);

  function latestTimestamp(address base, address quote) external view returns (uint256 timestamp);

  function latestRound(address base, address quote) external view returns (uint256 roundId);

  function getAnswer(
    address base,
    address quote,
    uint256 roundId
  ) external view returns (int256 answer);

  function getTimestamp(
    address base,
    address quote,
    uint256 roundId
  ) external view returns (uint256 timestamp);

  // Registry getters

  function getFeed(address base, address quote) external view returns (AggregatorV2V3Interface aggregator);

  function getPhaseFeed(
    address base,
    address quote,
    uint16 phaseId
  ) external view returns (AggregatorV2V3Interface aggregator);

  function isFeedEnabled(address aggregator) external view returns (bool);

  function getPhase(
    address base,
    address quote,
    uint16 phaseId
  ) external view returns (Phase memory phase);

  // Round helpers

  function getRoundFeed(
    address base,
    address quote,
    uint80 roundId
  ) external view returns (AggregatorV2V3Interface aggregator);

  function getPhaseRange(
    address base,
    address quote,
    uint16 phaseId
  ) external view returns (uint80 startingRoundId, uint80 endingRoundId);

  function getPreviousRoundId(
    address base,
    address quote,
    uint80 roundId
  ) external view returns (uint80 previousRoundId);

  function getNextRoundId(
    address base,
    address quote,
    uint80 roundId
  ) external view returns (uint80 nextRoundId);

  // Feed management

  function proposeFeed(
    address base,
    address quote,
    address aggregator
  ) external;

  function confirmFeed(
    address base,
    address quote,
    address aggregator
  ) external;

  // Proposed aggregator

  function getProposedFeed(address base, address quote)
    external
    view
    returns (AggregatorV2V3Interface proposedAggregator);

  function proposedGetRoundData(
    address base,
    address quote,
    uint80 roundId
  )
    external
    view
    returns (
      uint80 id,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function proposedLatestRoundData(address base, address quote)
    external
    view
    returns (
      uint80 id,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  // Phases
  function getCurrentPhaseId(address base, address quote) external view returns (uint16 currentPhaseId);
}

File 24 of 35 : UniswapHelpers.sol
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./UniswapV2Helpers.sol";

library UniswapHelpers {
    using UniswapV2Helpers for IUniswapV2Router02;

    IUniswapV2Router02 constant uniswapV2Router =
        IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);

    IERC20 constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    IERC20 constant ETH = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);

    /// @dev In handler meaning, we are providing an exact amount of input to receive a variable amount of output. This function also handles the routing to the appropriate uniswap V2 function
    function _exactInUniswapHandler(
        IERC20 _fromToken,
        IERC20 _toToken,
        uint256 _amountIn,
        uint256 _amountOutMinimum
    ) internal returns (uint256, uint256) {
        if (_fromToken == ETH) {
            revert("Swapping from ETH not supported");
            // ! Deprecated currently
            // (
            //     uint256 swappedAmountIn,
            //     uint256 swappedAmountOut
            // ) = uniswapV2Router._swapExactETHForTokens(
            //         _fromToken,
            //         _amountIn,
            //         _amountOutMinimum,
            //         address(this)
            //     );

            // return (swappedAmountIn, swappedAmountOut);
        } else if (_toToken == ETH) {
            (
                uint256 swappedAmountIn,
                uint256 swappedAmountOut
            ) = uniswapV2Router._swapExactTokensForETH(
                    _fromToken,
                    _amountIn,
                    _amountOutMinimum,
                    address(this)
                );

            return (swappedAmountIn, swappedAmountOut);
        } else {
            (
                uint256 swappedAmountIn,
                uint256 swappedAmountOut
            ) = uniswapV2Router._swapExactTokensForTokens(
                    _fromToken,
                    _toToken,
                    _amountIn,
                    _amountOutMinimum,
                    address(this)
                );
            return (swappedAmountIn, swappedAmountOut);
        }
    }
}

File 25 of 35 : IBaseSwapProxy.sol
import "./IVault.sol";
import "./IERC20Extension.sol";

interface IBaseSwapProxy {
    /// @dev Event used when an admin updates the feePercentage
    event SetFee(address indexed from, uint256 fee);
    /// @dev Event used when an admin updates the vault contract
    event VaultSet(IVault vault, address indexed setter);

    /// @notice This function calculates the exchange rate between the _fromToken and _toToken
    /// @dev This function tries to lookup the rate through chainlink first and if the request fails it then looks for a rate through Uniswap V2. If no rate can be found the function reverts.
    /// @param _fromToken The token the user is swapping with
    /// @param _toToken The token the user wwants
    /// @return The exchange rate
    function getExchangeRate(
        IERC20Extension _fromToken,
        IERC20Extension _toToken
    ) external view returns (uint256);

    /// @notice This function tries to calculate the exchange rate between the two tokens using chainlink
    /// @dev This function returns 0 if no rate can be found
    /// @param _fromToken The token the user is swapping with
    /// @param _toToken The token the user wwants
    /// @return exchangeRate The exchange rate or 0 if no rate is found
    function getChainlinkRate(
        IERC20Extension _fromToken,
        IERC20Extension _toToken
    ) external view returns (uint256 exchangeRate);

    /// @notice This function tries to find a rate using Uniswap V2. It gets the spot ratio between _fromToken and _toToken. This is typically a pretty unsafe operation and susceptible to MEV and sandwich attacks. This is somewhat mitigated because all swap transactions will be submitted through flashbots, which is private RPC.
    /// @param _fromToken The token the user is swapping with
    /// @param _toToken The token the user wwants
    /// @return exchangeRate The exchange rate or 0 if no rate is found
    function getUniswapV2Rate(
        IERC20Extension _fromToken,
        IERC20Extension _toToken
    ) external view returns (uint256);

    /// @notice This function calculates the percentage fee amount in ETH for the _fromToken the user is swapping from. It is deducts the _gasRefund value to ensure the user is charged correctly
    /// @param _fromToken The token the user is swapping from
    /// @param _amount The amount they are swapping with
    /// @param _gasRefund The gas refund required to cover the proxied swap
    /// @return feeTotalInETH The fee total priced in ETH
    /// @return feeTotalInFromToken The fee total priced in _fromToken
    function calculatePercentageFeeInETH(
        IERC20Extension _fromToken,
        uint256 _amount,
        uint256 _gasRefund
    )
        external
        view
        returns (uint256 feeTotalInETH, uint256 feeTotalInFromToken);
}

File 26 of 35 : IVault.sol
interface IVault {
    /// @dev Event used when the contract receives ETH
    event Received(address indexed from, uint256 value);
    /// @dev Event used when the contract is paid ETH, this will occur when fees have been deducted and transferred to the Vault contract for holding
    event PaidFees(address indexed from, uint256 value);
    /// @dev Event used whenever an admin claims fees from the contract
    event FeesClaimed(address indexed from, uint256 value);

    /// @dev To allow the contract to receive ETH
    receive() external payable;

    /// @notice Allows an admin to claim the ETH balance of the contract
    function claimFees() external;

    /// @notice This function is called whenever fees have been deducted from a user and transffered into the Vault for holding
    /// @param _sender The user who has been deducted a fee
    /// @param _amount The fee amount
    function paidFees(address _sender, uint256 _amount) external payable;

    /// @notice Allows an admin to set the balance limit for wallets that have the HOT_WALLET role
    /// @param _walletBalanceLimit The updated balance limit
    function setWalletBalanceLimit(uint256 _walletBalanceLimit) external;

    /// @notice Allows an admin to top up registered HOT_WALLETS, these wallets will be used for sponosoring transactions and this method allows updating all of them with a single contract call
    function topUpHotWallets() external payable;

    /// @notice This allows us to easily see the total amount of ETH required to top-up all hot wallets. Used before calling the topUpHotWallets function
    /// @return totalETH The total amount of ETH required
    function ethRequiredForHotWalletTopup()
        external
        view
        returns (uint256 totalETH);
}

File 27 of 35 : AggregatorV2V3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./AggregatorInterface.sol";
import "./AggregatorV3Interface.sol";

interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}

File 28 of 35 : AggregatorInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorInterface {
  function latestAnswer() external view returns (int256);

  function latestTimestamp() external view returns (uint256);

  function latestRound() external view returns (uint256);

  function getAnswer(uint256 roundId) external view returns (int256);

  function getTimestamp(uint256 roundId) external view returns (uint256);

  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt);

  event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
}

File 29 of 35 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

File 30 of 35 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 31 of 35 : IUniswapV2Pair.sol
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

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

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

File 32 of 35 : IUniswapV2Factory.sol
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

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

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

File 33 of 35 : UniswapV2Helpers.sol
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "../interfaces/IERC20Extension.sol";

library UniswapV2Helpers {
    IERC20Extension constant WETH =
        IERC20Extension(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

    IUniswapV2Factory constant uniswapV2Factory =
        IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);

    /// @dev Simple wrapper for the swapTokensForExactETH uniswap V2 function
    function _swapTokensForExactETH(
        IUniswapV2Router02 _uniswapV2Router,
        IERC20 _token,
        uint256 _amountOut,
        uint256 _amountInMaximum,
        address _to
    ) internal returns (uint256 amountIn, uint256 amountOut) {
        address[] memory path = new address[](2);
        path[0] = address(_token);
        path[1] = address(WETH);

        uint256[] memory amounts = _uniswapV2Router.swapTokensForExactETH(
            _amountOut,
            _amountInMaximum,
            path,
            _to,
            block.timestamp
        );

        return (amounts[0], amounts[1]);
    }

    /// @notice This function calculates a path for swapping _fromToken for _toToken
    function _returnUniswapV2Path(IERC20 _fromToken, IERC20 _toToken)
        internal
        view
        returns (address[] memory path)
    {
        // Try to find a direct pair address for the given tokens
        try
            uniswapV2Factory.getPair(address(_fromToken), address(_toToken))
        returns (address _pairAddress) {
            // If a direct pair exists, return the direct path
            if (_pairAddress != address(0)) {
                // Been finding some direct pairs have old pools no one uses, so get the timestamp when the pool was used last
                (, , uint256 blocktimestampLast) = IUniswapV2Pair(_pairAddress)
                    .getReserves();

                // If the pool has been used within the last day, then route through the pool. If its been inactive longer than a day then its highly likely its a low liquidity pool and we don't want to route through it.

                // This is a cheap solution, it could pull the reserves from the pool and calculate the amount of stored liquidity in the pool in ETH and invalidate if less than a liquidity threshold. But that would cost a lot more gas and this seems ok for the current MVP
                if (block.timestamp - blocktimestampLast < 86400) {
                    path = new address[](2);

                    path[0] = address(_fromToken);
                    path[1] = address(_toToken);

                    return path;
                }
            }
        } catch {}

        // Return an empty path here, the route can't be handled if either of the tokens are WETH
        if (_fromToken == WETH || _toToken == WETH) {
            return path;
        }

        // Otherwise create a path through WETH
        path = new address[](3);

        path[0] = address(_fromToken);
        path[1] = address(WETH);
        path[2] = address(_toToken);
    }

    /// @dev Simple wrapper for the swapExactTokensForTokens uniswap V2 function
    function _swapExactTokensForTokens(
        IUniswapV2Router02 _uniswapV2Router,
        IERC20 _fromToken,
        IERC20 _toToken,
        uint256 _amountIn,
        uint256 _amountOutMin,
        address _to
    ) internal returns (uint256 amountIn, uint256 amountOut) {
        address[] memory path = _returnUniswapV2Path(_fromToken, _toToken);

        uint256[] memory amounts = _uniswapV2Router.swapExactTokensForTokens(
            _amountIn,
            _amountOutMin,
            path,
            _to,
            block.timestamp
        );

        // Return the first item and the last item, so that it adheres to the path length
        return (amounts[0], amounts[path.length - 1]);
    }

    /// @dev Simple wrapper for the swapExactETHForTokens uniswap V2 function
    function _swapExactETHForTokens(
        IUniswapV2Router02 _uniswapV2Router,
        IERC20 _token,
        uint256 _amountIn,
        uint256 _amountOutMin,
        address _to
    ) internal returns (uint256 amountIn, uint256 amountOut) {
        address[] memory path = new address[](2);
        path[0] = address(WETH);
        path[1] = address(_token);

        uint256[] memory amounts = _uniswapV2Router.swapExactETHForTokens{
            value: _amountIn
        }(_amountOutMin, path, _to, block.timestamp);

        return (amounts[0], amounts[1]);
    }

    /// @dev Simple wrapper for the swapExactTokensForETH uniswap V2 function
    function _swapExactTokensForETH(
        IUniswapV2Router02 _uniswapV2Router,
        IERC20 _token,
        uint256 _amountIn,
        uint256 _amountOutMin,
        address _to
    ) internal returns (uint256 amountIn, uint256 amountOut) {
        address[] memory path = new address[](2);
        path[0] = address(_token);
        path[1] = address(WETH);

        uint256[] memory amounts = _uniswapV2Router.swapExactTokensForETH(
            _amountIn,
            _amountOutMin,
            path,
            _to,
            block.timestamp
        );

        return (amounts[0], amounts[1]);
    }
}

File 34 of 35 : IUniswapV3SwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

File 35 of 35 : IWhitelist.sol
interface IWhitelist {
    /// @dev Event emitted whenever a new contractAddress is added to the whitelist
    event AddedToWhitelist(address indexed contractAddress);

    /// @dev Event emitted whenever a contractAddress is removed from the whitelist
    event RemovedFromWhitelist(address indexed contractAddress);

    /// @notice This function returns whether a given _address param is within the whitelist
    /// @param _address The address to return the whitelist status for
    /// @return A boolean indiciating if the address is whitelisted
    function isWhitelisted(address _address) external returns (bool);

    /// @notice This function is called by an owner to add a new contractAddress to the whitelist
    /// @param _address The new address to add the whitelist
    function addToWhitelist(address _address) external;

    /// @notice This function is called by an owner to remove a contractAddress from the whitelist
    /// @param _address The address to remove from the whitelist
    function removeFromWhitelist(address _address) external;
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"}],"name":"PRBMath__MulDivFixedPointOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"PRBMath__MulDivOverflow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"}],"name":"AddedToWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"}],"name":"RemovedFromWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"SetFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IVault","name":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"setter","type":"address"}],"name":"VaultSet","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"contract IERC20Extension","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"addToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_gasRefund","type":"uint256"}],"name":"calculatePercentageFeeInETH","outputs":[{"internalType":"uint256","name":"feeTotalInETH","type":"uint256"},{"internalType":"uint256","name":"feeTotalInToken","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ethContract","outputs":[{"internalType":"contract IERC20Extension","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feedRegistry","outputs":[{"internalType":"contract FeedRegistryInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_fromToken","type":"address"},{"internalType":"contract IERC20Extension","name":"_toToken","type":"address"}],"name":"getChainlinkRate","outputs":[{"internalType":"uint256","name":"exchangeRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_fromToken","type":"address"},{"internalType":"contract IERC20Extension","name":"_toToken","type":"address"}],"name":"getExchangeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_fromToken","type":"address"},{"internalType":"contract IERC20Extension","name":"_toToken","type":"address"}],"name":"getUniswapV2Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_token","type":"address"}],"name":"isEth","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_fromToken","type":"address"},{"internalType":"contract IERC20Extension","name":"_toToken","type":"address"},{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct IForwardingSwapProxy.SwapParams","name":"_swapParams","type":"tuple"},{"internalType":"uint256","name":"_gasRefund","type":"uint256"},{"internalType":"uint256","name":"_minimumReturnAmount","type":"uint256"}],"name":"proxySwapWithFee","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"removeFromWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint8","name":"_inputDecimals","type":"uint8"},{"internalType":"uint8","name":"_outputDecimals","type":"uint8"}],"name":"scaleAmountFromDecimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint8","name":"_inputDecimals","type":"uint8"}],"name":"scaleAmountFromTokenDecimals","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_pauseContract","type":"bool"}],"name":"setContractPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IVault","name":"_vault","type":"address"}],"name":"setVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapV2Router","outputs":[{"internalType":"contract IUniswapV2Router02","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Extension","name":"_token","type":"address"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b50604051620033e9380380620033e98339810160408190526200003491620001cd565b6002805460ff19169055600160035580806200005260008262000068565b506200006060008262000068565b5050620001ff565b62000074828262000078565b5050565b6200008f8282620000bb60201b620015ef1760201c565b6000828152600160209081526040909120620000b69183906200168d6200015b821b17901c565b505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000074576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001173390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600062000172836001600160a01b0384166200017b565b90505b92915050565b6000818152600183016020526040812054620001c45750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915562000175565b50600062000175565b600060208284031215620001e057600080fd5b81516001600160a01b0381168114620001f857600080fd5b9392505050565b6131da806200020f6000396000f3fe6080604052600436106101dc5760003560e01c80639010d07c11610102578063baaa61be11610095578063ea9119a511610064578063ea9119a5146105c8578063ead8ece814610605578063f4f3b2001461063a578063fbfa77cf1461065a57600080fd5b8063baaa61be14610548578063ca15c87314610568578063d547741f14610588578063e43252d7146105a857600080fd5b8063a001ecdd116100d1578063a001ecdd146104d5578063a217fddf146104eb578063a702f2c014610500578063ad5c46481461052057600080fd5b80639010d07c1461043657806390238c391461045657806391d148541461047e5780639ca519c6146104c257600080fd5b80634021a8671161017a5780636817031b116101495780636817031b146103b657806369fe0e2d146103d6578063882796f1146103f65780638ab1d6811461041657600080fd5b80634021a8671461033e5780634c7125941461035e5780635285301c1461037e5780635c975abb1461039e57600080fd5b80632f2ff15d116101b65780632f2ff15d1461029b57806336568abe146102bd5780633af32abf146102dd5780633cc562b21461031657600080fd5b806301ffc9a7146101e85780631694505e1461021d578063248a9ca31461025d57600080fd5b366101e357005b600080fd5b3480156101f457600080fd5b50610208610203366004612970565b61067a565b60405190151581526020015b60405180910390f35b34801561022957600080fd5b50610245737a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b039091168152602001610214565b34801561026957600080fd5b5061028d61027836600461299a565b60009081526020819052604090206001015490565b604051908152602001610214565b3480156102a757600080fd5b506102bb6102b63660046129cb565b6106be565b005b3480156102c957600080fd5b506102bb6102d83660046129cb565b6106e9565b3480156102e957600080fd5b506102086102f83660046129fb565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561032257600080fd5b5061024573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561034a57600080fd5b5061028d610359366004612a27565b61077a565b34801561036a57600080fd5b5061028d610379366004612a69565b61079e565b34801561038a57600080fd5b5061028d610399366004612a69565b610936565b3480156103aa57600080fd5b5060025460ff16610208565b3480156103c257600080fd5b506102bb6103d13660046129fb565b610ab8565b3480156103e257600080fd5b506102bb6103f136600461299a565b610b34565b34801561040257600080fd5b506102bb610411366004612aa5565b610b77565b34801561042257600080fd5b506102bb6104313660046129fb565b610b99565b34801561044257600080fd5b50610245610451366004612ac2565b610c7d565b34801561046257600080fd5b506102457347fb2585d2c56fe188d0e6ec628a38b74fceeedf81565b34801561048a57600080fd5b506102086104993660046129cb565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102bb6104d0366004612ae4565b610c95565b3480156104e157600080fd5b5061028d60055481565b3480156104f757600080fd5b5061028d600081565b34801561050c57600080fd5b5061028d61051b366004612b5d565b61101f565b34801561052c57600080fd5b5061024573c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b34801561055457600080fd5b5061028d610563366004612a69565b611090565b34801561057457600080fd5b5061028d61058336600461299a565b6111bb565b34801561059457600080fd5b506102bb6105a33660046129cb565b6111d2565b3480156105b457600080fd5b506102bb6105c33660046129fb565b6111f8565b3480156105d457600080fd5b506102086105e33660046129fb565b6001600160a01b031673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b34801561061157600080fd5b50610625610620366004612b94565b6112cd565b60408051928352602083019190915201610214565b34801561064657600080fd5b506102bb6106553660046129fb565b6113f5565b34801561066657600080fd5b50600454610245906001600160a01b031681565b60006001600160e01b031982167f5a05180f0000000000000000000000000000000000000000000000000000000014806106b857506106b8826116a2565b92915050565b6000828152602081905260409020600101546106da8133611709565b6106e48383611787565b505050565b6001600160a01b038116331461076c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61077682826117a9565b5050565b600080610786856117cb565b905061079384848361101f565b9150505b9392505050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038416016107dd5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc292505b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b0383160161081a5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc291505b6000610826848461185c565b9050805160000361083b5760009150506106b8565b6000610846856117cb565b9050600061085582600a612cc3565b610860906001612cd2565b6040517fd06ca61f000000000000000000000000000000000000000000000000000000008152909150737a250d5630b4cf539739df2c5dacb4c659f2488d9063d06ca61f906108b59084908790600401612d35565b600060405180830381865afa9250505080156108f357506040513d6000823e601f3d908101601f191682016040526108f09190810190612d6c565b60015b61090357600093505050506106b8565b80600185516109129190612e2a565b8151811061092257610922612e3d565b602002602001015194505050505092915050565b600073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc1196001600160a01b038416016109755773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee92505b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc1196001600160a01b038316016109b25773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee91505b60006109be8484611b41565b905080156109da576109d28382601261077a565b9150506106b8565b6001600160a01b03841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1480610a2157506001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b15610a305760009150506106b8565b6000610a508573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee611b41565b90506000610a7273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee86611b41565b90508115801590610a8257508015155b15610aac576000610a938383611c59565b9050610aa18682601261077a565b9450505050506106b8565b50600095945050505050565b6000610ac48133611709565b600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03841690811790915560405190815233907f8800deb8c31293b539eaf5391fcc88280dc58f015c043d65dd5b72a0979a1dd1906020015b60405180910390a25050565b6000610b408133611709565b600582905560405182815233907f01fe2943baee27f47add82886c2200f910c749c461c9b63c5fe83901a53bdb4990602001610b28565b6000610b838133611709565b8115610b9157610776611c65565b610776611d0a565b6000610ba58133611709565b6001600160a01b03821660009081526006602052604090205460ff16610c335760405162461bcd60e51b815260206004820152602560248201527f41646472657373206973206d697373696e672066726f6d20746865207768697460448201527f656c6973740000000000000000000000000000000000000000000000000000006064820152608401610763565b6001600160a01b038216600081815260066020526040808220805460ff19169055517fcdd2e9b91a56913d370075169cefa1602ba36be5301664f752192bb1709df7579190a25050565b60008281526001602052604081206107979083611d8d565b60025460ff1615610ce85760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610763565b600260035403610d3a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610763565b60026003556001600160a01b0380851690861603610d9a5760405162461bcd60e51b815260206004820152601c60248201527f5f66726f6d546f6b656e20657175616c20746f205f746f546f6b656e000000006044820152606401610763565b6000610da886868685611d99565b90506000610db78683866112cd565b50905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03871603610e6c57610de88183612e2a565b9150828211610e395760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f75676820746f6b656e732072657475726e65640000000000006044820152606401610763565b604051339083156108fc029084906000818181858888f19350505050158015610e66573d6000803e3d6000fd5b50610f97565b60008115610eb857610e9387737a250d5630b4cf539739df2c5dacb4c659f2488d85612070565b610eb4737a250d5630b4cf539739df2c5dacb4c659f2488d8884863061217a565b5090505b610ec28184612e2a565b9250838311610f135760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f75676820746f6b656e732072657475726e65640000000000006044820152606401610763565b6001600160a01b03871663a9059cbb336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018690526044016020604051808303816000875af1158015610f70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f949190612e53565b50505b8015611011576004546001600160a01b031663180e222d82336040516001600160e01b031960e085901b1681526001600160a01b039091166004820152602481018590526044016000604051808303818588803b158015610ff757600080fd5b505af115801561100b573d6000803e3d6000fd5b50505050505b505060016003555050505050565b60008160ff168360ff161015611058576110398383612e70565b6110479060ff16600a612e89565b6110519085612cd2565b9050610797565b8160ff168360ff161115611088576110708284612e70565b61107e9060ff16600a612e89565b6110519085612eab565b509192915050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841614806110d957506001600160a01b03831673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2145b8015611127575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038316148061112757506001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2145b1561113b5750670de0b6b3a76400006106b8565b60006111478484610936565b905080156111565790506106b8565b6000611162858561079e565b905080156111735791506106b89050565b60405162461bcd60e51b815260206004820152600d60248201527f4e6f205261746520466f756e64000000000000000000000000000000000000006044820152606401610763565b60008181526001602052604081206106b8906122ea565b6000828152602081905260409020600101546111ee8133611709565b6106e483836117a9565b60006112048133611709565b6001600160a01b0382166112805760405162461bcd60e51b815260206004820152602960248201527f43616e27742061646420746865203078206164647265737320746f207468652060448201527f77686974656c69737400000000000000000000000000000000000000000000006064820152608401610763565b6001600160a01b038216600081815260066020526040808220805460ff19166001179055517fa850ae9193f515cbae8d35e8925bd2be26627fc91bce650b8652ed254e9cab039190a25050565b60008060006112f08673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2611090565b905060006112fd876117cb565b9050600061131661130e8885611c59565b83601261101f565b905085811161138d5760405162461bcd60e51b815260206004820152602d60248201527f4e6f74207377617070696e6720656e6f75676820746f207265636f766572207460448201527f68652067617320726566756e64000000000000000000000000000000000000006064820152608401610763565b60006113a760055488846113a19190612e2a565b90611c59565b90506113b38782612ecd565b955060006113c38760128661101f565b905060006113d9670de0b6b3a7640000876122f4565b90506113e58282611c59565b9650505050505050935093915050565b60006114018133611709565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038316016114a75747806114745760405162461bcd60e51b815260206004820152601360248201527f4e6f7468696e6720746f207769746864726177000000000000000000000000006044820152606401610763565b604051339082156108fc029083906000818181858888f193505050501580156114a1573d6000803e3d6000fd5b50505050565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156114ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115129190612ee0565b9050600081116115645760405162461bcd60e51b815260206004820152601360248201527f4e6f7468696e6720746f207769746864726177000000000000000000000000006044820152606401610763565b6040517fa9059cbb000000000000000000000000000000000000000000000000000000008152336004820152602481018290526001600160a01b0384169063a9059cbb906044015b6020604051808303816000875af11580156115cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a19190612e53565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610776576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556116493390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610797836001600160a01b038416612309565b60006001600160e01b031982167f7965db0b0000000000000000000000000000000000000000000000000000000014806106b857507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316146106b8565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661077657611745816001600160a01b03166014612358565b611750836020612358565b604051602001611761929190612f1d565b60408051601f198184030181529082905262461bcd60e51b825261076391600401612f9e565b61179182826115ef565b60008281526001602052604090206106e4908261168d565b6117b38282612539565b60008281526001602052604090206106e490826125b8565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038316016117fa57506012919050565b816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611838573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b89190612fd1565b6040517fe6a439050000000000000000000000000000000000000000000000000000000081526001600160a01b03808416600483015282166024820152606090735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f9063e6a4390590604401602060405180830381865afa9250505080156118f4575060408051601f3d908101601f191682019092526118f191810190612fee565b60015b15611a1f576001600160a01b03811615611a1d576000816001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611948573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061196c919061302e565b63ffffffff16925050506201518081426119869190612e2a565b1015611a1b57604080516002808252606082018352909160208301908036833701905050925084836000815181106119c0576119c0612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505083836001815181106119f4576119f4612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505050506106b8565b505b505b6001600160a01b03831673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21480611a6657506001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2145b6106b8576040805160038082526080820190925290602082016060803683370190505090508281600081518110611a9f57611a9f612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110611ae757611ae7612e3d565b60200260200101906001600160a01b031690816001600160a01b0316815250508181600281518110611b1b57611b1b612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505092915050565b60006001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee148015611b835791925073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee915b6040517fbcfd032d0000000000000000000000000000000000000000000000000000000081526001600160a01b038086166004830152841660248201527347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa925050508015611c18575060408051601f3d908101601f19168201909252611c159181019061308d565b60015b611c265760009150506106b8565b8515611c4b57611c3e670de0b6b3a7640000856122f4565b96505050505050506106b8565b8396505050505050506106b8565b600061079783836125cd565b60025460ff1615611cb85760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610763565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611ced3390565b6040516001600160a01b03909116815260200160405180910390a1565b60025460ff16611d5c5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610763565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33611ced565b600061079783836126c6565b6000611dab6102f860208501856129fb565b611df75760405162461bcd60e51b815260206004820152600f60248201527f4e6f742077686974656c697374656400000000000000000000000000000000006044820152606401610763565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03861603611e74578260400135341015611e6f5760405162461bcd60e51b815260206004820152601760248201527f4e6f7420656e6f756768204554482070726f76696465640000000000000000006044820152606401610763565b611f27565b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152602085810135604483015291516001600160a01b038816926323b872dd926064808201939182900301816000875af1158015611ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0b9190612e53565b50611f2785611f1d60208601866129fb565b8560200135612070565b6000611f3385306126f0565b90506000611f4460208601866129fb565b6001600160a01b031634611f5b60608801886130dd565b604051611f6992919061312b565b60006040518083038185875af1925050503d8060008114611fa6576040519150601f19603f3d011682016040523d82523d6000602084013e611fab565b606091505b5050905080611ffc5760405162461bcd60e51b815260206004820152601360248201527f50726f786965642053776170204661696c6564000000000000000000000000006044820152606401610763565b600061200887306126f0565b90506120148382612e2a565b93508484116120655760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f75676820746f6b656e732072657475726e65640000000000006044820152606401610763565b505050949350505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0384160361209957505050565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03838116602483015282919085169063dd62ed3e90604401602060405180830381865afa158015612101573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121259190612ee0565b10156106e4576040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b038381166004830152600019602483015284169063095ea7b3906044016115ac565b60408051600280825260608201835260009283928392909160208301908036833701905050905086816000815181106121b5576121b5612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2816001815181106121fd576121fd612e3d565b6001600160a01b0392831660209182029290920101526040517f4a25d94a0000000000000000000000000000000000000000000000000000000081526000918a1690634a25d94a9061225b908a908a9087908b90429060040161313b565b6000604051808303816000875af115801561227a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526122a29190810190612d6c565b9050806000815181106122b7576122b7612e3d565b6020026020010151816001815181106122d2576122d2612e3d565b60200260200101519350935050509550959350505050565b60006106b8825490565b600061079783670de0b6b3a764000084612797565b6000818152600183016020526040812054612350575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106b8565b5060006106b8565b60606000612367836002612cd2565b612372906002612ecd565b67ffffffffffffffff81111561238a5761238a612d56565b6040519080825280601f01601f1916602001820160405280156123b4576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106123eb576123eb612e3d565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061243657612436612e3d565b60200101906001600160f81b031916908160001a905350600061245a846002612cd2565b612465906001612ecd565b90505b60018111156124ea577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106124a6576124a6612e3d565b1a60f81b8282815181106124bc576124bc612e3d565b60200101906001600160f81b031916908160001a90535060049490941c936124e381613177565b9050612468565b5083156107975760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610763565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610776576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610797836001600160a01b03841661287d565b60008080600019848609848602925082811083820303915050670de0b6b3a7640000811061262a576040517fd31b340200000000000000000000000000000000000000000000000000000000815260048101829052602401610763565b600080670de0b6b3a764000086880991506706f05b59d3b1ffff82119050826000036126685780670de0b6b3a76400008504019450505050506106b8565b6204000082850304939091119091037d40000000000000000000000000000000000000000000000000000000000002919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b60008260000182815481106126dd576126dd612e3d565b9060005260206000200154905092915050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841614612787576040516370a0823160e01b81526001600160a01b0383811660048301528416906370a0823190602401602060405180830381865afa15801561275c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127809190612ee0565b90506106b8565b506001600160a01b031631919050565b60008080600019858709858702925082811083820303915050806000036127d1578382816127c7576127c7612e95565b0492505050610797565b838110612814576040517f773cc18c0000000000000000000000000000000000000000000000000000000081526004810182905260248101859052604401610763565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b600081815260018301602052604081205480156129665760006128a1600183612e2a565b85549091506000906128b590600190612e2a565b905081811461291a5760008660000182815481106128d5576128d5612e3d565b90600052602060002001549050808760000184815481106128f8576128f8612e3d565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061292b5761292b61318e565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506106b8565b60009150506106b8565b60006020828403121561298257600080fd5b81356001600160e01b03198116811461079757600080fd5b6000602082840312156129ac57600080fd5b5035919050565b6001600160a01b03811681146129c857600080fd5b50565b600080604083850312156129de57600080fd5b8235915060208301356129f0816129b3565b809150509250929050565b600060208284031215612a0d57600080fd5b8135610797816129b3565b60ff811681146129c857600080fd5b600080600060608486031215612a3c57600080fd5b8335612a47816129b3565b9250602084013591506040840135612a5e81612a18565b809150509250925092565b60008060408385031215612a7c57600080fd5b8235612a87816129b3565b915060208301356129f0816129b3565b80151581146129c857600080fd5b600060208284031215612ab757600080fd5b813561079781612a97565b60008060408385031215612ad557600080fd5b50508035926020909101359150565b600080600080600060a08688031215612afc57600080fd5b8535612b07816129b3565b94506020860135612b17816129b3565b9350604086013567ffffffffffffffff811115612b3357600080fd5b860160808189031215612b4557600080fd5b94979396509394606081013594506080013592915050565b600080600060608486031215612b7257600080fd5b833592506020840135612b8481612a18565b91506040840135612a5e81612a18565b600080600060608486031215612ba957600080fd5b8335612bb4816129b3565b95602085013595506040909401359392505050565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115612c1a578160001904821115612c0057612c00612bc9565b80851615612c0d57918102915b93841c9390800290612be4565b509250929050565b600082612c31575060016106b8565b81612c3e575060006106b8565b8160018114612c545760028114612c5e57612c7a565b60019150506106b8565b60ff841115612c6f57612c6f612bc9565b50506001821b6106b8565b5060208310610133831016604e8410600b8410161715612c9d575081810a6106b8565b612ca78383612bdf565b8060001904821115612cbb57612cbb612bc9565b029392505050565b600061079760ff841683612c22565b6000816000190483118215151615612cec57612cec612bc9565b500290565b600081518084526020808501945080840160005b83811015612d2a5781516001600160a01b031687529582019590820190600101612d05565b509495945050505050565b828152604060208201526000612d4e6040830184612cf1565b949350505050565b634e487b7160e01b600052604160045260246000fd5b60006020808385031215612d7f57600080fd5b825167ffffffffffffffff80821115612d9757600080fd5b818501915085601f830112612dab57600080fd5b815181811115612dbd57612dbd612d56565b8060051b604051601f19603f83011681018181108582111715612de257612de2612d56565b604052918252848201925083810185019188831115612e0057600080fd5b938501935b82851015612e1e57845184529385019392850192612e05565b98975050505050505050565b818103818111156106b8576106b8612bc9565b634e487b7160e01b600052603260045260246000fd5b600060208284031215612e6557600080fd5b815161079781612a97565b60ff82811682821603908111156106b8576106b8612bc9565b60006107978383612c22565b634e487b7160e01b600052601260045260246000fd5b600082612ec857634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156106b8576106b8612bc9565b600060208284031215612ef257600080fd5b5051919050565b60005b83811015612f14578181015183820152602001612efc565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612f55816017850160208801612ef9565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351612f92816028840160208801612ef9565b01602801949350505050565b6020815260008251806020840152612fbd816040850160208701612ef9565b601f01601f19169190910160400192915050565b600060208284031215612fe357600080fd5b815161079781612a18565b60006020828403121561300057600080fd5b8151610797816129b3565b80516dffffffffffffffffffffffffffff8116811461302957600080fd5b919050565b60008060006060848603121561304357600080fd5b61304c8461300b565b925061305a6020850161300b565b9150604084015163ffffffff81168114612a5e57600080fd5b805169ffffffffffffffffffff8116811461302957600080fd5b600080600080600060a086880312156130a557600080fd5b6130ae86613073565b94506020860151935060408601519250606086015191506130d160808701613073565b90509295509295909350565b6000808335601e198436030181126130f457600080fd5b83018035915067ffffffffffffffff82111561310f57600080fd5b60200191503681900382131561312457600080fd5b9250929050565b8183823760009101908152919050565b85815284602082015260a06040820152600061315a60a0830186612cf1565b6001600160a01b0394909416606083015250608001529392505050565b60008161318657613186612bc9565b506000190190565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220779a2aef3a91b7a1dd8423e4d22e496a724583bd3ef74da0dfec037ca4b4269f64736f6c6343000810003300000000000000000000000057983af61b683173db345710805aefe959cda5b5

Deployed Bytecode

0x6080604052600436106101dc5760003560e01c80639010d07c11610102578063baaa61be11610095578063ea9119a511610064578063ea9119a5146105c8578063ead8ece814610605578063f4f3b2001461063a578063fbfa77cf1461065a57600080fd5b8063baaa61be14610548578063ca15c87314610568578063d547741f14610588578063e43252d7146105a857600080fd5b8063a001ecdd116100d1578063a001ecdd146104d5578063a217fddf146104eb578063a702f2c014610500578063ad5c46481461052057600080fd5b80639010d07c1461043657806390238c391461045657806391d148541461047e5780639ca519c6146104c257600080fd5b80634021a8671161017a5780636817031b116101495780636817031b146103b657806369fe0e2d146103d6578063882796f1146103f65780638ab1d6811461041657600080fd5b80634021a8671461033e5780634c7125941461035e5780635285301c1461037e5780635c975abb1461039e57600080fd5b80632f2ff15d116101b65780632f2ff15d1461029b57806336568abe146102bd5780633af32abf146102dd5780633cc562b21461031657600080fd5b806301ffc9a7146101e85780631694505e1461021d578063248a9ca31461025d57600080fd5b366101e357005b600080fd5b3480156101f457600080fd5b50610208610203366004612970565b61067a565b60405190151581526020015b60405180910390f35b34801561022957600080fd5b50610245737a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b039091168152602001610214565b34801561026957600080fd5b5061028d61027836600461299a565b60009081526020819052604090206001015490565b604051908152602001610214565b3480156102a757600080fd5b506102bb6102b63660046129cb565b6106be565b005b3480156102c957600080fd5b506102bb6102d83660046129cb565b6106e9565b3480156102e957600080fd5b506102086102f83660046129fb565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561032257600080fd5b5061024573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561034a57600080fd5b5061028d610359366004612a27565b61077a565b34801561036a57600080fd5b5061028d610379366004612a69565b61079e565b34801561038a57600080fd5b5061028d610399366004612a69565b610936565b3480156103aa57600080fd5b5060025460ff16610208565b3480156103c257600080fd5b506102bb6103d13660046129fb565b610ab8565b3480156103e257600080fd5b506102bb6103f136600461299a565b610b34565b34801561040257600080fd5b506102bb610411366004612aa5565b610b77565b34801561042257600080fd5b506102bb6104313660046129fb565b610b99565b34801561044257600080fd5b50610245610451366004612ac2565b610c7d565b34801561046257600080fd5b506102457347fb2585d2c56fe188d0e6ec628a38b74fceeedf81565b34801561048a57600080fd5b506102086104993660046129cb565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6102bb6104d0366004612ae4565b610c95565b3480156104e157600080fd5b5061028d60055481565b3480156104f757600080fd5b5061028d600081565b34801561050c57600080fd5b5061028d61051b366004612b5d565b61101f565b34801561052c57600080fd5b5061024573c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b34801561055457600080fd5b5061028d610563366004612a69565b611090565b34801561057457600080fd5b5061028d61058336600461299a565b6111bb565b34801561059457600080fd5b506102bb6105a33660046129cb565b6111d2565b3480156105b457600080fd5b506102bb6105c33660046129fb565b6111f8565b3480156105d457600080fd5b506102086105e33660046129fb565b6001600160a01b031673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b34801561061157600080fd5b50610625610620366004612b94565b6112cd565b60408051928352602083019190915201610214565b34801561064657600080fd5b506102bb6106553660046129fb565b6113f5565b34801561066657600080fd5b50600454610245906001600160a01b031681565b60006001600160e01b031982167f5a05180f0000000000000000000000000000000000000000000000000000000014806106b857506106b8826116a2565b92915050565b6000828152602081905260409020600101546106da8133611709565b6106e48383611787565b505050565b6001600160a01b038116331461076c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b61077682826117a9565b5050565b600080610786856117cb565b905061079384848361101f565b9150505b9392505050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038416016107dd5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc292505b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b0383160161081a5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc291505b6000610826848461185c565b9050805160000361083b5760009150506106b8565b6000610846856117cb565b9050600061085582600a612cc3565b610860906001612cd2565b6040517fd06ca61f000000000000000000000000000000000000000000000000000000008152909150737a250d5630b4cf539739df2c5dacb4c659f2488d9063d06ca61f906108b59084908790600401612d35565b600060405180830381865afa9250505080156108f357506040513d6000823e601f3d908101601f191682016040526108f09190810190612d6c565b60015b61090357600093505050506106b8565b80600185516109129190612e2a565b8151811061092257610922612e3d565b602002602001015194505050505092915050565b600073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc1196001600160a01b038416016109755773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee92505b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc1196001600160a01b038316016109b25773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee91505b60006109be8484611b41565b905080156109da576109d28382601261077a565b9150506106b8565b6001600160a01b03841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1480610a2157506001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b15610a305760009150506106b8565b6000610a508573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee611b41565b90506000610a7273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee86611b41565b90508115801590610a8257508015155b15610aac576000610a938383611c59565b9050610aa18682601261077a565b9450505050506106b8565b50600095945050505050565b6000610ac48133611709565b600480547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03841690811790915560405190815233907f8800deb8c31293b539eaf5391fcc88280dc58f015c043d65dd5b72a0979a1dd1906020015b60405180910390a25050565b6000610b408133611709565b600582905560405182815233907f01fe2943baee27f47add82886c2200f910c749c461c9b63c5fe83901a53bdb4990602001610b28565b6000610b838133611709565b8115610b9157610776611c65565b610776611d0a565b6000610ba58133611709565b6001600160a01b03821660009081526006602052604090205460ff16610c335760405162461bcd60e51b815260206004820152602560248201527f41646472657373206973206d697373696e672066726f6d20746865207768697460448201527f656c6973740000000000000000000000000000000000000000000000000000006064820152608401610763565b6001600160a01b038216600081815260066020526040808220805460ff19169055517fcdd2e9b91a56913d370075169cefa1602ba36be5301664f752192bb1709df7579190a25050565b60008281526001602052604081206107979083611d8d565b60025460ff1615610ce85760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610763565b600260035403610d3a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610763565b60026003556001600160a01b0380851690861603610d9a5760405162461bcd60e51b815260206004820152601c60248201527f5f66726f6d546f6b656e20657175616c20746f205f746f546f6b656e000000006044820152606401610763565b6000610da886868685611d99565b90506000610db78683866112cd565b50905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03871603610e6c57610de88183612e2a565b9150828211610e395760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f75676820746f6b656e732072657475726e65640000000000006044820152606401610763565b604051339083156108fc029084906000818181858888f19350505050158015610e66573d6000803e3d6000fd5b50610f97565b60008115610eb857610e9387737a250d5630b4cf539739df2c5dacb4c659f2488d85612070565b610eb4737a250d5630b4cf539739df2c5dacb4c659f2488d8884863061217a565b5090505b610ec28184612e2a565b9250838311610f135760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f75676820746f6b656e732072657475726e65640000000000006044820152606401610763565b6001600160a01b03871663a9059cbb336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018690526044016020604051808303816000875af1158015610f70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f949190612e53565b50505b8015611011576004546001600160a01b031663180e222d82336040516001600160e01b031960e085901b1681526001600160a01b039091166004820152602481018590526044016000604051808303818588803b158015610ff757600080fd5b505af115801561100b573d6000803e3d6000fd5b50505050505b505060016003555050505050565b60008160ff168360ff161015611058576110398383612e70565b6110479060ff16600a612e89565b6110519085612cd2565b9050610797565b8160ff168360ff161115611088576110708284612e70565b61107e9060ff16600a612e89565b6110519085612eab565b509192915050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841614806110d957506001600160a01b03831673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2145b8015611127575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038316148061112757506001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2145b1561113b5750670de0b6b3a76400006106b8565b60006111478484610936565b905080156111565790506106b8565b6000611162858561079e565b905080156111735791506106b89050565b60405162461bcd60e51b815260206004820152600d60248201527f4e6f205261746520466f756e64000000000000000000000000000000000000006044820152606401610763565b60008181526001602052604081206106b8906122ea565b6000828152602081905260409020600101546111ee8133611709565b6106e483836117a9565b60006112048133611709565b6001600160a01b0382166112805760405162461bcd60e51b815260206004820152602960248201527f43616e27742061646420746865203078206164647265737320746f207468652060448201527f77686974656c69737400000000000000000000000000000000000000000000006064820152608401610763565b6001600160a01b038216600081815260066020526040808220805460ff19166001179055517fa850ae9193f515cbae8d35e8925bd2be26627fc91bce650b8652ed254e9cab039190a25050565b60008060006112f08673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2611090565b905060006112fd876117cb565b9050600061131661130e8885611c59565b83601261101f565b905085811161138d5760405162461bcd60e51b815260206004820152602d60248201527f4e6f74207377617070696e6720656e6f75676820746f207265636f766572207460448201527f68652067617320726566756e64000000000000000000000000000000000000006064820152608401610763565b60006113a760055488846113a19190612e2a565b90611c59565b90506113b38782612ecd565b955060006113c38760128661101f565b905060006113d9670de0b6b3a7640000876122f4565b90506113e58282611c59565b9650505050505050935093915050565b60006114018133611709565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038316016114a75747806114745760405162461bcd60e51b815260206004820152601360248201527f4e6f7468696e6720746f207769746864726177000000000000000000000000006044820152606401610763565b604051339082156108fc029083906000818181858888f193505050501580156114a1573d6000803e3d6000fd5b50505050565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156114ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115129190612ee0565b9050600081116115645760405162461bcd60e51b815260206004820152601360248201527f4e6f7468696e6720746f207769746864726177000000000000000000000000006044820152606401610763565b6040517fa9059cbb000000000000000000000000000000000000000000000000000000008152336004820152602481018290526001600160a01b0384169063a9059cbb906044015b6020604051808303816000875af11580156115cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a19190612e53565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16610776576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556116493390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610797836001600160a01b038416612309565b60006001600160e01b031982167f7965db0b0000000000000000000000000000000000000000000000000000000014806106b857507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316146106b8565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1661077657611745816001600160a01b03166014612358565b611750836020612358565b604051602001611761929190612f1d565b60408051601f198184030181529082905262461bcd60e51b825261076391600401612f9e565b61179182826115ef565b60008281526001602052604090206106e4908261168d565b6117b38282612539565b60008281526001602052604090206106e490826125b8565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038316016117fa57506012919050565b816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611838573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b89190612fd1565b6040517fe6a439050000000000000000000000000000000000000000000000000000000081526001600160a01b03808416600483015282166024820152606090735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f9063e6a4390590604401602060405180830381865afa9250505080156118f4575060408051601f3d908101601f191682019092526118f191810190612fee565b60015b15611a1f576001600160a01b03811615611a1d576000816001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611948573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061196c919061302e565b63ffffffff16925050506201518081426119869190612e2a565b1015611a1b57604080516002808252606082018352909160208301908036833701905050925084836000815181106119c0576119c0612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505083836001815181106119f4576119f4612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505050506106b8565b505b505b6001600160a01b03831673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21480611a6657506001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2145b6106b8576040805160038082526080820190925290602082016060803683370190505090508281600081518110611a9f57611a9f612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110611ae757611ae7612e3d565b60200260200101906001600160a01b031690816001600160a01b0316815250508181600281518110611b1b57611b1b612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505092915050565b60006001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee148015611b835791925073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee915b6040517fbcfd032d0000000000000000000000000000000000000000000000000000000081526001600160a01b038086166004830152841660248201527347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa925050508015611c18575060408051601f3d908101601f19168201909252611c159181019061308d565b60015b611c265760009150506106b8565b8515611c4b57611c3e670de0b6b3a7640000856122f4565b96505050505050506106b8565b8396505050505050506106b8565b600061079783836125cd565b60025460ff1615611cb85760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610763565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611ced3390565b6040516001600160a01b03909116815260200160405180910390a1565b60025460ff16611d5c5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610763565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33611ced565b600061079783836126c6565b6000611dab6102f860208501856129fb565b611df75760405162461bcd60e51b815260206004820152600f60248201527f4e6f742077686974656c697374656400000000000000000000000000000000006044820152606401610763565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03861603611e74578260400135341015611e6f5760405162461bcd60e51b815260206004820152601760248201527f4e6f7420656e6f756768204554482070726f76696465640000000000000000006044820152606401610763565b611f27565b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152602085810135604483015291516001600160a01b038816926323b872dd926064808201939182900301816000875af1158015611ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0b9190612e53565b50611f2785611f1d60208601866129fb565b8560200135612070565b6000611f3385306126f0565b90506000611f4460208601866129fb565b6001600160a01b031634611f5b60608801886130dd565b604051611f6992919061312b565b60006040518083038185875af1925050503d8060008114611fa6576040519150601f19603f3d011682016040523d82523d6000602084013e611fab565b606091505b5050905080611ffc5760405162461bcd60e51b815260206004820152601360248201527f50726f786965642053776170204661696c6564000000000000000000000000006044820152606401610763565b600061200887306126f0565b90506120148382612e2a565b93508484116120655760405162461bcd60e51b815260206004820152601a60248201527f4e6f7420656e6f75676820746f6b656e732072657475726e65640000000000006044820152606401610763565b505050949350505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b0384160361209957505050565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03838116602483015282919085169063dd62ed3e90604401602060405180830381865afa158015612101573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121259190612ee0565b10156106e4576040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b038381166004830152600019602483015284169063095ea7b3906044016115ac565b60408051600280825260608201835260009283928392909160208301908036833701905050905086816000815181106121b5576121b5612e3d565b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2816001815181106121fd576121fd612e3d565b6001600160a01b0392831660209182029290920101526040517f4a25d94a0000000000000000000000000000000000000000000000000000000081526000918a1690634a25d94a9061225b908a908a9087908b90429060040161313b565b6000604051808303816000875af115801561227a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526122a29190810190612d6c565b9050806000815181106122b7576122b7612e3d565b6020026020010151816001815181106122d2576122d2612e3d565b60200260200101519350935050509550959350505050565b60006106b8825490565b600061079783670de0b6b3a764000084612797565b6000818152600183016020526040812054612350575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106b8565b5060006106b8565b60606000612367836002612cd2565b612372906002612ecd565b67ffffffffffffffff81111561238a5761238a612d56565b6040519080825280601f01601f1916602001820160405280156123b4576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106123eb576123eb612e3d565b60200101906001600160f81b031916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061243657612436612e3d565b60200101906001600160f81b031916908160001a905350600061245a846002612cd2565b612465906001612ecd565b90505b60018111156124ea577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106124a6576124a6612e3d565b1a60f81b8282815181106124bc576124bc612e3d565b60200101906001600160f81b031916908160001a90535060049490941c936124e381613177565b9050612468565b5083156107975760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610763565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1615610776576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610797836001600160a01b03841661287d565b60008080600019848609848602925082811083820303915050670de0b6b3a7640000811061262a576040517fd31b340200000000000000000000000000000000000000000000000000000000815260048101829052602401610763565b600080670de0b6b3a764000086880991506706f05b59d3b1ffff82119050826000036126685780670de0b6b3a76400008504019450505050506106b8565b6204000082850304939091119091037d40000000000000000000000000000000000000000000000000000000000002919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b60008260000182815481106126dd576126dd612e3d565b9060005260206000200154905092915050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03841614612787576040516370a0823160e01b81526001600160a01b0383811660048301528416906370a0823190602401602060405180830381865afa15801561275c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127809190612ee0565b90506106b8565b506001600160a01b031631919050565b60008080600019858709858702925082811083820303915050806000036127d1578382816127c7576127c7612e95565b0492505050610797565b838110612814576040517f773cc18c0000000000000000000000000000000000000000000000000000000081526004810182905260248101859052604401610763565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b600081815260018301602052604081205480156129665760006128a1600183612e2a565b85549091506000906128b590600190612e2a565b905081811461291a5760008660000182815481106128d5576128d5612e3d565b90600052602060002001549050808760000184815481106128f8576128f8612e3d565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061292b5761292b61318e565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506106b8565b60009150506106b8565b60006020828403121561298257600080fd5b81356001600160e01b03198116811461079757600080fd5b6000602082840312156129ac57600080fd5b5035919050565b6001600160a01b03811681146129c857600080fd5b50565b600080604083850312156129de57600080fd5b8235915060208301356129f0816129b3565b809150509250929050565b600060208284031215612a0d57600080fd5b8135610797816129b3565b60ff811681146129c857600080fd5b600080600060608486031215612a3c57600080fd5b8335612a47816129b3565b9250602084013591506040840135612a5e81612a18565b809150509250925092565b60008060408385031215612a7c57600080fd5b8235612a87816129b3565b915060208301356129f0816129b3565b80151581146129c857600080fd5b600060208284031215612ab757600080fd5b813561079781612a97565b60008060408385031215612ad557600080fd5b50508035926020909101359150565b600080600080600060a08688031215612afc57600080fd5b8535612b07816129b3565b94506020860135612b17816129b3565b9350604086013567ffffffffffffffff811115612b3357600080fd5b860160808189031215612b4557600080fd5b94979396509394606081013594506080013592915050565b600080600060608486031215612b7257600080fd5b833592506020840135612b8481612a18565b91506040840135612a5e81612a18565b600080600060608486031215612ba957600080fd5b8335612bb4816129b3565b95602085013595506040909401359392505050565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115612c1a578160001904821115612c0057612c00612bc9565b80851615612c0d57918102915b93841c9390800290612be4565b509250929050565b600082612c31575060016106b8565b81612c3e575060006106b8565b8160018114612c545760028114612c5e57612c7a565b60019150506106b8565b60ff841115612c6f57612c6f612bc9565b50506001821b6106b8565b5060208310610133831016604e8410600b8410161715612c9d575081810a6106b8565b612ca78383612bdf565b8060001904821115612cbb57612cbb612bc9565b029392505050565b600061079760ff841683612c22565b6000816000190483118215151615612cec57612cec612bc9565b500290565b600081518084526020808501945080840160005b83811015612d2a5781516001600160a01b031687529582019590820190600101612d05565b509495945050505050565b828152604060208201526000612d4e6040830184612cf1565b949350505050565b634e487b7160e01b600052604160045260246000fd5b60006020808385031215612d7f57600080fd5b825167ffffffffffffffff80821115612d9757600080fd5b818501915085601f830112612dab57600080fd5b815181811115612dbd57612dbd612d56565b8060051b604051601f19603f83011681018181108582111715612de257612de2612d56565b604052918252848201925083810185019188831115612e0057600080fd5b938501935b82851015612e1e57845184529385019392850192612e05565b98975050505050505050565b818103818111156106b8576106b8612bc9565b634e487b7160e01b600052603260045260246000fd5b600060208284031215612e6557600080fd5b815161079781612a97565b60ff82811682821603908111156106b8576106b8612bc9565b60006107978383612c22565b634e487b7160e01b600052601260045260246000fd5b600082612ec857634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156106b8576106b8612bc9565b600060208284031215612ef257600080fd5b5051919050565b60005b83811015612f14578181015183820152602001612efc565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612f55816017850160208801612ef9565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351612f92816028840160208801612ef9565b01602801949350505050565b6020815260008251806020840152612fbd816040850160208701612ef9565b601f01601f19169190910160400192915050565b600060208284031215612fe357600080fd5b815161079781612a18565b60006020828403121561300057600080fd5b8151610797816129b3565b80516dffffffffffffffffffffffffffff8116811461302957600080fd5b919050565b60008060006060848603121561304357600080fd5b61304c8461300b565b925061305a6020850161300b565b9150604084015163ffffffff81168114612a5e57600080fd5b805169ffffffffffffffffffff8116811461302957600080fd5b600080600080600060a086880312156130a557600080fd5b6130ae86613073565b94506020860151935060408601519250606086015191506130d160808701613073565b90509295509295909350565b6000808335601e198436030181126130f457600080fd5b83018035915067ffffffffffffffff82111561310f57600080fd5b60200191503681900382131561312457600080fd5b9250929050565b8183823760009101908152919050565b85815284602082015260a06040820152600061315a60a0830186612cf1565b6001600160a01b0394909416606083015250608001529392505050565b60008161318657613186612bc9565b506000190190565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220779a2aef3a91b7a1dd8423e4d22e496a724583bd3ef74da0dfec037ca4b4269f64736f6c63430008100033

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

00000000000000000000000057983af61b683173db345710805aefe959cda5b5

-----Decoded View---------------
Arg [0] : _admin (address): 0x57983af61B683173db345710805aEfE959cdA5B5

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000057983af61b683173db345710805aefe959cda5b5


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.