Contract 0x6646A35e74e35585B0B02e5190445A324E5D4D01 2

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x639831fb5c055c9bdc90757a9389825c6eefd4cb29a6eb35754682619b85417c0x60806040199464582022-08-10 21:57:3750 days 18 hrs ago0x4b70031e70a64a3c9af242a0ba96e4b9bdb2fd6c IN  Create: AMMRouterV10 ETH0.015354133927 ETH
[ Download CSV Export 
Latest 1 internal transaction
Parent Txn Hash Block From To Value
0xec2ebe02f99906cc79d45ecfc86c98df0db9026958e77940831cc01ff92efb70199464632022-08-10 21:58:4650 days 18 hrs ago 0x462bcb4bbd05990446b948926523f27f1be03fd1 0x6646a35e74e35585b0b02e5190445a324e5d4d010 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AMMRouterV1

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 1000 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 13 : AMMRouterV1.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.7.6;
pragma abicoder v2;

import "@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/EnumerableSetUpgradeable.sol";

import "./interfaces/IAMM.sol";
import "./interfaces/IAMMRouterV1.sol";
import "./interfaces/IAMMRegistry.sol";
import "./interfaces/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

contract AMMRouterV1 is IAMMRouterV1, AccessControlUpgradeable {
    using SafeERC20Upgradeable for IERC20;
    using SafeMathUpgradeable for uint256;
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;

    uint256 internal constant UNIT = 10**18;
    uint256 private constant MAX_UINT256 = uint256(-1);
    bytes32 internal constant ADMIN_ROLE =
        0xa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775;
    bytes32 internal constant WHITELIST_ROLE =
        0xdc72ed553f2544c34465af23b847953efeb813428162d767f9ba5f4013be6760;

    IAMMRegistry public registry;
    uint256 public GOVERNANCE_FEE;
    mapping(address => uint256) public REFERRAL_FEE; // % of the governance fee
    EnumerableSetUpgradeable.AddressSet internal referralAddresses;

    modifier ensure(uint256 deadline) {
        require(
            deadline >= block.timestamp,
            "AMMRouterV1: Deadline has expired"
        );
        _;
    }

    modifier isValidAmm(address _ammAddress) {
        require(
            registry.isRegisteredAMM(_ammAddress),
            "AMMRouterV1: invalid amm address"
        );
        _;
    }

    event RegistrySet(IAMMRegistry _registry);
    event TokenApproved(IERC20 _token, IAMM _amm);
    event GovernanceFeeUpdated(uint256 _fee);
    event GovernanceFeeCollected(
        IERC20 _token,
        uint256 _amount,
        address _recipient
    );
    event ReferralRecipientAdded(address _recipient);
    event ReferralRecipientRemoved(address _recipient);
    event ReferralSet(address _recipient, uint256 _fee);
    event ReferralFeePaid(address _recipient, uint256 _feeAmount);

    function initialize(IAMMRegistry _registry, address _admin)
        public
        virtual
        initializer
    {
        _setupRole(DEFAULT_ADMIN_ROLE, _admin);
        registry = _registry;
        emit RegistrySet(_registry);
    }

    /* Swapping methods */
    function swapExactAmountIn(
        IAMM _amm,
        uint256[] calldata _pairPath, // e.g. [0, 1] -> will swap on pair 0 then 1
        uint256[] calldata _tokenPath, // e.g. [1, 0, 0, 1] -> will swap on pair 0 from token 1 to 0, then swap on pair 1 from token 0 to 1.
        uint256 _tokenAmountIn,
        uint256 _minAmountOut,
        address _to,
        uint256 _deadline,
        address _referralRecipient
    ) public override ensure(_deadline) returns (uint256 tokenAmountOut) {
        require(
            _tokenPath[0] != _tokenPath[1],
            "AMMRouterV1: invalid token path"
        );
        uint256 _currentTokenAmountIn = _pushFees(
            _amm,
            _pairPath,
            _tokenPath,
            _tokenAmountIn,
            _referralRecipient,
            false
        );

        uint256 _pairPathMaxIndex = _pairPath.length;
        require(
            _pairPathMaxIndex <= 2 && _pairPathMaxIndex > 0,
            "AMMRouterV1: invalid path length"
        );
        if (_pairPathMaxIndex == 2) {
            // only feasible path is 1 0 0 1
            require(
                _pairPath[0] != _pairPath[1] &&
                    _tokenPath[2] != _tokenPath[3] &&
                    _tokenPath[0] == _tokenPath[3] &&
                    _tokenPath[0] == 1,
                "AMMRouterV1: invalid path"
            );
        }

        (_currentTokenAmountIn, ) = _amm.swapExactAmountIn(
            _pairPath[0],
            _tokenPath[0],
            _currentTokenAmountIn,
            _tokenPath[1],
            0, // ignore _minAmountOut for intermediary swaps
            _pairPathMaxIndex == 1 ? _to : address(this) // send to recipient only for last swap
        );

        if (_pairPathMaxIndex == 2) {
            (_currentTokenAmountIn, ) = _amm.swapExactAmountIn(
                _pairPath[1],
                _tokenPath[2],
                _currentTokenAmountIn,
                _tokenPath[3],
                0, // ignore _minAmountOut for intermediary swaps
                _to // send to recipient only for last swap
            );
        }

        require(
            _currentTokenAmountIn >= _minAmountOut,
            "AMMRouterV1: Min amount not reached"
        );
        tokenAmountOut = _currentTokenAmountIn; // return value of last swapExactAmountIn call
    }

    function _pushFeesCalculation(uint256 _tokenAmountIn, bool _isSwappingOut)
        internal
        returns (
            uint256 _currentAmountIn,
            uint256 _feeAmount,
            uint256 _pushAmount
        )
    {
        if (_isSwappingOut) {
            _currentAmountIn = _tokenAmountIn.mul(UNIT).div(
                UNIT - GOVERNANCE_FEE
            ); // deScale currentAmout
            _feeAmount = _currentAmountIn.sub(_tokenAmountIn);
            _pushAmount = _currentAmountIn;
        } else {
            _currentAmountIn = _tokenAmountIn.mul(UNIT - GOVERNANCE_FEE) / UNIT; // Scale currentAmout
            _feeAmount = _tokenAmountIn.sub(_currentAmountIn);
            _pushAmount = _tokenAmountIn;
        }
    }

    function _pushFees(
        IAMM _amm,
        uint256[] calldata _pairPath, // e.g. [0, 1] -> will swap on pair 0 then 1
        uint256[] calldata _tokenPath, // e.g. [1, 0, 0, 1] -> will swap on pair 0 from token 1 to 0, then swap on pair 1 from token 0 to 1.
        uint256 _tokenAmountIn,
        address _referralRecipient,
        bool _isSwappingOut
    ) internal returns (uint256 _currentAmountIn) {
        uint256 _feeAmount;
        uint256 _pushAmount;
        IERC20 tokenIn = _tokenPath[0] == 0
            ? IERC20(_amm.getPTAddress())
            : IERC20(_amm.getPairWithID(_pairPath[0]).tokenAddress);
        (_currentAmountIn, _feeAmount, _pushAmount) = _pushFeesCalculation(
            _tokenAmountIn,
            _isSwappingOut
        );

        tokenIn.safeTransferFrom(msg.sender, address(this), _pushAmount);
        uint256 referralFee = REFERRAL_FEE[_referralRecipient];
        if (referralFee != 0) {
            uint256 feeAmount = _feeAmount.mul(referralFee) / UNIT;
            if (feeAmount > 0) {
                tokenIn.safeTransfer(_referralRecipient, feeAmount);
                emit ReferralFeePaid(_referralRecipient, feeAmount);
            }
        }
    }

    function swapExactAmountOut(
        IAMM _amm,
        uint256[] calldata _pairPath, // e.g. [0, 1] -> will swap on pair 0 then 1
        uint256[] calldata _tokenPath, // e.g. [1, 0, 0, 1] -> will swap on pair 0 from token 1 to 0, then swap on pair 1 from token 0 to 1.
        uint256 _maxAmountIn,
        uint256 _tokenAmountOut,
        address _to,
        uint256 _deadline,
        address _referralRecipient
    ) external override ensure(_deadline) returns (uint256 tokenAmountIn) {
        require(
            _tokenPath[0] != _tokenPath[1],
            "AMMRouterV1: invalid token path"
        );
        uint256 _pairPathMaxIndex = _pairPath.length;
        require(
            _pairPathMaxIndex <= 2 && _pairPathMaxIndex > 0,
            "AMMRouterswapExactAmountOutV1: invalid path length"
        );
        if (_pairPathMaxIndex == 2) {
            // only feasible path is 1 0 0 1
            require(
                _pairPath[0] != _pairPath[1] &&
                    _tokenPath[2] != _tokenPath[3] &&
                    _tokenPath[0] == _tokenPath[3] &&
                    _tokenPath[0] == 1,
                "AMMRouterV1: invalid path"
            );
        }

        uint256 currentAmountInWithoutGovernance = _getAmountInWithoutGovernance(
                _amm,
                _pairPath,
                _tokenPath,
                _tokenAmountOut
            );
        _pushFees(
            _amm,
            _pairPath,
            _tokenPath,
            currentAmountInWithoutGovernance,
            _referralRecipient,
            true
        );
        require(
            currentAmountInWithoutGovernance <= _maxAmountIn,
            "AMMRouterV1: Max amount in reached"
        );
        tokenAmountIn = _executeSwap(
            _amm,
            _pairPath,
            _tokenPath,
            currentAmountInWithoutGovernance,
            _tokenAmountOut,
            _to
        );
    }

    function _executeSwap(
        IAMM _amm,
        uint256[] memory _pairPath,
        uint256[] memory _tokenPath,
        uint256 amountIn,
        uint256 _tokenAmountOut,
        address _to
    ) private returns (uint256 tokenAmountIn) {
        uint256[] memory pairPath = new uint256[](1);
        uint256[] memory tokenPath = new uint256[](2);
        uint256 firstSwapAmountOut;
        if (_pairPath.length == 2) {
            pairPath[0] = _pairPath[1];
            tokenPath[0] = _tokenPath[2];
            tokenPath[1] = _tokenPath[3];
            firstSwapAmountOut = _getAmountInWithoutGovernance(
                _amm,
                pairPath,
                tokenPath,
                _tokenAmountOut
            );

            (tokenAmountIn, ) = _amm.swapExactAmountOut(
                _pairPath[0],
                _tokenPath[0],
                amountIn,
                _tokenPath[1],
                firstSwapAmountOut,
                address(this)
            );
        } else {
            tokenPath[0] = _tokenPath[0];
            tokenPath[1] = _tokenPath[1];
            firstSwapAmountOut = amountIn;
        }

        _amm.swapExactAmountOut(
            _pairPath.length == 2 ? _pairPath[1] : _pairPath[0],
            tokenPath[0],
            firstSwapAmountOut,
            tokenPath[1],
            _tokenAmountOut,
            _to // send to recipient only for last swap
        );
    }

    /* getter methods */
    function getSpotPrice(
        IAMM _amm,
        uint256[] calldata _pairPath, // e.g. [0, 1] -> will swap on pair 0 then 1
        uint256[] calldata _tokenPath // e.g. [1, 0, 0, 1] -> will swap on pair 0 from token 1 to 0, then swap on pair 1 from token 0 to 1.
    ) external view override returns (uint256 spotPrice) {
        uint256 _pairPathMaxIndex = _pairPath.length;
        if (_pairPathMaxIndex == 0 || _pairPathMaxIndex > 2) {
            return spotPrice;
        }
        require(
            _tokenPath[0] != _tokenPath[1],
            "AMMRouterV1: invalid token path"
        );
        if (_pairPathMaxIndex == 2) {
            // only feasible path is 1 0 0 1
            require(
                _pairPath[0] != _pairPath[1] &&
                    _tokenPath[2] != _tokenPath[3] &&
                    _tokenPath[0] == _tokenPath[3] &&
                    _tokenPath[0] == 1,
                "AMMRouterV1: invalid path"
            );
        }

        spotPrice = UNIT;
        for (uint256 i; i < _pairPathMaxIndex; i++) {
            uint256 currentSpotPrice = _amm.getSpotPrice(
                _pairPath[i],
                _tokenPath[2 * i],
                _tokenPath[2 * i + 1]
            );
            spotPrice = spotPrice.mul(currentSpotPrice) / UNIT;
        }
        return spotPrice;
    }

    function _getAmountInWithoutGovernance(
        IAMM _amm,
        uint256[] memory _pairPath,
        uint256[] memory _tokenPath,
        uint256 _tokenAmountOut
    ) internal view returns (uint256 _currentTokenAmountInWithoutGovernance) {
        _currentTokenAmountInWithoutGovernance = _tokenAmountOut;
        uint256 _pairPathMaxIndex = _pairPath.length;
        require(
            _tokenPath[0] != _tokenPath[1],
            "AMMRouterV1: invalid token path"
        );
        if (_pairPathMaxIndex == 2) {
            // only feasible path is 1 0 0 1
            require(
                _pairPath[0] != _pairPath[1] &&
                    _tokenPath[2] != _tokenPath[3] &&
                    _tokenPath[0] == _tokenPath[3] &&
                    _tokenPath[0] == 1,
                "AMMRouterV1: invalid path"
            );
        }
        for (uint256 i = _pairPathMaxIndex; i > 0; i--) {
            (_currentTokenAmountInWithoutGovernance, ) = _amm
                .calcInAndSpotGivenOut(
                    _pairPath[i - 1],
                    _tokenPath[2 * i - 2],
                    MAX_UINT256,
                    _tokenPath[2 * i - 1],
                    _currentTokenAmountInWithoutGovernance
                );
        }
    }

    function getAmountIn(
        IAMM _amm,
        uint256[] memory _pairPath,
        uint256[] memory _tokenPath,
        uint256 _tokenAmountOut
    ) public view override returns (uint256 tokenAmountIn) {
        uint256 _currentTokenAmountIn = _getAmountInWithoutGovernance(
            _amm,
            _pairPath,
            _tokenPath,
            _tokenAmountOut
        );
        tokenAmountIn = _currentTokenAmountIn.mul(UNIT).div(
            UNIT - GOVERNANCE_FEE
        );
    }

    function getAmountOut(
        IAMM _amm,
        uint256[] calldata _pairPath,
        uint256[] calldata _tokenPath,
        uint256 _tokenAmountIn
    ) external view override returns (uint256 tokenAmountOut) {
        uint256 _currentTokenAmountOut = _tokenAmountIn;
        uint256 _pairPathMaxIndex = _pairPath.length;
        require(
            _tokenPath[0] != _tokenPath[1],
            "AMMRouterV1: invalid token path"
        );
        if (_pairPathMaxIndex == 2) {
            // only feasible path is 1 0 0 1
            require(
                _pairPath[0] != _pairPath[1] &&
                    _tokenPath[2] != _tokenPath[3] &&
                    _tokenPath[0] == _tokenPath[3] &&
                    _tokenPath[0] == 1,
                "AMMRouterV1: invalid path"
            );
        }
        for (uint256 i; i < _pairPathMaxIndex; i++) {
            (_currentTokenAmountOut, ) = _amm.calcOutAndSpotGivenIn(
                _pairPath[i],
                _tokenPath[2 * i],
                _currentTokenAmountOut,
                _tokenPath[2 * i + 1],
                0
            );
        }
        tokenAmountOut =
            _currentTokenAmountOut.mul(UNIT - GOVERNANCE_FEE) /
            UNIT;
    }

    /* Approval methods */
    function setRegistry(IAMMRegistry _registry) external {
        require(
            hasRole(ADMIN_ROLE, msg.sender),
            "AMMRouterV1: Caller is not an admin"
        );
        registry = _registry;
        emit RegistrySet(_registry);
    }

    function setGovernanceFee(uint256 _fee) external {
        require(
            hasRole(ADMIN_ROLE, msg.sender),
            "AMMRouterV1: Caller is not an admin"
        );
        require(_fee < UNIT, "AMMRouterV1: Invalid fee value");
        GOVERNANCE_FEE = _fee;
        emit GovernanceFeeUpdated(_fee);
    }

    function setReferral(address _recipient, uint256 _fee) external {
        require(
            hasRole(WHITELIST_ROLE, msg.sender),
            "AMMRouterV1: Caller cannot doesnt have whitelist role"
        );
        require(_fee <= UNIT, "AMMRouterV1: Invalid referral fee");
        if (_fee == 0) {
            delete REFERRAL_FEE[_recipient];
            referralAddresses.remove(_recipient);
            emit ReferralRecipientRemoved(_recipient);
        } else {
            if (referralAddresses.add(_recipient))
                emit ReferralRecipientAdded(_recipient);
            REFERRAL_FEE[_recipient] = _fee;
            emit ReferralSet(_recipient, _fee);
        }
    }

    function collectGovernanceFee(IERC20 _token, address _recipient) external {
        require(
            hasRole(ADMIN_ROLE, msg.sender),
            "AMMRouterV1: Caller is not an admin"
        );
        uint256 amount = _token.balanceOf(address(this));
        _token.safeTransfer(_recipient, amount);
        emit GovernanceFeeCollected(_token, amount, _recipient);
    }

    function updateFYTApprovalOf(IAMM _amm) external isValidAmm(address(_amm)) {
        IERC20 fyt = IERC20(_amm.getFYTAddress());
        fyt.safeIncreaseAllowance(
            address(_amm),
            MAX_UINT256.sub(fyt.allowance(address(this), address(_amm)))
        );
        emit TokenApproved(fyt, _amm);
    }

    function updateAllTokenApprovalOf(IAMM _amm)
        external
        isValidAmm(address(_amm))
    {
        IERC20 fyt = IERC20(_amm.getFYTAddress());
        IERC20 pt = IERC20(_amm.getPTAddress());
        IERC20 underlying = IERC20(_amm.getUnderlyingOfIBTAddress());
        fyt.safeIncreaseAllowance(
            address(_amm),
            MAX_UINT256.sub(fyt.allowance(address(this), address(_amm)))
        );
        pt.safeIncreaseAllowance(
            address(_amm),
            MAX_UINT256.sub(pt.allowance(address(this), address(_amm)))
        );
        underlying.safeIncreaseAllowance(
            address(_amm),
            MAX_UINT256.sub(underlying.allowance(address(this), address(_amm)))
        );
        emit TokenApproved(fyt, _amm);
        emit TokenApproved(pt, _amm);
        emit TokenApproved(underlying, _amm);
    }
}

File 2 of 13 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20Upgradeable.sol";
import "../../math/SafeMathUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";

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

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

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

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

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

    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

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

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

File 3 of 13 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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 EnumerableSetUpgradeable {
    // 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;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            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] = toDeleteIndex + 1; // All indexes are 1-based

            // 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) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

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

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


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

File 4 of 13 : IAMM.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.7.6;
pragma abicoder v2;

interface IAMM {
    /* Struct */
    struct Pair {
        address tokenAddress; // first is always PT
        uint256[2] weights;
        uint256[2] balances;
        bool liquidityIsInitialized;
    }

    /**
     * @notice finalize the initialization of the amm
     * @dev must be called during the first period the amm is supposed to be active
     */
    function finalize() external;

    /**
     * @notice switch period
     * @dev must be called after each new period switch
     * @dev the switch will auto renew part of the tokens and update the weights accordingly
     */
    function switchPeriod() external;

    /**
     * @notice toggle amm pause for pausing/resuming all user functionalities
     */
    function togglePauseAmm() external;

    /**
     * @notice Withdraw expired LP tokens
     */
    function withdrawExpiredToken(address _user, uint256 _lpTokenId) external;

    /**
     * @notice Getter for redeemable expired tokens info
     * @param _user the address of the user to check the redeemable tokens of
     * @param _lpTokenId the lp token id
     * @return the amount, the period id and the pair id of the expired tokens of the user
     */
    function getExpiredTokensInfo(address _user, uint256 _lpTokenId)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    function swapExactAmountIn(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _tokenAmountIn,
        uint256 _tokenOut,
        uint256 _minAmountOut,
        address _to
    ) external returns (uint256 tokenAmountOut, uint256 spotPriceAfter);

    function swapExactAmountOut(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _maxAmountIn,
        uint256 _tokenOut,
        uint256 _tokenAmountOut,
        address _to
    ) external returns (uint256 tokenAmountIn, uint256 spotPriceAfter);

    /**
     * @notice Create liquidity on the pair setting an initial price
     */
    function createLiquidity(uint256 _pairID, uint256[2] memory _tokenAmounts)
        external;

    function addLiquidity(
        uint256 _pairID,
        uint256 _poolAmountOut,
        uint256[2] memory _maxAmountsIn
    ) external;

    function removeLiquidity(
        uint256 _pairID,
        uint256 _poolAmountIn,
        uint256[2] memory _minAmountsOut
    ) external;

    function joinSwapExternAmountIn(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _tokenAmountIn,
        uint256 _minPoolAmountOut
    ) external returns (uint256 poolAmountOut);

    function joinSwapPoolAmountOut(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _poolAmountOut,
        uint256 _maxAmountIn
    ) external returns (uint256 tokenAmountIn);

    function exitSwapPoolAmountIn(
        uint256 _pairID,
        uint256 _tokenOut,
        uint256 _poolAmountIn,
        uint256 _minAmountOut
    ) external returns (uint256 tokenAmountOut);

    function exitSwapExternAmountOut(
        uint256 _pairID,
        uint256 _tokenOut,
        uint256 _tokenAmountOut,
        uint256 _maxPoolAmountIn
    ) external returns (uint256 poolAmountIn);

    function setSwappingFees(uint256 _swapFee) external;

    /* Getters */
    function calcOutAndSpotGivenIn(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _tokenAmountIn,
        uint256 _tokenOut,
        uint256 _minAmountOut
    ) external view returns (uint256 tokenAmountOut, uint256 spotPriceAfter);

    function calcInAndSpotGivenOut(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _maxAmountIn,
        uint256 _tokenOut,
        uint256 _tokenAmountOut
    ) external view returns (uint256 tokenAmountIn, uint256 spotPriceAfter);

    /**
     * @notice Getter for the spot price of a pair
     * @param _pairID the id of the pair
     * @param _tokenIn the id of the tokens sent
     * @param _tokenOut the id of the tokens received
     * @return the sport price of the pair
     */
    function getSpotPrice(
        uint256 _pairID,
        uint256 _tokenIn,
        uint256 _tokenOut
    ) external view returns (uint256);

    /**
     * @notice Getter for the address of the corresponding future vault
     * @return the address of the future vault
     */
    function getFutureAddress() external view returns (address);

    /**
     * @notice Getter for the pt address
     * @return the pt address
     */
    function getPTAddress() external view returns (address);

    /**
     * @notice Getter for the address of the underlying token of the ibt
     * @return the address of the underlying token of the ibt
     */
    function getUnderlyingOfIBTAddress() external view returns (address);

    /**
     * @notice Getter for the fyt address
     * @return the fyt address
     */
    function getFYTAddress() external view returns (address);

    /**
     * @notice Getter for the PT weight in the first pair (0)
     * @return the weight of the pt
     */
    function getPTWeightInPair() external view returns (uint256);

    function getPairWithID(uint256 _pairID) external view returns (Pair memory);

    function getLPTokenId(
        uint256 _ammId,
        uint256 _periodIndex,
        uint256 _pairID
    ) external pure returns (uint256);

    function ammId() external returns (uint64);
}

File 5 of 13 : IAMMRouterV1.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.7.6;
import "./IAMM.sol";

/**
 * IAMMRouter is an on-chain router designed to batch swaps for the APWine AMM.
 * It can be used to facilitate swaps and save gas fees as opposed to executing multiple transactions.
 * Example: swap from pair 0 to pair 1, from token 0 to token 1 then token 1 to token 0.
 * One practical use-case would be swapping from FYT to underlying, which would otherwise not be possible natively.
 */
interface IAMMRouterV1 {
    /**
     * @dev execute a swapExactAmountIn given pair and token paths. Works just like the regular swapExactAmountIn from AMM.
     *
     * @param _amm the address of the AMM instance to execute the swap on
     * @param _pairPath a list of N pair indices, where N is the number of swaps to execute
     * @param _tokenPath a list of 2 * N token indices corresponding to the swaps path. For swap I, tokenIn = 2*I, tokenOut = 2*I + 1
     * @param _tokenAmountIn the exact input token amount
     * @param _minAmountOut the minimum amount of output tokens to receive, call will revert if not reached
     * @param _to the recipient address
     * @param _deadline the absolute deadline, in seconds, to prevent outdated swaps from being executed
     * @param _referralRecipient the recipient address for the referral
     */
    function swapExactAmountIn(
        IAMM _amm,
        uint256[] calldata _pairPath,
        uint256[] calldata _tokenPath,
        uint256 _tokenAmountIn,
        uint256 _minAmountOut,
        address _to,
        uint256 _deadline,
        address _referralRecipient
    ) external returns (uint256 tokenAmountOut);

    /**
     * @dev execute a swapExactAmountOut given pair and token paths. Works just like the regular swapExactAmountOut from AMM.
     *
     * @param _amm the address of the AMM instance to execute the swap on
     * @param _pairPath a list of N pair indices, where N is the number of swaps to execute
     * @param _tokenPath a list of 2 * N token indices corresponding to the swaps path. For swap I, tokenIn = 2*I, tokenOut = 2*I + 1
     * @param _maxAmountIn the maximum amount of input tokens needed to send, call will revert if not reached
     * @param _tokenAmountOut the exact out token amount
     * @param _to the recipient address
     * @param _deadline the absolute deadline, in seconds, to prevent outdated swaps from being executed
     * @param _referralRecipient the recipient address for the referral
     */
    function swapExactAmountOut(
        IAMM _amm,
        uint256[] calldata _pairPath,
        uint256[] calldata _tokenPath,
        uint256 _maxAmountIn,
        uint256 _tokenAmountOut,
        address _to,
        uint256 _deadline,
        address _referralRecipient
    ) external returns (uint256 tokenAmountIn);

    /**
     * @dev execute a getSpotPrice given pair and token paths. Works just like the regular getSpotPrice from AMM.
     *
     * @param _amm the address of the AMM instance to execute the spotPrice on
     * @param _pairPath a list of N pair indices, where N is the number of getSpotPrice to execute
     * @param _tokenPath a list of 2 * N token indices corresponding to the getSpotPrice path. For getSpotPrice I, tokenIn = 2*I, tokenOut = 2*I + 1
     */
    function getSpotPrice(
        IAMM _amm,
        uint256[] calldata _pairPath,
        uint256[] calldata _tokenPath
    ) external returns (uint256 spotPrice);

    /**
     * @dev execute a getAmountIn given pair and token paths. Works just like the regular calcInAndSpotGivenOut from AMM.
     *
     * @param _amm the address of the AMM instance to execute the getAmountIn on
     * @param _pairPath a list of N pair indices, where N is the number of getAmountIn to execute
     * @param _tokenPath a list of 2 * N token indices corresponding to the getAmountIn path. For getAmountIn I, tokenIn = 2*I, tokenOut = 2*I + 1
     * @param _tokenAmountOut the exact out token amount
     */
    function getAmountIn(
        IAMM _amm,
        uint256[] calldata _pairPath,
        uint256[] calldata _tokenPath,
        uint256 _tokenAmountOut
    ) external returns (uint256 tokenAmountIn);

    /**
     * @dev execute a getAmountOut given pair and token paths. Works just like the regular calcInAndSpotGivenOut from AMM.
     *
     * @param _amm the address of the AMM instance to execute the getAmountOut on
     * @param _pairPath a list of N pair indices, where N is the number of getAmountOut to execute
     * @param _tokenPath a list of 2 * N token indices corresponding to the getAmountOut path. For getAmountOut I, tokenIn = 2*I, tokenOut = 2*I + 1
     * @param _tokenAmountIn the exact input token amount
     */
    function getAmountOut(
        IAMM _amm,
        uint256[] calldata _pairPath,
        uint256[] calldata _tokenPath,
        uint256 _tokenAmountIn
    ) external returns (uint256 tokenAmountOut);
}

File 6 of 13 : IAMMRegistry.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

/**
 * @title AMM Registry interface
 * @notice Keeps a record of all Future / Pool pairs
 */
interface IAMMRegistry {
    /**
     * @notice Initializer of the contract
     * @param _admin the address of the admin of the contract
     */
    function initialize(address _admin) external;

    /* Setters */

    /**
     * @notice Setter for the AMM pools
     * @param _futureVaultAddress the future vault address
     * @param _ammPool the AMM pool address
     */
    function setAMMPoolByFuture(address _futureVaultAddress, address _ammPool)
        external;

    /**
     * @notice Register the AMM pools
     * @param _ammPool the AMM pool address
     */
    function setAMMPool(address _ammPool) external;

    /**
     * @notice Remove an AMM Pool from the registry
     * @param _ammPool the address of the pool to remove from the registry
     */
    function removeAMMPool(address _ammPool) external;

    /* Getters */
    /**
     * @notice Getter for the controller address
     * @return the address of the controller
     */
    function getFutureAMMPool(address _futureVaultAddress)
        external
        view
        returns (address);

    function isRegisteredAMM(address _ammAddress) external view returns (bool);
}

File 7 of 13 : IERC20.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.7.6;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";

interface IERC20 is IERC20Upgradeable {
    /**
     * @dev Returns the name of the token.
     */
    function name() external returns (string memory);

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() external returns (string memory);

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

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

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue)
        external
        returns (bool);
}

File 8 of 13 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/EnumerableSetUpgradeable.sol";
import "../utils/AddressUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms.
 *
 * 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 AccessControlUpgradeable is Initializable, ContextUpgradeable {
    function __AccessControl_init() internal initializer {
        __Context_init_unchained();
        __AccessControl_init_unchained();
    }

    function __AccessControl_init_unchained() internal initializer {
    }
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
    using AddressUpgradeable for address;

    struct RoleData {
        EnumerableSetUpgradeable.AddressSet members;
        bytes32 adminRole;
    }

    mapping (bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

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

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

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

    /**
     * @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 returns (uint256) {
        return _roles[role].members.length();
    }

    /**
     * @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 returns (address) {
        return _roles[role].members.at(index);
    }

    /**
     * @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 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 {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");

        _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 {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");

        _revokeRole(role, account);
    }

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

        _revokeRole(role, account);
    }

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

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

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

    function _revokeRole(bytes32 role, address account) private {
        if (_roles[role].members.remove(account)) {
            emit RoleRevoked(role, account, _msgSender());
        }
    }
    uint256[49] private __gap;
}

File 9 of 13 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

File 10 of 13 : SafeMathUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMathUpgradeable {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

File 11 of 13 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 12 of 13 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
import "../proxy/Initializable.sol";

/*
 * @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 GSN 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 ContextUpgradeable is Initializable {
    function __Context_init() internal initializer {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal initializer {
    }
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

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

File 13 of 13 : Initializable.sol
// SPDX-License-Identifier: MIT

// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;

import "../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {

    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /// @dev Returns true if and only if the function is running in the constructor
    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_recipient","type":"address"}],"name":"GovernanceFeeCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"GovernanceFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"_feeAmount","type":"uint256"}],"name":"ReferralFeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_recipient","type":"address"}],"name":"ReferralRecipientAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_recipient","type":"address"}],"name":"ReferralRecipientRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"ReferralSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAMMRegistry","name":"_registry","type":"address"}],"name":"RegistrySet","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":false,"internalType":"contract IERC20","name":"_token","type":"address"},{"indexed":false,"internalType":"contract IAMM","name":"_amm","type":"address"}],"name":"TokenApproved","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GOVERNANCE_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"REFERRAL_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"collectGovernanceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAMM","name":"_amm","type":"address"},{"internalType":"uint256[]","name":"_pairPath","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenPath","type":"uint256[]"},{"internalType":"uint256","name":"_tokenAmountOut","type":"uint256"}],"name":"getAmountIn","outputs":[{"internalType":"uint256","name":"tokenAmountIn","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IAMM","name":"_amm","type":"address"},{"internalType":"uint256[]","name":"_pairPath","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenPath","type":"uint256[]"},{"internalType":"uint256","name":"_tokenAmountIn","type":"uint256"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"tokenAmountOut","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 IAMM","name":"_amm","type":"address"},{"internalType":"uint256[]","name":"_pairPath","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenPath","type":"uint256[]"}],"name":"getSpotPrice","outputs":[{"internalType":"uint256","name":"spotPrice","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 IAMMRegistry","name":"_registry","type":"address"},{"internalType":"address","name":"_admin","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract IAMMRegistry","name":"","type":"address"}],"stateMutability":"view","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":"_fee","type":"uint256"}],"name":"setGovernanceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setReferral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAMMRegistry","name":"_registry","type":"address"}],"name":"setRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAMM","name":"_amm","type":"address"},{"internalType":"uint256[]","name":"_pairPath","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenPath","type":"uint256[]"},{"internalType":"uint256","name":"_tokenAmountIn","type":"uint256"},{"internalType":"uint256","name":"_minAmountOut","type":"uint256"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"address","name":"_referralRecipient","type":"address"}],"name":"swapExactAmountIn","outputs":[{"internalType":"uint256","name":"tokenAmountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAMM","name":"_amm","type":"address"},{"internalType":"uint256[]","name":"_pairPath","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenPath","type":"uint256[]"},{"internalType":"uint256","name":"_maxAmountIn","type":"uint256"},{"internalType":"uint256","name":"_tokenAmountOut","type":"uint256"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"address","name":"_referralRecipient","type":"address"}],"name":"swapExactAmountOut","outputs":[{"internalType":"uint256","name":"tokenAmountIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAMM","name":"_amm","type":"address"}],"name":"updateAllTokenApprovalOf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAMM","name":"_amm","type":"address"}],"name":"updateFYTApprovalOf","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50613648806100206000396000f3fe608060405234801561001057600080fd5b506004361061018d5760003560e01c806391d14854116100e3578063bc408aac1161008c578063e719808d11610066578063e719808d1461031f578063e7baf24814610332578063e7ffb5f7146103455761018d565b8063bc408aac146102e6578063ca15c873146102f9578063d547741f1461030c5761018d565b8063a91ee0dc116100bd578063a91ee0dc146102ad578063aa8b9c8d146102c0578063ae5e6406146102d35761018d565b806391d148541461027d578063a217fddf1461029d578063a4fbeec3146102a55761018d565b806336568abe116101455780637b1039991161011f5780637b1039991461024257806380eb114a146102575780639010d07c1461026a5761018d565b806336568abe14610209578063485cc9551461021c57806374994e351461022f5761018d565b80632d067a3e116101765780632d067a3e146101ce5780632f2ff15d146101e357806332a69330146101f65761018d565b806316dc3ace14610192578063248a9ca3146101bb575b600080fd5b6101a56101a0366004612e36565b610358565b6040516101b2919061307b565b60405180910390f35b6101a56101c9366004612c99565b610616565b6101e16101dc366004612c1c565b61062e565b005b6101e16101f1366004612cb1565b61081c565b6101e1610204366004612c99565b610883565b6101e1610217366004612cb1565b610930565b6101e161022a366004612d01565b610991565b6101e161023d366004612c1c565b610aa0565b61024a610e0e565b6040516101b29190613029565b6101e1610265366004612d01565b610e1d565b61024a610278366004612ce0565b610f44565b61029061028b366004612cb1565b610f65565b6040516101b29190613070565b6101a5610f7d565b6101a5610f82565b6101e16102bb366004612c1c565b610f88565b6101a56102ce366004612d2e565b611026565b6101e16102e1366004612c54565b611263565b6101a56102f4366004612dae565b6113d8565b6101a5610307366004612c99565b61160a565b6101e161031a366004612cb1565b611621565b6101a561032d366004612ef9565b61167a565b6101a5610340366004612c1c565b6116c6565b6101a5610353366004612e36565b6116d8565b600082428110156103845760405162461bcd60e51b815260040161037b906132af565b60405180910390fd5b8888600181811061039157fe5b90506020020135898960008181106103a557fe5b9050602002013514156103ca5760405162461bcd60e51b815260040161037b9061321b565b89600281118015906103dc5750600081115b6103f85760405162461bcd60e51b815260040161037b90613161565b80600214156104c9578b8b600181811061040e57fe5b905060200201358c8c600081811061042257fe5b905060200201351415801561045d57508989600381811061043f57fe5b905060200201358a8a600281811061045357fe5b9050602002013514155b801561048e57508989600381811061047157fe5b905060200201358a8a600081811061048557fe5b90506020020135145b80156104ad5750898960008181106104a257fe5b905060200201356001145b6104c95760405162461bcd60e51b815260040161037b9061340a565b600061054c8e8e8e80806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050508d8d808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508e9250611a27915050565b905061055f8e8e8e8e8e868b6001611c39565b50888111156105805760405162461bcd60e51b815260040161037b90613104565b6106048e8e8e80806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050508d8d808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508792508e91508d9050611e2c565b9e9d5050505050505050505050505050565b6000818152603360205260409020600201545b919050565b606554604051634d271a5d60e11b815282916001600160a01b031690639a4e34ba9061065e908490600401613029565b60206040518083038186803b15801561067657600080fd5b505afa15801561068a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ae9190612c7f565b6106ca5760405162461bcd60e51b815260040161037b906133a0565b6000826001600160a01b0316638cd8854f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561070557600080fd5b505afa158015610719573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073d9190612c38565b90506107de836107cd836001600160a01b031663dd62ed3e30886040518363ffffffff1660e01b815260040161077492919061303d565b60206040518083038186803b15801561078c57600080fd5b505afa1580156107a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107c49190612fee565b60001990612138565b6001600160a01b0384169190612195565b7f95ac6a9243eb257624256f38389a079659c62030e9153331cd38ef4ed8bfa00e818460405161080f92919061303d565b60405180910390a1505050565b60008281526033602052604090206002015461083a9061028b61229f565b6108755760405162461bcd60e51b815260040180806020018281038252602f8152602001806134e6602f913960400191505060405180910390fd5b61087f82826122a3565b5050565b6108ad7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177533610f65565b6108c95760405162461bcd60e51b815260040161037b90613252565b670de0b6b3a764000081106108f05760405162461bcd60e51b815260040161037b90613369565b60668190556040517f78ec98f839c83f9772deb71634aae776280186c92df2a27e1de8dee2053ba5999061092590839061307b565b60405180910390a150565b61093861229f565b6001600160a01b0316816001600160a01b0316146109875760405162461bcd60e51b815260040180806020018281038252602f8152602001806135e4602f913960400191505060405180910390fd5b61087f828261230c565b600054610100900460ff16806109aa57506109aa612375565b806109b8575060005460ff16155b6109f35760405162461bcd60e51b815260040180806020018281038252602e81526020018061356b602e913960400191505060405180910390fd5b600054610100900460ff16158015610a1e576000805460ff1961ff0019909116610100171660011790555b610a29600083610875565b6065805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0385161790556040517f27fe5f0c1c3b1ed427cc63d0f05759ffdecf9aec9e18d31ef366fc8a6cb5dc3b90610a81908590613029565b60405180910390a18015610a9b576000805461ff00191690555b505050565b606554604051634d271a5d60e11b815282916001600160a01b031690639a4e34ba90610ad0908490600401613029565b60206040518083038186803b158015610ae857600080fd5b505afa158015610afc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b209190612c7f565b610b3c5760405162461bcd60e51b815260040161037b906133a0565b6000826001600160a01b0316638cd8854f6040518163ffffffff1660e01b815260040160206040518083038186803b158015610b7757600080fd5b505afa158015610b8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610baf9190612c38565b90506000836001600160a01b0316631e5f74a16040518163ffffffff1660e01b815260040160206040518083038186803b158015610bec57600080fd5b505afa158015610c00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c249190612c38565b90506000846001600160a01b031663c6ec27bf6040518163ffffffff1660e01b815260040160206040518083038186803b158015610c6157600080fd5b505afa158015610c75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c999190612c38565b9050610ce185610cd0856001600160a01b031663dd62ed3e308a6040518363ffffffff1660e01b815260040161077492919061303d565b6001600160a01b0386169190612195565b610d2785610d16846001600160a01b031663dd62ed3e308a6040518363ffffffff1660e01b815260040161077492919061303d565b6001600160a01b0385169190612195565b610d5c856107cd836001600160a01b031663dd62ed3e308a6040518363ffffffff1660e01b815260040161077492919061303d565b7f95ac6a9243eb257624256f38389a079659c62030e9153331cd38ef4ed8bfa00e8386604051610d8d92919061303d565b60405180910390a17f95ac6a9243eb257624256f38389a079659c62030e9153331cd38ef4ed8bfa00e8286604051610dc692919061303d565b60405180910390a17f95ac6a9243eb257624256f38389a079659c62030e9153331cd38ef4ed8bfa00e8186604051610dff92919061303d565b60405180910390a15050505050565b6065546001600160a01b031681565b610e477fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177533610f65565b610e635760405162461bcd60e51b815260040161037b90613252565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526000906001600160a01b038416906370a0823190610eab903090600401613029565b60206040518083038186803b158015610ec357600080fd5b505afa158015610ed7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610efb9190612fee565b9050610f116001600160a01b0384168383612386565b7fe89003d4ba1203f4d3ad24366748d97b0eb217e67479bdc9f02661b27c284e9f83828460405161080f93929190613084565b6000828152603360205260408120610f5c90836123f1565b90505b92915050565b6000828152603360205260408120610f5c90836123fd565b600081565b60665481565b610fb27fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177533610f65565b610fce5760405162461bcd60e51b815260040161037b90613252565b6065805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0383161790556040517f27fe5f0c1c3b1ed427cc63d0f05759ffdecf9aec9e18d31ef366fc8a6cb5dc3b90610925908390613029565b6000838015806110365750600281115b15611041575061125a565b8383600181811061104e57fe5b905060200201358484600081811061106257fe5b9050602002013514156110875760405162461bcd60e51b815260040161037b9061321b565b8060021415611158578585600181811061109d57fe5b90506020020135868660008181106110b157fe5b90506020020135141580156110ec5750838360038181106110ce57fe5b90506020020135848460028181106110e257fe5b9050602002013514155b801561111d57508383600381811061110057fe5b905060200201358484600081811061111457fe5b90506020020135145b801561113c57508383600081811061113157fe5b905060200201356001145b6111585760405162461bcd60e51b815260040161037b9061340a565b670de0b6b3a7640000915060005b81811015611257576000886001600160a01b0316637cfee94689898581811061118b57fe5b905060200201358888866002028181106111a157fe5b905060200201358989876002026001018181106111ba57fe5b905060200201356040518463ffffffff1660e01b81526004016111df93929190613441565b60206040518083038186803b1580156111f757600080fd5b505afa15801561120b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122f9190612fee565b9050670de0b6b3a76400006112448583612412565b8161124b57fe5b04935050600101611166565b50505b95945050505050565b61128d7fdc72ed553f2544c34465af23b847953efeb813428162d767f9ba5f4013be676033610f65565b6112a95760405162461bcd60e51b815260040161037b906131be565b670de0b6b3a76400008111156112d15760405162461bcd60e51b815260040161037b906130a7565b80611337576001600160a01b0382166000908152606760205260408120556112fa60688361246b565b507f9e56f2b5b210b425856e84c08dcc4ab9057c542f0f45b995351ee95da6ba01af8260405161132a9190613029565b60405180910390a161087f565b611342606883612480565b1561137f577fcd5840c854e8e8db2f54e73f3bed4ac3b8ae9101db5728ae45d8d2739e6d8694826040516113769190613029565b60405180910390a15b6001600160a01b03821660009081526067602052604090819020829055517fc4e26aa6be6770b94168bf3bbb8f7e13da5619433246feb7fdd847838e4f30b1906113cc9084908490613057565b60405180910390a15050565b60008185858560018181106113e957fe5b90506020020135868660008181106113fd57fe5b9050602002013514156114225760405162461bcd60e51b815260040161037b9061321b565b80600214156114f3578787600181811061143857fe5b905060200201358888600081811061144c57fe5b905060200201351415801561148757508585600381811061146957fe5b905060200201358686600281811061147d57fe5b9050602002013514155b80156114b857508585600381811061149b57fe5b90506020020135868660008181106114af57fe5b90506020020135145b80156114d75750858560008181106114cc57fe5b905060200201356001145b6114f35760405162461bcd60e51b815260040161037b9061340a565b60005b818110156115cc57896001600160a01b031663e01299a28a8a8481811061151957fe5b9050602002013589898560020281811061152f57fe5b90506020020135868b8b8760020260010181811061154957fe5b9050602002013560006040518663ffffffff1660e01b8152600401611572959493929190613457565b604080518083038186803b15801561158957600080fd5b505afa15801561159d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115c19190613006565b5092506001016114f6565b50670de0b6b3a76400006115f5606654670de0b6b3a7640000038461241290919063ffffffff16565b816115fc57fe5b049998505050505050505050565b6000818152603360205260408120610f5f90612495565b60008281526033602052604090206002015461163f9061028b61229f565b6109875760405162461bcd60e51b815260040180806020018281038252603081526020018061353b6030913960400191505060405180910390fd5b60008061168986868686611a27565b90506116bc606654670de0b6b3a7640000036116b6670de0b6b3a76400008461241290919063ffffffff16565b906124a0565b9695505050505050565b60676020526000908152604090205481565b600082428110156116fb5760405162461bcd60e51b815260040161037b906132af565b8888600181811061170857fe5b905060200201358989600081811061171c57fe5b9050602002013514156117415760405162461bcd60e51b815260040161037b9061321b565b60006117548d8d8d8d8d8d8a6000611c39565b90508a600281118015906117685750600081115b6117845760405162461bcd60e51b815260040161037b906133d5565b8060021415611855578c8c600181811061179a57fe5b905060200201358d8d60008181106117ae57fe5b90506020020135141580156117e957508a8a60038181106117cb57fe5b905060200201358b8b60028181106117df57fe5b9050602002013514155b801561181a57508a8a60038181106117fd57fe5b905060200201358b8b600081811061181157fe5b90506020020135145b801561183957508a8a600081811061182e57fe5b905060200201356001145b6118555760405162461bcd60e51b815260040161037b9061340a565b8d6001600160a01b0316635dde4ba68e8e600081811061187157fe5b905060200201358d8d600081811061188557fe5b90506020020135858f8f600181811061189a57fe5b905060200201356000876001146118b157306118b3565b8d5b6040518763ffffffff1660e01b81526004016118d49695949392919061347a565b6040805180830381600087803b1580156118ed57600080fd5b505af1158015611901573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119259190613006565b50915060028114156119f6578d6001600160a01b0316635dde4ba68e8e600181811061194d57fe5b905060200201358d8d600281811061196157fe5b90506020020135858f8f600381811061197657fe5b9050602002013560008d6040518763ffffffff1660e01b81526004016119a19695949392919061347a565b6040805180830381600087803b1580156119ba57600080fd5b505af11580156119ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119f29190613006565b5091505b87821015611a165760405162461bcd60e51b815260040161037b9061330c565b509c9b505050505050505050505050565b8251825182919084906001908110611a3b57fe5b602002602001015184600081518110611a5057fe5b60200260200101511415611a765760405162461bcd60e51b815260040161037b9061321b565b8060021415611b4e5784600181518110611a8c57fe5b602002602001015185600081518110611aa157fe5b602002602001015114158015611adf575083600381518110611abf57fe5b602002602001015184600281518110611ad457fe5b602002602001015114155b8015611b12575083600381518110611af357fe5b602002602001015184600081518110611b0857fe5b6020026020010151145b8015611b32575083600081518110611b2657fe5b60200260200101516001145b611b4e5760405162461bcd60e51b815260040161037b9061340a565b805b8015611c2f57866001600160a01b031663814cf2d5876001840381518110611b7457fe5b6020026020010151876002856002020381518110611b8e57fe5b6020026020010151600019896001876002020381518110611bab57fe5b6020026020010151886040518663ffffffff1660e01b8152600401611bd4959493929190613457565b604080518083038186803b158015611beb57600080fd5b505afa158015611bff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c239190613006565b50925060001901611b50565b5050949350505050565b60008060008088886000818110611c4c57fe5b90506020020135600014611cef578b6001600160a01b031663d3866ae68c8c6000818110611c7657fe5b905060200201356040518263ffffffff1660e01b8152600401611c99919061307b565b60c06040518083038186803b158015611cb157600080fd5b505afa158015611cc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce99190612f74565b51611d60565b8b6001600160a01b0316631e5f74a16040518163ffffffff1660e01b815260040160206040518083038186803b158015611d2857600080fd5b505afa158015611d3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d609190612c38565b9050611d6c8786612507565b91955093509150611d886001600160a01b03821633308561259c565b6001600160a01b0386166000908152606760205260409020548015611e1c576000670de0b6b3a7640000611dbc8684612412565b81611dc357fe5b0490508015611e1a57611de06001600160a01b0384168983612386565b7f339143a0e6309caafa5c4c55cd7b75d2e49115ce1e88b394e3376814b8507c158882604051611e11929190613057565b60405180910390a15b505b5050505098975050505050505050565b604080516001808252818301909252600091829190602080830190803683375050604080516002808252606082018352939450600093909250906020830190803683370190505090506000885160021415611fe45788600181518110611e8e57fe5b602002602001015183600081518110611ea357fe5b60200260200101818152505087600281518110611ebc57fe5b602002602001015182600081518110611ed157fe5b60200260200101818152505087600381518110611eea57fe5b602002602001015182600181518110611eff57fe5b602002602001018181525050611f178a848489611a27565b9050896001600160a01b03166325efb3df8a600081518110611f3557fe5b60200260200101518a600081518110611f4a57fe5b60200260200101518a8c600181518110611f6057fe5b602002602001015186306040518763ffffffff1660e01b8152600401611f8b9695949392919061347a565b6040805180830381600087803b158015611fa457600080fd5b505af1158015611fb8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fdc9190613006565b509350612042565b87600081518110611ff157fe5b60200260200101518260008151811061200657fe5b6020026020010181815250508760018151811061201f57fe5b60200260200101518260018151811061203457fe5b602090810291909101015250855b896001600160a01b03166325efb3df8a51600214612074578a60008151811061206757fe5b602002602001015161208a565b8a60018151811061208157fe5b60200260200101515b8460008151811061209757fe5b602002602001015184866001815181106120ad57fe5b60200260200101518b8b6040518763ffffffff1660e01b81526004016120d89695949392919061347a565b6040805180830381600087803b1580156120f157600080fd5b505af1158015612105573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121299190613006565b50505050509695505050505050565b60008282111561218f576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600061222b82856001600160a01b031663dd62ed3e30876040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b031681526020019250505060206040518083038186803b1580156121f957600080fd5b505afa15801561220d573d6000803e3d6000fd5b505050506040513d602081101561222357600080fd5b50519061260f565b604080516001600160a01b038616602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b03167f095ea7b300000000000000000000000000000000000000000000000000000000179052909150612299908590612669565b50505050565b3390565b60008281526033602052604090206122bb9082612480565b1561087f576122c861229f565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152603360205260409020612324908261246b565b1561087f5761233161229f565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60006123803061271a565b15905090565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b03167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610a9b908490612669565b6000610f5c8383612720565b6000610f5c836001600160a01b038416612784565b60008261242157506000610f5f565b8282028284828161242e57fe5b0414610f5c5760405162461bcd60e51b81526004018080602001828103825260218152602001806135996021913960400191505060405180910390fd5b6000610f5c836001600160a01b03841661279c565b6000610f5c836001600160a01b038416612862565b6000610f5f826128ac565b60008082116124f6576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816124ff57fe5b049392505050565b600080600083156125535761253d606654670de0b6b3a7640000036116b6670de0b6b3a76400008861241290919063ffffffff16565b92506125498386612138565b9150829050612595565b670de0b6b3a764000061257b606654670de0b6b3a7640000038761241290919063ffffffff16565b8161258257fe5b04925061258f8584612138565b91508490505b9250925092565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03167f23b872dd00000000000000000000000000000000000000000000000000000000179052612299908590612669565b600082820183811015610f5c576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60006126be826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166128b09092919063ffffffff16565b805190915015610a9b578080602001905160208110156126dd57600080fd5b5051610a9b5760405162461bcd60e51b815260040180806020018281038252602a8152602001806135ba602a913960400191505060405180910390fd5b3b151590565b815460009082106127625760405162461bcd60e51b81526004018080602001828103825260228152602001806134c46022913960400191505060405180910390fd5b82600001828154811061277157fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b6000818152600183016020526040812054801561285857835460001980830191908101906000908790839081106127cf57fe5b90600052602060002001549050808760000184815481106127ec57fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061281c57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610f5f565b6000915050610f5f565b600061286e8383612784565b6128a457508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610f5f565b506000610f5f565b5490565b60606128bf84846000856128c9565b90505b9392505050565b60608247101561290a5760405162461bcd60e51b81526004018080602001828103825260268152602001806135156026913960400191505060405180910390fd5b6129138561271a565b612964576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106129a25780518252601f199092019160209182019101612983565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114612a04576040519150601f19603f3d011682016040523d82523d6000602084013e612a09565b606091505b5091509150612a19828286612a24565b979650505050505050565b60608315612a335750816128c2565b825115612a435782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612a8d578181015183820152602001612a75565b50505050905090810190601f168015612aba5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b600082601f830112612ad8578081fd5b6040516040810181811067ffffffffffffffff82111715612af557fe5b8060405250808385604086011115612b0b578384fd5b835b6002811015612b2c578151835260209283019290910190600101612b0d565b509195945050505050565b60008083601f840112612b48578182fd5b50813567ffffffffffffffff811115612b5f578182fd5b6020830191508360208083028501011115612b7957600080fd5b9250929050565b600082601f830112612b90578081fd5b8135602067ffffffffffffffff80831115612ba757fe5b81830260405183828201018181108482111715612bc057fe5b60405284815283810192508684018288018501891015612bde578687fd5b8692505b85831015612c00578035845292840192600192909201918401612be2565b50979650505050505050565b8051801515811461062957600080fd5b600060208284031215612c2d578081fd5b8135610f5c816134ab565b600060208284031215612c49578081fd5b8151610f5c816134ab565b60008060408385031215612c66578081fd5b8235612c71816134ab565b946020939093013593505050565b600060208284031215612c90578081fd5b610f5c82612c0c565b600060208284031215612caa578081fd5b5035919050565b60008060408385031215612cc3578182fd5b823591506020830135612cd5816134ab565b809150509250929050565b60008060408385031215612cf2578182fd5b50508035926020909101359150565b60008060408385031215612d13578182fd5b8235612d1e816134ab565b91506020830135612cd5816134ab565b600080600080600060608688031215612d45578081fd5b8535612d50816134ab565b9450602086013567ffffffffffffffff80821115612d6c578283fd5b612d7889838a01612b37565b90965094506040880135915080821115612d90578283fd5b50612d9d88828901612b37565b969995985093965092949392505050565b60008060008060008060808789031215612dc6578384fd5b8635612dd1816134ab565b9550602087013567ffffffffffffffff80821115612ded578586fd5b612df98a838b01612b37565b90975095506040890135915080821115612e11578283fd5b50612e1e89828a01612b37565b979a9699509497949695606090950135949350505050565b6000806000806000806000806000806101008b8d031215612e55578788fd5b8a35612e60816134ab565b995060208b013567ffffffffffffffff80821115612e7c57898afd5b612e888e838f01612b37565b909b50995060408d0135915080821115612ea0578586fd5b50612ead8d828e01612b37565b90985096505060608b0135945060808b0135935060a08b0135612ecf816134ab565b925060c08b0135915060e08b0135612ee6816134ab565b809150509295989b9194979a5092959850565b60008060008060808587031215612f0e578182fd5b8435612f19816134ab565b9350602085013567ffffffffffffffff80821115612f35578384fd5b612f4188838901612b80565b94506040870135915080821115612f56578384fd5b50612f6387828801612b80565b949793965093946060013593505050565b600060c08284031215612f85578081fd5b6040516080810181811067ffffffffffffffff82111715612fa257fe5b6040528251612fb0816134ab565b8152612fbf8460208501612ac8565b6020820152612fd18460608501612ac8565b6040820152612fe260a08401612c0c565b60608201529392505050565b600060208284031215612fff578081fd5b5051919050565b60008060408385031215613018578182fd5b505080516020909101519092909150565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b90815260200190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b60208082526021908201527f414d4d526f7574657256313a20496e76616c696420726566657272616c20666560408201527f6500000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526022908201527f414d4d526f7574657256313a204d617820616d6f756e7420696e20726561636860408201527f6564000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526032908201527f414d4d526f75746572737761704578616374416d6f756e744f757456313a206960408201527f6e76616c69642070617468206c656e6774680000000000000000000000000000606082015260800190565b60208082526035908201527f414d4d526f7574657256313a2043616c6c65722063616e6e6f7420646f65736e60408201527f7420686176652077686974656c69737420726f6c650000000000000000000000606082015260800190565b6020808252601f908201527f414d4d526f7574657256313a20696e76616c696420746f6b656e207061746800604082015260600190565b60208082526023908201527f414d4d526f7574657256313a2043616c6c6572206973206e6f7420616e20616460408201527f6d696e0000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526021908201527f414d4d526f7574657256313a20446561646c696e65206861732065787069726560408201527f6400000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526023908201527f414d4d526f7574657256313a204d696e20616d6f756e74206e6f74207265616360408201527f6865640000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252601e908201527f414d4d526f7574657256313a20496e76616c6964206665652076616c75650000604082015260600190565b6020808252818101527f414d4d526f7574657256313a20696e76616c696420616d6d2061646472657373604082015260600190565b6020808252818101527f414d4d526f7574657256313a20696e76616c69642070617468206c656e677468604082015260600190565b60208082526019908201527f414d4d526f7574657256313a20696e76616c6964207061746800000000000000604082015260600190565b9283526020830191909152604082015260600190565b948552602085019390935260408401919091526060830152608082015260a00190565b95865260208601949094526040850192909252606084015260808301526001600160a01b031660a082015260c00190565b6001600160a01b03811681146134c057600080fd5b5056fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e74416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b65496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a26469706673582212207758c01b3f9fcd5bb1d046548f779a194f44daed2fc2f261bdfa62c729011ae164736f6c63430007060033

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