Contract 0x2Baac806CB2b7A07f8f73DB1329767E5a3CbDF4e

 
Txn Hash
Block
From
To
Value [Txn Fee]
0xfa67109b7800832ead79260289e38519e755dc39ab8a71b624acb50e5e03d47d2259032021-08-28 10:40:2020 days 7 hrs ago0x904b5993fc92979eeedc19ccc58bed6b7216667c IN  Contract Creation0 ETH0.14339074784 ETH
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
LpGovernor

Compiler Version
v0.7.4+commit.3f05b770

Optimization Enabled:
Yes with 1000 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 23 : LpGovernor.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts-upgradeable/GSN/ContextUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";

import "./GovernorAlpha.sol";
import "./RewardDistribution.sol";
import "../interface/IGovernor.sol";

contract LpGovernor is
    IGovernor,
    Initializable,
    ContextUpgradeable,
    ERC20Upgradeable,
    GovernorAlpha,
    RewardDistribution
{
    // admin:  to mint/burn token
    address internal _minter;

    /**
     * @notice  Initialize LpGovernor instance.
     *
     * @param   name        ERC20 name of token.
     * @param   symbol      ERC20 symbol of token.
     * @param   minter      The role that has privilege to mint / burn token.
     * @param   target      The target of execution, all action of proposal will be send to target.
     * @param   rewardToken The ERC20 token used as reward of mining / reward distribution.
     * @param   poolCreator The address of pool creator, whose owner will be the owner of governor.
     */
    function initialize(
        string memory name,
        string memory symbol,
        address minter,
        address target,
        address rewardToken,
        address poolCreator
    ) external virtual override initializer {
        __ERC20_init_unchained(name, symbol);
        __GovernorAlpha_init_unchained(target);
        __RewardDistribution_init_unchained(rewardToken, poolCreator);

        _minter = minter;
        _target = target;
    }

    function getMinter() public view returns (address) {
        return _minter;
    }

    function getTarget() public view virtual override(IGovernor, GovernorAlpha) returns (address) {
        return GovernorAlpha.getTarget();
    }

    /**
     * @notice  Mint token to account.
     */
    function mint(address account, uint256 amount) public virtual override {
        require(_msgSender() == _minter, "must be minter to mint");
        _mint(account, amount);
    }

    /**
     * @notice  Burn token from account. Voting will block also block burning.
     */
    function burn(address account, uint256 amount) public virtual override {
        require(_msgSender() == _minter, "must be minter to burn");
        _burn(account, amount);
    }

    function isLocked(address account) public virtual returns (bool) {
        return GovernorAlpha.isLockedByVoting(account);
    }

    /**
     * @notice  Override ERC20 balanceOf.
     */
    function balanceOf(address account)
        public
        view
        virtual
        override(IGovernor, ERC20Upgradeable, GovernorAlpha, RewardDistribution)
        returns (uint256)
    {
        return ERC20Upgradeable.balanceOf(account);
    }

    /**
     * @notice  Override ERC20 balanceOf.
     */
    function totalSupply()
        public
        view
        virtual
        override(IGovernor, ERC20Upgradeable, GovernorAlpha, RewardDistribution)
        returns (uint256)
    {
        return ERC20Upgradeable.totalSupply();
    }

    function _beforeTokenTransfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual override {
        require(!isLocked(sender), "sender is locked");
        _updateReward(sender);
        _updateReward(recipient);
        super._beforeTokenTransfer(sender, recipient, amount);
    }

    bytes32[50] private __gap;
}

File 2 of 23 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/ContextUpgradeable.sol";

File 3 of 23 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/ContextUpgradeable.sol";
import "./IERC20Upgradeable.sol";
import "../../math/SafeMathUpgradeable.sol";
import "../../proxy/Initializable.sol";

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

    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal initializer {
        __Context_init_unchained();
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

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

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

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_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() public view virtual returns (uint8) {
        return _decimals;
    }

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

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

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

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

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

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

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

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

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

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

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

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

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

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

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

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

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

File 4 of 23 : 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));
    }
}

File 5 of 23 : GovernorAlpha.sol
// SPDX-License-Identifier: BUSL-1.1
//
// The 3-Clause BSD License
// Copyright 2020 Compound Labs, Inc.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts-upgradeable/GSN/ContextUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";

import "../interface/IPoolCreatorFull.sol";
import "../interface/ILiquidityPoolGetter.sol";

/**
 * @notice Possible states that a proposal may be in.
 *
 *         There basically are up to 4 stages for a proposal:
 *           1. Pending:  Period before voter can cast vote.
 *           2. Active:   Period for casting vote.
 *                        Once voted, voter's all governor token will be locked until votingPeriod passed.
 *           3. Defeated / Succeeded:
 *                        For a defeated proposal, voting is done, all governor tokens are will unlock immediately;
 *                        For a succeeded proposal, lock will be extended by `executionDelay` + `unlockDelay`.
 *           4. Queued:   Succeeded proposal can only be executed after an `executionDelay`;
 *           5. Executed: After `executionDelay` a succeeded proposal is able to be called by anyone then marked as 'executed';
 *           6. Expired:  If a proposal succeeded but no one try to execute it, when the `unlockDelay` passed.
 *                        it will be marked as expired and no longer can be executed.
 *
 */
enum ProposalState {
    Pending,
    Active,
    Defeated,
    Succeeded,
    Queued,
    Executed,
    Expired
}

struct Proposal {
    // Unique id for looking up a proposal
    uint256 id;
    address target;
    // Creator of the proposal
    address proposer;
    // The ordered list of function signatures to be called
    string[] signatures;
    // The ordered list of calldata to be passed to each call
    bytes[] calldatas;
    // The block at which voting begins: holders must delegate their votes prior to this block
    uint256 startBlock;
    // The block at which voting ends: votes must be cast prior to this block
    uint256 endBlock;
    // Minimal votes for a proposal to succeed
    uint256 quorumVotes;
    // Current number of votes in favor of this proposal
    uint256 forVotes;
    // Current number of votes in opposition to this proposal
    uint256 againstVotes;
    // Flag marking whether the proposal has been executed
    bool executed;
    // Receipts of ballots for the entire set of voters
    mapping(address => Receipt) receipts;
}

/**
 * @notice Ballot receipt record for a account.
 */
struct Receipt {
    // Whether or not a vote has been cast
    bool hasVoted;
    // Whether or not the account supports the proposal
    bool support;
    // The number of votes the account had, which were cast
    uint256 votes;
}

/**
 * @notice This is a simplify version of 'Compound GovernorAlpha'.
 *         Timelock is integrated into GovernorAlpha.
 */
abstract contract GovernorAlpha is Initializable, ContextUpgradeable {
    using AddressUpgradeable for address;
    using SafeMathUpgradeable for uint256;
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;

    bytes4 public constant SIGNATURE_PERPETUAL_UPGRADE_AND_CALL =
        bytes4(keccak256(bytes("upgradeToAndCall(bytes32,bytes,bytes)")));
    bytes4 public constant SIGNATURE_PERPETUAL_SETTLE =
        bytes4(keccak256(bytes("forceToSetEmergencyState(uint256,int256)")));
    bytes4 public constant SIGNATURE_PERPETUAL_TRANSFER_OPERATOR =
        bytes4(keccak256(bytes("transferOperator(address)")));

    IPoolCreatorFull internal _creator;
    address internal _target;
    mapping(address => uint256) internal _voteLocks;
    mapping(address => EnumerableSetUpgradeable.UintSet) internal _supportedProposals;

    /**
     * @notice The total number of proposals.
     */
    uint256 public proposalCount;

    /**
     * @notice The official record of all proposals ever proposed.
     */
    mapping(uint256 => Proposal) public proposals;

    /**
     * @notice The latest proposal for each proposer.
     */
    mapping(address => uint256) public latestProposalIds;

    /**
     * @notice An event emitted when a new proposal is created.
     */
    event ProposalCreated(
        uint256 id,
        address proposer,
        address target,
        string[] signatures,
        bytes[] calldatas,
        uint256 startBlock,
        uint256 endBlock,
        uint256 quorumVotes,
        string description
    );

    /**
     * @notice An event emitted when a proposal is executed.
     */
    event ExecuteTransaction(
        bytes32 indexed txHash,
        address indexed target,
        string signature,
        bytes data,
        uint256 eta
    );

    /**
     * @notice  An event emitted when a vote has been cast on a proposal.
     */
    event VoteCast(address account, uint256 proposalId, bool support, uint256 votes);

    /**
     * @notice  An event emitted when a proposal has been executed in the Timelock.
     */
    event ProposalExecuted(uint256 id);

    function __GovernorAlpha_init_unchained(address target_) internal initializer {
        _target = target_;
        _creator = IPoolCreatorFull(_msgSender());
    }

    function getTarget() public view virtual returns (address) {
        return _target;
    }

    /**
     * @notice  Balance of vote token which must be implemented through inheritance.
     */
    function balanceOf(address account) public view virtual returns (uint256);

    /**
     * @notice  TotalSupply of vote token which must be implemented through inheritance.
     */
    function totalSupply() public view virtual returns (uint256);

    /**
     * @notice The number of votes in support of a proposal required in order for a quorum to be reached
     *         and for a vote to succeed.
     * @dev    [ConfirmBeforeDeployment]
     */
    function quorumRate() public pure virtual returns (uint256) {
        return 1e17;
    }

    /**
     * @notice  The number of votes in support of a proposal required in order for a quorum to be reached
     *          and for a vote to succeed.
     * @dev     [ConfirmBeforeDeployment]
     */
    function criticalQuorumRate() public pure virtual returns (uint256) {
        return 2e17;
    }

    /**
     * @notice  The number of votes required in order for a account to become a proposer.
     * @dev     [ConfirmBeforeDeployment]
     */
    function proposalThresholdRate() public pure virtual returns (uint256) {
        return 1e16;
    }

    /**
     * @notice The maximum number of actions that can be included in a proposal.
     * @dev    [ConfirmBeforeDeployment]
     */
    function proposalMaxOperations() public pure virtual returns (uint256) {
        return 10;
    }

    /**
     * @notice  The delay before voting on a proposal may take place, once proposed.
     *          See `ProposalState` for details;
     * @dev     [ConfirmBeforeDeployment]
     */
    function votingDelay() public pure virtual returns (uint256) {
        return 1;
    }

    /**
     * @notice  The duration of voting on a proposal, in blocks.
     *          See `ProposalState` for details;
     * @dev     [ConfirmBeforeDeployment]
     */
    function votingPeriod() public pure virtual returns (uint256) {
        return 17280;
    }

    /**
     * @notice  The delay before a succeeded proposal being executed (say, proposal in queued state).
     *          See `ProposalState` for details;
     * @dev     [ConfirmBeforeDeployment]
     */
    function executionDelay() public pure virtual returns (uint256) {
        return 11520;
    }

    /**
     * @notice  The duration after a proposal can be executed. See `ProposalState` for details;
     * @dev     [ConfirmBeforeDeployment]
     */
    function unlockDelay() public pure virtual returns (uint256) {
        return 17280;
    }

    function getProposalThreshold() public view virtual returns (uint256) {
        uint256 totalVotes = totalSupply();
        return totalVotes.mul(proposalThresholdRate()).div(1e18);
    }

    function getQuorumVotes(uint256 proposalId) public view virtual returns (uint256) {
        Proposal storage proposal = proposals[proposalId];
        uint256 length = proposal.signatures.length;
        uint256 totalVotes = totalSupply();
        for (uint256 i = 0; i < length; i++) {
            if (isCriticalFunction(proposal.signatures[i])) {
                return totalVotes.mul(criticalQuorumRate()).div(1e18);
            }
        }
        return totalVotes.mul(quorumRate()).div(1e18);
    }

    /**
     * @notice  Return true if a signature matches critical functions, which means a proposal with critical actions
     *          will require more share (governance) token to reach quorum.
     *
     * @param   functionSignature   The string signature of function to test.
     */
    function isCriticalFunction(string memory functionSignature) public pure returns (bool) {
        bytes4 functionHash = bytes4(keccak256(bytes(functionSignature)));
        return
            functionHash == SIGNATURE_PERPETUAL_UPGRADE_AND_CALL ||
            functionHash == SIGNATURE_PERPETUAL_SETTLE ||
            functionHash == SIGNATURE_PERPETUAL_TRANSFER_OPERATOR;
    }

    /**
     * @notice Execute a transaction in 'queue' state.
     *
     & @param   proposalId  The id of proposal to execute.
     */
    function execute(uint256 proposalId) public payable {
        require(
            state(proposalId) == ProposalState.Queued,
            "proposal can only be executed if it is success and queued"
        );
        Proposal storage proposal = proposals[proposalId];
        proposal.executed = true;
        for (uint256 i = 0; i < proposal.signatures.length; i++) {
            _executeTransaction(
                proposal.target,
                proposal.signatures[i],
                proposal.calldatas[i],
                proposal.endBlock
            );
        }
        emit ProposalExecuted(proposalId);
    }

    function getActions(uint256 proposalId)
        public
        view
        returns (string[] memory signatures, bytes[] memory calldatas)
    {
        Proposal storage p = proposals[proposalId];
        return (p.signatures, p.calldatas);
    }

    function getReceipt(uint256 proposalId, address account) public view returns (Receipt memory) {
        return proposals[proposalId].receipts[account];
    }

    function state(uint256 proposalId) public view returns (ProposalState) {
        require(proposalCount >= proposalId && proposalId > 0, "invalid proposal id");
        Proposal storage proposal = proposals[proposalId];
        if (block.number <= proposal.startBlock) {
            return ProposalState.Pending;
        } else if (block.number <= proposal.endBlock) {
            return ProposalState.Active;
        } else if (
            proposal.forVotes <= proposal.againstVotes ||
            proposal.forVotes.add(proposal.againstVotes) < proposal.quorumVotes
        ) {
            return ProposalState.Defeated;
        } else if (block.number <= proposal.endBlock.add(executionDelay())) {
            return ProposalState.Succeeded;
        } else if (proposal.executed) {
            return ProposalState.Executed;
        } else if (block.number > proposal.endBlock.add(executionDelay()).add(unlockDelay())) {
            return ProposalState.Expired;
        } else {
            return ProposalState.Queued;
        }
    }

    function propose(
        string[] memory signatures,
        bytes[] memory calldatas,
        string memory description
    ) public virtual returns (uint256) {
        require(signatures.length == calldatas.length, "function information arity mismatch");
        require(signatures.length != 0, "must provide actions");
        require(signatures.length <= proposalMaxOperations(), "too many actions");

        address proposer = _msgSender();
        uint256 proposalId = _createProposal(
            proposer,
            getTarget(),
            signatures,
            calldatas,
            description
        );
        latestProposalIds[proposer] = proposalId;
        _castVote(proposer, proposalId, true);
        return proposalId;
    }

    /**
     * @notice  Since the governor itself is upgradeable too and
     *          the ProxyAdmin is a independent contract controlled by pool creator,
     *          upgrade now is a special proposal.
     *
     * @param   targetVersionKey        The key of target version to be upgrade to.
     * @param   dataForLiquidityPool    A bytes array contains calldata to call a function of new liquidity pool after upgrade.
     *                                  This field will be ignored if left empty.
     * @param   dataForGovernor         A bytes array contains calldata to call a function of new governor after upgrade.
     *                                  This field will be ignored if left empty.
     * @param   description             A description of this proposal, only appears in transaction logs.
     * @return  proposalId              The id of new proposal.
     *
     */
    function proposeToUpgradeAndCall(
        bytes32 targetVersionKey,
        bytes memory dataForLiquidityPool,
        bytes memory dataForGovernor,
        string memory description
    ) public virtual returns (uint256) {
        _validateVersion(targetVersionKey);
        address proposer = _msgSender();
        string[] memory signatures = new string[](1);
        signatures[0] = "upgradeToAndCall(bytes32,bytes,bytes)";
        bytes[] memory calldatas = new bytes[](1);
        calldatas[0] = abi.encode(targetVersionKey, dataForLiquidityPool, dataForGovernor);
        uint256 proposalId = _createProposal(
            proposer,
            address(_creator),
            signatures,
            calldatas,
            description
        );
        latestProposalIds[proposer] = proposalId;
        _castVote(proposer, proposalId, true);
        return proposalId;
    }

    function _validateVersion(bytes32 targetVersionKey) internal view {
        require(_creator.isVersionKeyValid(targetVersionKey), "version to upgrade to is not valid");
        bytes32 baseVersionKey = _creator.getAppliedVersionKey(getTarget(), address(this));
        require(
            _creator.isVersionCompatible(targetVersionKey, baseVersionKey),
            "version to upgrade to is not compatible"
        );
    }

    function _validateProposer(address proposer) internal view {
        address operator = _getOperator();
        if (operator != address(0)) {
            require(proposer == operator, "proposer must be operator when operator exists");
        } else {
            require(balanceOf(proposer) >= getProposalThreshold(), "proposal threshold unmet");
        }
        if (latestProposalIds[proposer] != 0) {
            ProposalState latestProposalState = state(latestProposalIds[proposer]);
            require(latestProposalState != ProposalState.Pending, "last proposal is pending");
            require(latestProposalState != ProposalState.Active, "last proposal is active");
        }
    }

    function _createProposal(
        address proposer,
        address target,
        string[] memory signatures,
        bytes[] memory calldatas,
        string memory description
    ) internal returns (uint256) {
        _validateProposer(proposer);

        uint256 startBlock = _getBlockNumber().add(votingDelay());
        uint256 endBlock = startBlock.add(votingPeriod());
        proposalCount++;
        uint256 proposalId = proposalCount;

        Proposal storage proposal = proposals[proposalId];
        proposal.id = proposalId;
        proposal.target = target;
        proposal.proposer = proposer;
        proposal.signatures = signatures;
        proposal.calldatas = calldatas;
        proposal.startBlock = startBlock;
        proposal.endBlock = endBlock;
        uint256 quorumVotes = getQuorumVotes(proposalId);
        proposal.quorumVotes = quorumVotes;

        emit ProposalCreated(
            proposalId,
            proposer,
            target,
            signatures,
            calldatas,
            startBlock,
            endBlock,
            quorumVotes,
            description
        );
        return proposalId;
    }

    function castVote(uint256 proposalId, bool support) public virtual {
        require(state(proposalId) == ProposalState.Active, "voting is closed");
        _castVote(_msgSender(), proposalId, support);
    }

    function isLockedByVoting(address account) public virtual returns (bool) {
        if (account == address(0)) {
            return false;
        }
        return _getBlockNumber() <= _updateVoteLock(account, 0);
    }

    function getUnlockBlock(address account) public view virtual returns (uint256) {
        (uint256 lastUnlockBlock, , ) = _getVoteLock(account);
        return lastUnlockBlock;
    }

    function _getVoteLock(address account)
        internal
        view
        virtual
        returns (
            uint256 lastUnlockBlock,
            uint256 stableProposalCount,
            uint256[] memory stableProposalIds
        )
    {
        lastUnlockBlock = _voteLocks[account];
        EnumerableSetUpgradeable.UintSet storage proposalIds = _supportedProposals[account];
        uint256 length = proposalIds.length();
        if (length > 0) {
            stableProposalIds = new uint256[](length);
            for (uint256 i = 0; i < length; i++) {
                uint256 proposalId = proposalIds.at(i);
                ProposalState proposalState = state(proposalId);
                if (
                    proposalState == ProposalState.Pending || proposalState == ProposalState.Active
                ) {
                    continue;
                }
                if (
                    proposalState == ProposalState.Succeeded ||
                    proposalState == ProposalState.Executed ||
                    proposalState == ProposalState.Queued ||
                    proposalState == ProposalState.Expired
                ) {
                    uint256 unlockBlock = proposals[proposalId].endBlock.add(
                        executionDelay().add(unlockDelay())
                    );
                    if (unlockBlock > lastUnlockBlock) {
                        lastUnlockBlock = unlockBlock;
                    }
                }
                stableProposalIds[stableProposalCount] = proposalId;
                stableProposalCount++;
            }
        }
    }

    function _updateVoteLock(address account, uint256 blockNumber) internal returns (uint256) {
        EnumerableSetUpgradeable.UintSet storage proposalIds = _supportedProposals[account];
        (
            uint256 lastUnlockBlock,
            uint256 stableProposalCount,
            uint256[] memory stableProposalIds
        ) = _getVoteLock(account);
        for (uint256 i = 0; i < stableProposalCount; i++) {
            uint256 proposalId = stableProposalIds[i];
            if (proposalId != 0) {
                proposalIds.remove(proposalId);
            }
        }
        _voteLocks[account] = blockNumber > lastUnlockBlock ? blockNumber : lastUnlockBlock;
        return _voteLocks[account];
    }

    function _castVote(
        address account,
        uint256 proposalId,
        bool support
    ) internal {
        Proposal storage proposal = proposals[proposalId];
        Receipt storage receipt = proposal.receipts[account];
        require(receipt.hasVoted == false, "account already voted");
        uint256 votes = balanceOf(account);
        if (support) {
            proposal.forVotes = proposal.forVotes.add(votes);
        } else {
            proposal.againstVotes = proposal.againstVotes.add(votes);
        }
        receipt.hasVoted = true;
        receipt.support = support;
        receipt.votes = votes;

        _updateVoteLock(account, proposal.endBlock.add(1));
        if (support) {
            _supportedProposals[account].add(proposalId);
        }
        emit VoteCast(account, proposalId, support, votes);
    }

    function _getOperator() internal view returns (address) {
        (, , address[7] memory addresses, , ) = ILiquidityPoolGetter(_target)
            .getLiquidityPoolInfo();
        return addresses[1];
    }

    function _executeTransaction(
        address target,
        string memory signature,
        bytes memory data,
        uint256 eta
    ) internal returns (bytes memory) {
        bytes32 txHash = keccak256(abi.encode(target, signature, data, eta));
        uint256 blockNumber = _getBlockNumber();
        require(
            blockNumber >= eta.add(executionDelay()),
            "Transaction hasn't surpassed time lock."
        );
        require(
            blockNumber <= eta.add(executionDelay()).add(unlockDelay()),
            "Transaction is stale."
        );
        bytes memory returnData = target.functionCall(
            abi.encodePacked(bytes4(keccak256(bytes(signature))), data)
        );
        emit ExecuteTransaction(txHash, target, signature, data, eta);
        return returnData;
    }

    function _getBlockNumber() internal view virtual returns (uint256) {
        return block.number;
    }

    bytes32[50] private __gap;
}

File 6 of 23 : RewardDistribution.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.4;

import "@openzeppelin/contracts-upgradeable/GSN/ContextUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";

import "../interface/IPoolCreatorFull.sol";

abstract contract RewardDistribution is Initializable, ContextUpgradeable {
    using SafeMathUpgradeable for uint256;
    using SafeERC20Upgradeable for IERC20Upgradeable;

    IPoolCreatorFull public poolCreator;
    IERC20Upgradeable public rewardToken;

    uint256 public periodFinish;
    uint256 public rewardRate;
    uint256 public lastUpdateTime;
    uint256 public rewardPerTokenStored;
    address public rewardDistribution;

    mapping(address => uint256) public userRewardPerTokenPaid;
    mapping(address => uint256) public rewards;

    event RewardPaid(address indexed user, uint256 reward);
    event RewardAdded(uint256 reward, uint256 periodFinish);
    event RewardRateChanged(uint256 previousRate, uint256 currentRate, uint256 periodFinish);

    modifier updateReward(address account) {
        _updateReward(account);
        _;
    }

    modifier onlyOwnerOfPoolCreator() {
        require(_msgSender() == poolCreator.owner(), "caller must be owner of pool creator");
        _;
    }

    // virtual methods
    function balanceOf(address account) public view virtual returns (uint256);

    function totalSupply() public view virtual returns (uint256);

    function __RewardDistribution_init_unchained(address rewardToken_, address poolCreator_)
        internal
        initializer
    {
        rewardToken = IERC20Upgradeable(rewardToken_);
        poolCreator = IPoolCreatorFull(poolCreator_);
    }

    /**
     * @notice  Set reward distribution rate. If there is unfinished distribution, the end block will be changed
     *          according to change of newRewardRate.
     *
     * @param   newRewardRate   New reward distribution rate.
     */
    function setRewardRate(uint256 newRewardRate)
        external
        virtual
        onlyOwnerOfPoolCreator
        updateReward(address(0))
    {
        if (newRewardRate == 0) {
            periodFinish = block.number;
        } else if (periodFinish != 0) {
            periodFinish = periodFinish.sub(lastUpdateTime).mul(rewardRate).div(newRewardRate).add(
                block.number
            );
        }
        emit RewardRateChanged(rewardRate, newRewardRate, periodFinish);
        rewardRate = newRewardRate;
    }

    /**
     * @notice  Add new distributable reward to current pool, this will extend an exist distribution or
     *          start a new distribution if previous one is already ended.
     *
     * @param   reward  Amount of reward to add.
     */
    function notifyRewardAmount(uint256 reward)
        external
        virtual
        onlyOwnerOfPoolCreator
        updateReward(address(0))
    {
        require(rewardRate > 0, "rewardRate is zero");
        uint256 period = reward.div(rewardRate);
        // already finished or not initialized
        if (block.number > periodFinish) {
            lastUpdateTime = block.number;
            periodFinish = block.number.add(period);
            emit RewardAdded(reward, periodFinish);
        } else {
            // not finished or not initialized
            periodFinish = periodFinish.add(period);
            emit RewardAdded(reward, periodFinish);
        }
    }

    /**
     * @notice  Return end block if last distribution is done or current timestamp.
     */
    function lastBlockRewardApplicable() public view returns (uint256) {
        return block.number <= periodFinish ? block.number : periodFinish;
    }

    /**
     * @notice  Return the per token amount of reward.
     *          The expected reward of user is: [amount of share] x rewardPerToken - claimedReward.
     */
    function rewardPerToken() public view returns (uint256) {
        if (totalSupply() == 0) {
            return rewardPerTokenStored;
        }
        return
            rewardPerTokenStored.add(
                lastBlockRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(
                    totalSupply()
                )
            );
    }

    /**
     * @notice  Return real time reward of account.
     */
    function earned(address account) public view returns (uint256) {
        return
            balanceOf(account)
                .mul(rewardPerToken().sub(userRewardPerTokenPaid[account]))
                .div(1e18)
                .add(rewards[account]);
    }

    /**
     * @notice  Claim all remaining reward of account.
     */
    function getReward() public updateReward(_msgSender()) {
        address account = _msgSender();
        uint256 reward = earned(account);
        if (reward > 0) {
            rewards[account] = 0;
            rewardToken.safeTransfer(account, reward);
            emit RewardPaid(account, reward);
        }
    }

    function _updateReward(address account) internal {
        rewardPerTokenStored = rewardPerToken();
        lastUpdateTime = lastBlockRewardApplicable();
        if (account != address(0)) {
            rewards[account] = earned(account);
            userRewardPerTokenPaid[account] = rewardPerTokenStored;
        }
    }

    bytes32[50] private __gap;
}

File 7 of 23 : IGovernor.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IGovernor {
    function initialize(
        string memory name,
        string memory symbol,
        address minter,
        address target_,
        address rewardToken,
        address poolCreator
    ) external;

    function totalSupply() external view returns (uint256);

    function getTarget() external view returns (address);

    function mint(address account, uint256 amount) external;

    function burn(address account, uint256 amount) external;

    function balanceOf(address account) external view returns (uint256);
}

File 8 of 23 : 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 9 of 23 : 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 10 of 23 : 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 11 of 23 : 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 12 of 23 : 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 13 of 23 : IPoolCreatorFull.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

import "./IAccessControl.sol";
import "./IPoolCreator.sol";
import "./ITracer.sol";
import "./IVersionControl.sol";
import "./IVariables.sol";
import "./IKeeperWhitelist.sol";

interface IPoolCreatorFull is
    IPoolCreator,
    IVersionControl,
    ITracer,
    IVariables,
    IAccessControl,
    IKeeperWhitelist
{
    /**
     * @notice Owner of version control.
     */
    function owner() external view override(IVersionControl, IVariables) returns (address);
}

File 14 of 23 : ILiquidityPoolGetter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;

import "../Type.sol";

interface ILiquidityPoolGetter {
    /**
     * @notice Get the info of the liquidity pool
     * @return isRunning True if the liquidity pool is running
     * @return isFastCreationEnabled True if the operator of the liquidity pool is allowed to create new perpetual
     *                               when the liquidity pool is running
     * @return addresses The related addresses of the liquidity pool
     * @return intNums Int type properties, see below for details.
     * @return uintNums Uint type properties, see below for details.
     */
    function getLiquidityPoolInfo()
        external
        view
        returns (
            bool isRunning,
            bool isFastCreationEnabled,
            // [0] creator,
            // [1] operator,
            // [2] transferringOperator,
            // [3] governor,
            // [4] shareToken,
            // [5] collateralToken,
            // [6] vault,
            address[7] memory addresses,
            // [0] vaultFeeRate,
            // [1] poolCash,
            // [2] insuranceFundCap,
            // [3] insuranceFund,
            // [4] donatedInsuranceFund,
            int256[5] memory intNums,
            // [0] collateralDecimals,
            // [1] perpetualCount
            // [2] fundingTime,
            // [3] operatorExpiration,
            uint256[4] memory uintNums
        );

    /**
     * @notice Get the info of the perpetual. Need to update the funding state and the oracle price
     *         of each perpetual before and update the funding rate of each perpetual after
     * @param perpetualIndex The index of the perpetual in the liquidity pool
     * @return state The state of the perpetual
     * @return oracle The oracle's address of the perpetual
     * @return nums The related numbers of the perpetual
     */
    function getPerpetualInfo(uint256 perpetualIndex)
        external
        view
        returns (
            PerpetualState state,
            address oracle,
            // [0] totalCollateral
            // [1] markPrice, (return settlementPrice if it is in EMERGENCY state)
            // [2] indexPrice,
            // [3] fundingRate,
            // [4] unitAccumulativeFunding,
            // [5] initialMarginRate,
            // [6] maintenanceMarginRate,
            // [7] operatorFeeRate,
            // [8] lpFeeRate,
            // [9] referralRebateRate,
            // [10] liquidationPenaltyRate,
            // [11] keeperGasReward,
            // [12] insuranceFundRate,
            // [13-15] halfSpread value, min, max,
            // [16-18] openSlippageFactor value, min, max,
            // [19-21] closeSlippageFactor value, min, max,
            // [22-24] fundingRateLimit value, min, max,
            // [25-27] ammMaxLeverage value, min, max,
            // [28-30] maxClosePriceDiscount value, min, max,
            // [31] openInterest,
            // [32] maxOpenInterestRate,
            // [33-35] fundingRateFactor value, min, max,
            // [36-38] defaultTargetLeverage value, min, max,
            int256[39] memory nums
        );

    /**
     * @notice Get the account info of the trader. Need to update the funding state and the oracle price
     *         of each perpetual before and update the funding rate of each perpetual after
     * @param perpetualIndex The index of the perpetual in the liquidity pool
     * @param trader The address of the trader
     * @return cash The cash(collateral) of the account
     * @return position The position of the account
     * @return availableMargin The available margin of the account
     * @return margin The margin of the account
     * @return settleableMargin The settleable margin of the account
     * @return isInitialMarginSafe True if the account is initial margin safe
     * @return isMaintenanceMarginSafe True if the account is maintenance margin safe
     * @return isMarginSafe True if the total value of margin account is beyond 0
     * @return targetLeverage   The target leverage for openning position.
     */
    function getMarginAccount(uint256 perpetualIndex, address trader)
        external
        view
        returns (
            int256 cash,
            int256 position,
            int256 availableMargin,
            int256 margin,
            int256 settleableMargin,
            bool isInitialMarginSafe,
            bool isMaintenanceMarginSafe,
            bool isMarginSafe, // bankrupt
            int256 targetLeverage
        );

    /**
     * @notice Get the number of active accounts in the perpetual.
     *         Active means the trader's account is not empty in the perpetual.
     *         Empty means cash and position are zero
     * @param perpetualIndex The index of the perpetual in the liquidity pool
     * @return activeAccountCount The number of active accounts in the perpetual
     */
    function getActiveAccountCount(uint256 perpetualIndex) external view returns (uint256);

    /**
     * @notice Get the active accounts in the perpetual whose index between begin and end.
     *         Active means the trader's account is not empty in the perpetual.
     *         Empty means cash and position are zero
     * @param perpetualIndex The index of the perpetual in the liquidity pool
     * @param begin The begin index
     * @param end The end index
     * @return result The active accounts in the perpetual whose index between begin and end
     */
    function listActiveAccounts(
        uint256 perpetualIndex,
        uint256 begin,
        uint256 end
    ) external view returns (address[] memory result);

    /**
     * @notice Get the progress of clearing active accounts.
     *         Return the number of total active accounts and the number of active accounts not cleared
     * @param perpetualIndex The index of the perpetual in the liquidity pool
     * @return left The left active accounts
     * @return total The total active accounts
     */
    function getClearProgress(uint256 perpetualIndex)
        external
        view
        returns (uint256 left, uint256 total);

    /**
     * @notice Get the pool margin of the liquidity pool.
     *         Pool margin is how much collateral of the pool considering the AMM's positions of perpetuals
     * @return poolMargin The pool margin of the liquidity pool
     */
    function getPoolMargin() external view returns (int256 poolMargin, bool isSafe);

    /**
     * @notice  Query the price, fees and cost when trade agaist amm.
     *          The trading price is determined by the AMM based on the index price of the perpetual.
     *          This method should returns the same result as a 'read-only' trade.
     *          WARN: the result of this function is base on current storage of liquidityPool, not the latest.
     *          To get the latest status, call `syncState` first.
     *
     *          Flags is a 32 bit uint value which indicates: (from highest bit)
     *            - close only      only close position during trading;
     *            - market order    do not check limit price during trading;
     *            - stop loss       only available in brokerTrade mode;
     *            - take profit     only available in brokerTrade mode;
     *          For stop loss and take profit, see `validateTriggerPrice` in OrderModule.sol for details.
     *
     * @param   perpetualIndex  The index of the perpetual in liquidity pool.
     * @param   trader          The address of trader.
     * @param   amount          The amount of position to trader, positive for buying and negative for selling. The amount always use decimals 18.
     * @param   referrer        The address of referrer who will get rebate from the deal.
     * @param   flags           The flags of the trade.
     * @return  tradePrice      The average fill price.
     * @return  totalFee        The total fee collected from the trader after the trade.
     * @return  cost            Deposit or withdraw to let effective leverage == targetLeverage if flags contain USE_TARGET_LEVERAGE. > 0 if deposit, < 0 if withdraw.
     */
    function queryTrade(
        uint256 perpetualIndex,
        address trader,
        int256 amount,
        address referrer,
        uint32 flags
    )
        external
        returns (
            int256 tradePrice,
            int256 totalFee,
            int256 cost
        );

    /**
     * @notice  Query cash to add / share to mint when adding liquidity to the liquidity pool.
     *          Only one of cashToAdd or shareToMint may be non-zero.
     *
     * @param   cashToAdd         The amount of cash to add, always use decimals 18.
     * @param   shareToMint       The amount of share token to mint, always use decimals 18.
     * @return  cashToAddResult   The amount of cash to add, always use decimals 18. Equal to cashToAdd if cashToAdd is non-zero.
     * @return  shareToMintResult The amount of cash to add, always use decimals 18. Equal to shareToMint if shareToMint is non-zero.
     */
    function queryAddLiquidity(int256 cashToAdd, int256 shareToMint)
        external
        view
        returns (int256 cashToAddResult, int256 shareToMintResult);

    /**
     * @notice  Query cash to return / share to redeem when removing liquidity from the liquidity pool.
     *          Only one of shareToRemove or cashToReturn may be non-zero.
     *          Can only called when the pool is running.
     *
     * @param   shareToRemove       The amount of share token to redeem, always use decimals 18.
     * @param   cashToReturn        The amount of cash to return, always use decimals 18.
     * @return  shareToRemoveResult The amount of share token to redeem, always use decimals 18. Equal to shareToRemove if shareToRemove is non-zero.
     * @return  cashToReturnResult  The amount of cash to return, always use decimals 18. Equal to cashToReturn if cashToReturn is non-zero.
     */
    function queryRemoveLiquidity(int256 shareToRemove, int256 cashToReturn)
        external
        view
        returns (int256 shareToRemoveResult, int256 cashToReturnResult);
}

File 15 of 23 : IAccessControl.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

interface IAccessControl {
    function grantPrivilege(address trader, uint256 privilege) external;

    function revokePrivilege(address trader, uint256 privilege) external;

    function isGranted(
        address owner,
        address trader,
        uint256 privilege
    ) external view returns (bool);
}

File 16 of 23 : IPoolCreator.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

import "./IProxyAdmin.sol";

interface IPoolCreator {
    function upgradeAdmin() external view returns (IProxyAdmin proxyAdmin);

    /**
     * @notice  Create a liquidity pool with the latest version.
     *          The sender will be the operator of pool.
     *
     * @param   collateral              he collateral address of the liquidity pool.
     * @param   collateralDecimals      The collateral's decimals of the liquidity pool.
     * @param   nonce                   A random nonce to calculate the address of deployed contracts.
     * @param   initData                A bytes array contains data to initialize new created liquidity pool.
     * @return  liquidityPool           The address of the created liquidity pool.
     */
    function createLiquidityPool(
        address collateral,
        uint256 collateralDecimals,
        int256 nonce,
        bytes calldata initData
    ) external returns (address liquidityPool, address governor);

    /**
     * @notice  Upgrade a liquidity pool and governor pair then call a patch function on the upgraded contract (optional).
     *          This method checks the sender and forwards the request to ProxyAdmin to do upgrading.
     *
     * @param   targetVersionKey        The key of version to be upgrade up. The target version must be compatible with
     *                                  current version.
     * @param   dataForLiquidityPool    The patch calldata for upgraded liquidity pool.
     * @param   dataForGovernor         The patch calldata of upgraded governor.
     */
    function upgradeToAndCall(
        bytes32 targetVersionKey,
        bytes memory dataForLiquidityPool,
        bytes memory dataForGovernor
    ) external;

    /**
     * @notice  Indicates the universe settle state.
     *          If the flag set to true:
     *              - all the pereptual created by this poolCreator can be settled immediately;
     *              - all the trading method will be unavailable.
     */
    function isUniverseSettled() external view returns (bool);
}

File 17 of 23 : ITracer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

import "./IProxyAdmin.sol";

interface ITracer {
    /**
     * @notice  Activate the perpetual for the trader. Active means the trader's account is not empty in
     *          the perpetual. Empty means cash and position are zero. Can only called by a liquidity pool.
     *
     * @param   trader          The address of the trader.
     * @param   perpetualIndex  The index of the perpetual in the liquidity pool.
     * @return  True if the activation is successful.
     */
    function activatePerpetualFor(address trader, uint256 perpetualIndex) external returns (bool);

    /**
     * @notice  Deactivate the perpetual for the trader. Active means the trader's account is not empty in
     *          the perpetual. Empty means cash and position are zero. Can only called by a liquidity pool.
     *
     * @param   trader          The address of the trader.
     * @param   perpetualIndex  The index of the perpetual in the liquidity pool.
     * @return  True if the deactivation is successful.
     */
    function deactivatePerpetualFor(address trader, uint256 perpetualIndex) external returns (bool);

    /**
     * @notice  Liquidity pool must call this method when changing its ownership to the new operator.
     *          Can only be called by a liquidity pool. This method does not affect 'ownership' or privileges
     *          of operator but only make a record for further query.
     *
     * @param   liquidityPool   The address of the liquidity pool.
     * @param   operator        The address of the new operator, must be different from the old operator.
     */
    function registerOperatorOfLiquidityPool(address liquidityPool, address operator) external;
}

File 18 of 23 : IVersionControl.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

import "./IProxyAdmin.sol";

interface IVersionControl {
    function owner() external view returns (address);

    function getLatestVersion() external view returns (bytes32 latestVersionKey);

    /**
     * @notice  Get the details of the version.
     *
     * @param   versionKey              The key of the version to get.
     * @return  liquidityPoolTemplate   The address of the liquidity pool template.
     * @return  governorTemplate        The address of the governor template.
     * @return  compatibility           The compatibility of the specified version.
     */
    function getVersion(bytes32 versionKey)
        external
        view
        returns (
            address liquidityPoolTemplate,
            address governorTemplate,
            uint256 compatibility
        );

    /**
     * @notice  Get the description of the implementation of liquidity pool.
     *          Description contains creator, create time, compatibility and note
     *
     * @param  liquidityPool        The address of the liquidity pool.
     * @param  governor             The address of the governor.
     * @return appliedVersionKey    The version key of given liquidity pool and governor.
     */
    function getAppliedVersionKey(address liquidityPool, address governor)
        external
        view
        returns (bytes32 appliedVersionKey);

    /**
     * @notice  Check if a key is valid (exists).
     *
     * @param   versionKey  The key of the version to test.
     * @return  isValid     Return true if the version of given key is valid.
     */
    function isVersionKeyValid(bytes32 versionKey) external view returns (bool isValid);

    /**
     * @notice  Check if the implementation of liquidity pool target is compatible with the implementation base.
     *          Being compatible means having larger compatibility.
     *
     * @param   targetVersionKey    The key of the version to be upgraded to.
     * @param   baseVersionKey      The key of the version to be upgraded from.
     * @return  isCompatible        True if the target version is compatible with the base version.
     */
    function isVersionCompatible(bytes32 targetVersionKey, bytes32 baseVersionKey)
        external
        view
        returns (bool isCompatible);

    /**
     * @dev     Get a certain number of implementations of liquidity pool within range [begin, end).
     *
     * @param   begin       The index of first element to retrieve.
     * @param   end         The end index of element, exclusive.
     * @return  versionKeys An array contains current version keys.
     */
    function listAvailableVersions(uint256 begin, uint256 end)
        external
        view
        returns (bytes32[] memory versionKeys);
}

File 19 of 23 : IVariables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

import "./IProxyAdmin.sol";

interface IVariables {
    function owner() external view returns (address);

    /**
     * @notice Get the address of the vault
     * @return address The address of the vault
     */
    function getVault() external view returns (address);

    /**
     * @notice Get the vault fee rate
     * @return int256 The vault fee rate
     */
    function getVaultFeeRate() external view returns (int256);

    /**
     * @notice Get the address of the access controller. It's always its own address.
     *
     * @return address The address of the access controller.
     */
    function getAccessController() external view returns (address);

    /**
     * @notice  Get the address of the symbol service.
     *
     * @return  Address The address of the symbol service.
     */
    function getSymbolService() external view returns (address);

    /**
     * @notice  Set the vault address. Can only called by owner.
     *
     * @param   newVault    The new value of the vault fee rate
     */
    function setVault(address newVault) external;

    /**
     * @notice  Get the address of the mcb token.
     * @dev     [ConfirmBeforeDeployment]
     *
     * @return  Address The address of the mcb token.
     */
    function getMCBToken() external pure returns (address);

    /**
     * @notice  Set the vault fee rate. Can only called by owner.
     *
     * @param   newVaultFeeRate The new value of the vault fee rate
     */
    function setVaultFeeRate(int256 newVaultFeeRate) external;
}

File 20 of 23 : IKeeperWhitelist.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

interface IKeeperWhitelist {
    /**
     * @notice Add an address to keeper whitelist.
     */
    function addKeeper(address keeper) external;

    /**
     * @notice Remove an address from keeper whitelist.
     */
    function removeKeeper(address keeper) external;

    /**
     * @notice Check if an address is in keeper whitelist.
     */
    function isKeeper(address keeper) external view returns (bool);
}

File 21 of 23 : IProxyAdmin.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.4;

interface IProxyAdmin {
    function getProxyImplementation(address proxy) external view returns (address);

    /**
     * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
     *
     * Requirements:
     *
     * - This contract must be the admin of `proxy`.
     */
    function upgrade(address proxy, address implementation) external;

    /**
     * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
     * {TransparentUpgradeableProxy-upgradeToAndCall}.
     *
     * Requirements:
     *
     * - This contract must be the admin of `proxy`.
     */
    function upgradeAndCall(
        address proxy,
        address implementation,
        bytes memory data
    ) external payable;
}

File 22 of 23 : Type.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.4;

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

/**
 * @notice  Perpetual state:
 *          - INVALID:      Uninitialized or not non-existent perpetual;
 *          - INITIALIZING: Only when LiquidityPoolStorage.isRunning == false. Traders cannot perform operations;
 *          - NORMAL:       Full functional state. Traders is able to perform all operations;
 *          - EMERGENCY:    Perpetual is unsafe and only clear is available;
 *          - CLEARED:      All margin account is cleared. Trade could withdraw remaining margin balance.
 */
enum PerpetualState {
    INVALID,
    INITIALIZING,
    NORMAL,
    EMERGENCY,
    CLEARED
}
enum OrderType {
    LIMIT,
    MARKET,
    STOP
}

/**
 * @notice  Data structure to store risk parameter value.
 */
struct Option {
    int256 value;
    int256 minValue;
    int256 maxValue;
}

/**
 * @notice  Data structure to store oracle price data.
 */
struct OraclePriceData {
    int256 price;
    uint256 time;
}

/**
 * @notice  Data structure to store user margin information. See MarginAccountModule.sol for details.
 */
struct MarginAccount {
    int256 cash;
    int256 position;
    int256 targetLeverage;
}

/**
 * @notice  Data structure of an order object.
 */
struct Order {
    address trader;
    address broker;
    address relayer;
    address referrer;
    address liquidityPool;
    int256 minTradeAmount;
    int256 amount;
    int256 limitPrice;
    int256 triggerPrice;
    uint256 chainID;
    uint64 expiredAt;
    uint32 perpetualIndex;
    uint32 brokerFeeLimit;
    uint32 flags;
    uint32 salt;
}

/**
 * @notice  Core data structure, a core .
 */
struct LiquidityPoolStorage {
    bool isRunning;
    bool isFastCreationEnabled;
    // addresses
    address creator;
    address operator;
    address transferringOperator;
    address governor;
    address shareToken;
    address accessController;
    bool reserved3; // isWrapped
    uint256 scaler;
    uint256 collateralDecimals;
    address collateralToken;
    // pool attributes
    int256 poolCash;
    uint256 fundingTime;
    uint256 reserved5;
    uint256 operatorExpiration;
    mapping(address => int256) reserved1;
    bytes32[] reserved2;
    // perpetuals
    uint256 perpetualCount;
    mapping(uint256 => PerpetualStorage) perpetuals;
    // insurance fund
    int256 insuranceFundCap;
    int256 insuranceFund;
    int256 donatedInsuranceFund;
    address reserved4;
    // reserved slot for future upgrade
    bytes32[16] reserved;
}

/**
 * @notice  Core data structure, storing perpetual information.
 */
struct PerpetualStorage {
    uint256 id;
    PerpetualState state;
    address oracle;
    int256 totalCollateral;
    int256 openInterest;
    // prices
    OraclePriceData indexPriceData;
    OraclePriceData markPriceData;
    OraclePriceData settlementPriceData;
    // funding state
    int256 fundingRate;
    int256 unitAccumulativeFunding;
    // base parameters
    int256 initialMarginRate;
    int256 maintenanceMarginRate;
    int256 operatorFeeRate;
    int256 lpFeeRate;
    int256 referralRebateRate;
    int256 liquidationPenaltyRate;
    int256 keeperGasReward;
    int256 insuranceFundRate;
    int256 reserved1;
    int256 maxOpenInterestRate;
    // risk parameters
    Option halfSpread;
    Option openSlippageFactor;
    Option closeSlippageFactor;
    Option fundingRateLimit;
    Option fundingRateFactor;
    Option ammMaxLeverage;
    Option maxClosePriceDiscount;
    // users
    uint256 totalAccount;
    int256 totalMarginWithoutPosition;
    int256 totalMarginWithPosition;
    int256 redemptionRateWithoutPosition;
    int256 redemptionRateWithPosition;
    EnumerableSetUpgradeable.AddressSet activeAccounts;
    // insurance fund
    int256 reserved2;
    int256 reserved3;
    // accounts
    mapping(address => MarginAccount) marginAccounts;
    Option defaultTargetLeverage;
    // keeper
    address reserved4;
    EnumerableSetUpgradeable.AddressSet ammKeepers;
    EnumerableSetUpgradeable.AddressSet reserved5;
    // reserved slot for future upgrade
    bytes32[12] reserved;
}

File 23 of 23 : 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");
        }
    }
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"txHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"string","name":"signature","type":"string"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"eta","type":"uint256"}],"name":"ExecuteTransaction","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"address","name":"proposer","type":"address"},{"indexed":false,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"string[]","name":"signatures","type":"string[]"},{"indexed":false,"internalType":"bytes[]","name":"calldatas","type":"bytes[]"},{"indexed":false,"internalType":"uint256","name":"startBlock","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endBlock","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quorumVotes","type":"uint256"},{"indexed":false,"internalType":"string","name":"description","type":"string"}],"name":"ProposalCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"ProposalExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"periodFinish","type":"uint256"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"periodFinish","type":"uint256"}],"name":"RewardRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"proposalId","type":"uint256"},{"indexed":false,"internalType":"bool","name":"support","type":"bool"},{"indexed":false,"internalType":"uint256","name":"votes","type":"uint256"}],"name":"VoteCast","type":"event"},{"inputs":[],"name":"SIGNATURE_PERPETUAL_SETTLE","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SIGNATURE_PERPETUAL_TRANSFER_OPERATOR","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SIGNATURE_PERPETUAL_UPGRADE_AND_CALL","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"bool","name":"support","type":"bool"}],"name":"castVote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"criticalQuorumRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"executionDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"getActions","outputs":[{"internalType":"string[]","name":"signatures","type":"string[]"},{"internalType":"bytes[]","name":"calldatas","type":"bytes[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProposalThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"getQuorumVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"address","name":"account","type":"address"}],"name":"getReceipt","outputs":[{"components":[{"internalType":"bool","name":"hasVoted","type":"bool"},{"internalType":"bool","name":"support","type":"bool"},{"internalType":"uint256","name":"votes","type":"uint256"}],"internalType":"struct Receipt","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getTarget","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getUnlockBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"minter","type":"address"},{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"address","name":"poolCreator","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"functionSignature","type":"string"}],"name":"isCriticalFunction","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isLocked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isLockedByVoting","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastBlockRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"latestProposalIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"name":"notifyRewardAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"periodFinish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolCreator","outputs":[{"internalType":"contract IPoolCreatorFull","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proposalCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proposalMaxOperations","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"proposalThresholdRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"proposals","outputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"uint256","name":"startBlock","type":"uint256"},{"internalType":"uint256","name":"endBlock","type":"uint256"},{"internalType":"uint256","name":"quorumVotes","type":"uint256"},{"internalType":"uint256","name":"forVotes","type":"uint256"},{"internalType":"uint256","name":"againstVotes","type":"uint256"},{"internalType":"bool","name":"executed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string[]","name":"signatures","type":"string[]"},{"internalType":"bytes[]","name":"calldatas","type":"bytes[]"},{"internalType":"string","name":"description","type":"string"}],"name":"propose","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"targetVersionKey","type":"bytes32"},{"internalType":"bytes","name":"dataForLiquidityPool","type":"bytes"},{"internalType":"bytes","name":"dataForGovernor","type":"bytes"},{"internalType":"string","name":"description","type":"string"}],"name":"proposeToUpgradeAndCall","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"quorumRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"rewardDistribution","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRewardRate","type":"uint256"}],"name":"setRewardRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"state","outputs":[{"internalType":"enum ProposalState","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unlockDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votingDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"votingPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]

608060405234801561001057600080fd5b50614b2a806100206000396000f3fe6080604052600436106103805760003560e01c806385a21b19116101d1578063cd3daf9d11610102578063e56f2fe4116100a0578063f36675171161006f578063f3667517146109a8578063f7c292a2146109bd578063f7c618c1146109d2578063fe0d94c1146109e757610380565b8063e56f2fe41461093e578063ebe2b12b1461095e578063f00e6a2a14610973578063f3205ed81461098857610380565b8063dd62ed3e116100dc578063dd62ed3e146108c7578063df136d65146108e7578063e1a54078146108fc578063e23a9a521461091157610380565b8063cd3daf9d1461087d578063d08e237314610892578063da35c664146108b257610380565b8063a457c2d71161016f578063b4c4e25811610149578063b4c4e2581461081e578063c6c1decd14610833578063c8eb690214610848578063c8f33c911461086857610380565b8063a457c2d7146107c9578063a9059cbb146107e9578063abe0429c1461080957610380565b806395d89b41116101ab57806395d89b411461075f5780639c0784fd146107745780639dc29fac146107895780639e447fc6146107a957610380565b806385a21b19146107155780638b2579891461072a5780638b8763471461073f57610380565b8063313ce567116102b657806340c10f191161025457806370a082311161022357806370a08231146106a957806374281ee6146106c95780637b0a47ee146106eb5780637bdbe4d01461070057610380565b806340c10f19146106345780634a235528146106545780634a4fbeec146106695780634c852eb21461068957610380565b8063395093511161029057806339509351146105b25780633c6b16ab146105d25780633d18b912146105f25780633e4f49e61461060757610380565b8063313ce5671461054d578063328dd9821461056f5780633932abb11461059d57610380565b80630bb4df0c1161032357806317977c61116102fd57806317977c61146104d857806318160ddd146104f857806322ed77f81461050d57806323b872dd1461052d57610380565b80630bb4df0c14610474578063101114cf1461049457806315373e3d146104b657610380565b80630519da321161035f5780630519da32146103f057806306fdde03146104055780630700037d14610427578063095ea7b31461044757610380565b80628cc26214610385578063013cf08b146103bb57806302a251a3146103f0575b600080fd5b34801561039157600080fd5b506103a56103a0366004613b29565b6109fa565b6040516103b29190614153565b60405180910390f35b3480156103c757600080fd5b506103db6103d6366004613f1a565b610a6a565b6040516103b29998979695949392919061478e565b3480156103fc57600080fd5b506103a5610ac4565b34801561041157600080fd5b5061041a610acb565b6040516103b291906141e0565b34801561043357600080fd5b506103a5610442366004613b29565b610b61565b34801561045357600080fd5b50610467610462366004613bbd565b610b73565b6040516103b29190614148565b34801561048057600080fd5b506103a561048f366004613b29565b610b91565b3480156104a057600080fd5b506104a9610ba7565b6040516103b29190614087565b3480156104c257600080fd5b506104d66104d1366004613f56565b610bb6565b005b3480156104e457600080fd5b506103a56104f3366004613b29565b610c08565b34801561050457600080fd5b506103a5610c1a565b34801561051957600080fd5b50610467610528366004613b29565b610c29565b34801561053957600080fd5b50610467610548366004613b7d565b610c5c565b34801561055957600080fd5b50610562610ce4565b6040516103b291906147db565b34801561057b57600080fd5b5061058f61058a366004613f1a565b610ced565b6040516103b2929190614123565b3480156105a957600080fd5b506103a5610ebd565b3480156105be57600080fd5b506104676105cd366004613bbd565b610ec2565b3480156105de57600080fd5b506104d66105ed366004613f1a565b610f10565b3480156105fe57600080fd5b506104d661110d565b34801561061357600080fd5b50610627610622366004613f1a565b6111aa565b6040516103b291906141cc565b34801561064057600080fd5b506104d661064f366004613bbd565b6112c6565b34801561066057600080fd5b506103a561130a565b34801561067557600080fd5b50610467610684366004613b29565b611316565b34801561069557600080fd5b506103a56106a4366004613dad565b611321565b3480156106b557600080fd5b506103a56106c4366004613b29565b611455565b3480156106d557600080fd5b506106de611460565b6040516103b2919061419f565b3480156106f757600080fd5b506103a56114b9565b34801561070c57600080fd5b506103a56114bf565b34801561072157600080fd5b506103a56114c4565b34801561073657600080fd5b506103a56114f5565b34801561074b57600080fd5b506103a561075a366004613b29565b6114fb565b34801561076b57600080fd5b5061041a61150d565b34801561078057600080fd5b506103a561156e565b34801561079557600080fd5b506104d66107a4366004613bbd565b611579565b3480156107b557600080fd5b506104d66107c4366004613f1a565b6115bd565b3480156107d557600080fd5b506104676107e4366004613bbd565b611723565b3480156107f557600080fd5b50610467610804366004613bbd565b61178b565b34801561081557600080fd5b506103a561179f565b34801561082a57600080fd5b506106de6117b8565b34801561083f57600080fd5b506104a96117db565b34801561085457600080fd5b506103a5610863366004613be8565b6117ea565b34801561087457600080fd5b506103a56118a7565b34801561088957600080fd5b506103a56118ad565b34801561089e57600080fd5b506104676108ad366004613e3b565b6118fb565b3480156108be57600080fd5b506103a5611a02565b3480156108d357600080fd5b506103a56108e2366004613b45565b611a08565b3480156108f357600080fd5b506103a5611a33565b34801561090857600080fd5b506106de611a39565b34801561091d57600080fd5b5061093161092c366004613f32565b611a5c565b6040516103b291906146eb565b34801561094a57600080fd5b506104d6610959366004613e6e565b611abd565b34801561096a57600080fd5b506103a5611bb2565b34801561097f57600080fd5b506104a9611bb8565b34801561099457600080fd5b506103a56109a3366004613f1a565b611bc2565b3480156109b457600080fd5b506104a9611ce3565b3480156109c957600080fd5b506103a5611cf2565b3480156109de57600080fd5b506104a9611cfe565b6104d66109f5366004613f1a565b611d0d565b6001600160a01b038116600090815260a6602090815260408083205460a5909252822054610a629190610a5c90670de0b6b3a764000090610a5690610a4790610a416118ad565b90611f13565b610a5088611455565b90611f70565b90611fc9565b90612030565b90505b919050565b606a60205260009081526040902080546001820154600283015460058401546006850154600786015460088701546009880154600a9098015496976001600160a01b03968716979690951695939492939192909160ff1689565b6143805b90565b60368054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610b575780601f10610b2c57610100808354040283529160200191610b57565b820191906000526020600020905b815481529060010190602001808311610b3a57829003601f168201915b5050505050905090565b60a66020526000908152604090205481565b6000610b87610b8061208a565b848461208e565b5060015b92915050565b600080610b9d8361217a565b5090949350505050565b60a4546001600160a01b031681565b6001610bc1836111aa565b6006811115610bcc57fe5b14610bf25760405162461bcd60e51b8152600401610be9906143e1565b60405180910390fd5b610c04610bfd61208a565b838361231a565b5050565b606b6020526000908152604090205481565b6000610c2461244e565b905090565b60006001600160a01b038216610c4157506000610a65565b610c4c826000612454565b610c546124f6565b111592915050565b6000610c698484846124fa565b610cd984610c7561208a565b610cd4856040518060600160405280602881526020016149ec602891396001600160a01b038a16600090815260346020526040812090610cb361208a565b6001600160a01b031681526020810191909152604001600020549190612657565b61208e565b5060015b9392505050565b60385460ff1690565b6060806000606a60008581526020019081526020016000209050806003018160040181805480602002602001604051908101604052809291908181526020016000905b82821015610ddb5760008481526020908190208301805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015610dc75780601f10610d9c57610100808354040283529160200191610dc7565b820191906000526020600020905b815481529060010190602001808311610daa57829003601f168201915b505050505081526020019060010190610d30565b50505050915080805480602002602001604051908101604052809291908181526020016000905b82821015610ead5760008481526020908190208301805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015610e995780601f10610e6e57610100808354040283529160200191610e99565b820191906000526020600020905b815481529060010190602001808311610e7c57829003601f168201915b505050505081526020019060010190610e02565b5050505090509250925050915091565b600190565b6000610b87610ecf61208a565b84610cd48560346000610ee061208a565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490612030565b609e60009054906101000a90046001600160a01b03166001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b158015610f5e57600080fd5b505afa158015610f72573d6000803e3d6000fd5b505050506040513d6020811015610f8857600080fd5b50516001600160a01b0316610f9b61208a565b6001600160a01b031614610fe05760405162461bcd60e51b815260040180806020018281038252602481526020018061487f6024913960400191505060405180910390fd5b6000610feb816126ee565b600060a15411611042576040805162461bcd60e51b815260206004820152601260248201527f72657761726452617465206973207a65726f0000000000000000000000000000604482015290519081900360640190fd5b600061105960a15484611fc990919063ffffffff16565b905060a0544311156110ba574360a28190556110759082612030565b60a081905560408051858152602081019290925280517f6c07ee05dcf262f13abf9d87b846ee789d2f90fe991d495acd7d7fc109ee1f559281900390910190a1611108565b60a0546110c79082612030565b60a081905560408051858152602081019290925280517f6c07ee05dcf262f13abf9d87b846ee789d2f90fe991d495acd7d7fc109ee1f559281900390910190a15b505050565b61111561208a565b61111e816126ee565b600061112861208a565b90506000611135826109fa565b90508015611108576001600160a01b03808316600090815260a66020526040812055609f546111669116838361274b565b6040805182815290516001600160a01b038416917fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486919081900360200190a2505050565b600081606954101580156111be5750600082115b6111da5760405162461bcd60e51b8152600401610be990614229565b6000828152606a60205260409020600581015443116111fd576000915050610a65565b80600601544311611212576001915050610a65565b8060090154816008015411158061123e575060078101546009820154600883015461123c91612030565b105b1561124d576002915050610a65565b6112636112586114f5565b600683015490612030565b4311611273576003915050610a65565b600a81015460ff161561128a576005915050610a65565b6112ab611295610ac4565b610a5c6112a06114f5565b600685015490612030565b4311156112bc576006915050610a65565b6004915050610a65565b60d9546001600160a01b03166112da61208a565b6001600160a01b0316146113005760405162461bcd60e51b8152600401610be990614305565b610c0482826127b6565b6702c68af0bb14000090565b6000610a6282610c29565b600061132c856128a8565b600061133661208a565b60408051600180825281830190925291925060609190816020015b606081526020019060019003908161135157905050905060405180606001604052806025815260200161492c602591398160008151811061138e57fe5b6020908102919091010152604080516001808252818301909252606091816020015b60608152602001906001900390816113b05790505090508787876040516020016113dc9392919061416a565b604051602081830303815290604052816000815181106113f857fe5b60209081029190910101526065546000906114209085906001600160a01b031685858a612a9f565b6001600160a01b0385166000908152606b6020526040902081905590506114498482600161231a565b98975050505050505050565b6000610a6282612bd4565b60408051808201909152601981527f7472616e736665724f70657261746f72286164647265737329000000000000006020909101527f29605e77570554e17097b370f7d97acbb47139a4d78e46edc79331bbb54c115f81565b60a15481565b600a90565b6000806114cf610c1a565b90506114ef670de0b6b3a7640000610a566114e861156e565b8490611f70565b91505090565b612d0090565b60a56020526000908152604090205481565b60378054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610b575780601f10610b2c57610100808354040283529160200191610b57565b662386f26fc1000090565b60d9546001600160a01b031661158d61208a565b6001600160a01b0316146115b35760405162461bcd60e51b8152600401610be990614509565b610c048282612bef565b609e60009054906101000a90046001600160a01b03166001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561160b57600080fd5b505afa15801561161f573d6000803e3d6000fd5b505050506040513d602081101561163557600080fd5b50516001600160a01b031661164861208a565b6001600160a01b03161461168d5760405162461bcd60e51b815260040180806020018281038252602481526020018061487f6024913960400191505060405180910390fd5b6000611698816126ee565b816116a6574360a0556116d7565b60a054156116d7576116d343610a5c84610a5660a154610a5060a25460a054611f1390919063ffffffff16565b60a0555b60a15460a054604080519283526020830185905282810191909152517f3d209aed8ecb665e2e6cc55772bfc177e7aa7f6fa40ce4af171a43ed8fa2e2db9181900360600190a15060a155565b6000610b8761173061208a565b84610cd485604051806060016040528060258152602001614ad0602591396034600061175a61208a565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190612657565b6000610b8761179861208a565b84846124fa565b600060a0544311156117b35760a054610c24565b504390565b60405180606001604052806025815260200161492c602591398051906020012081565b609e546001600160a01b031681565b6000825184511461180d5760405162461bcd60e51b8152600401610be990614657565b835161182b5760405162461bcd60e51b8152600401610be9906142ce565b6118336114bf565b845111156118535760405162461bcd60e51b8152600401610be990614260565b600061185d61208a565b905060006118758261186d611bb8565b888888612a9f565b6001600160a01b0383166000908152606b60205260409020819055905061189e8282600161231a565b95945050505050565b60a25481565b60006118b7610c1a565b6118c4575060a354610ac8565b610c246118f26118d2610c1a565b610a56670de0b6b3a7640000610a5060a154610a5060a254610a4161179f565b60a35490612030565b6000808280519060200120905060405180606001604052806025815260200161492c60259139805190602001206001600160e01b031916816001600160e01b031916148061197b5750604051806060016040528060288152602001614a7e60289139805190602001206001600160e01b031916816001600160e01b031916145b80610cdd575060408051808201909152601981527f7472616e736665724f70657261746f72286164647265737329000000000000006020909101527fffffffff0000000000000000000000000000000000000000000000000000000081167f29605e7700000000000000000000000000000000000000000000000000000000149392505050565b60695481565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b60a35481565b604051806060016040528060288152602001614a7e602891398051906020012081565b611a64613776565b506000918252606a602090815260408084206001600160a01b03939093168452600b9092018152918190208151606081018352815460ff8082161515835261010090910416151593810193909352600101549082015290565b600054610100900460ff1680611ad65750611ad6612ceb565b80611ae4575060005460ff16155b611b1f5760405162461bcd60e51b815260040180806020018281038252602e81526020018061499d602e913960400191505060405180910390fd5b600054610100900460ff16158015611b4a576000805460ff1961ff0019909116610100171660011790555b611b548787612cfc565b611b5d84612dd4565b611b678383612eb9565b60d980546001600160a01b038088166001600160a01b03199283161790925560668054928716929091169190911790558015611ba9576000805461ff00191690555b50505050505050565b60a05481565b6000610c24612f8c565b6000818152606a60205260408120600381015482611bde610c1a565b905060005b82811015611ccb57611c95846003018281548110611bfd57fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015611c8b5780601f10611c6057610100808354040283529160200191611c8b565b820191906000526020600020905b815481529060010190602001808311611c6e57829003601f168201915b50505050506118fb565b15611cc357611cb8670de0b6b3a7640000610a56611cb161130a565b8590611f70565b945050505050610a65565b600101611be3565b5061189e670de0b6b3a7640000610a566114e8611cf2565b60d9546001600160a01b031690565b67016345785d8a000090565b609f546001600160a01b031681565b6004611d18826111aa565b6006811115611d2357fe5b14611d405760405162461bcd60e51b8152600401610be990614540565b6000818152606a60205260408120600a8101805460ff19166001179055905b6003820154811015611ed7576001820154600383018054611ece926001600160a01b0316919084908110611d8f57fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015611e1d5780601f10611df257610100808354040283529160200191611e1d565b820191906000526020600020905b815481529060010190602001808311611e0057829003601f168201915b5050505050846004018481548110611e3157fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015611ebf5780601f10611e9457610100808354040283529160200191611ebf565b820191906000526020600020905b815481529060010190602001808311611ea257829003601f168201915b50505050508560060154612f9b565b50600101611d5f565b507f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f82604051611f079190614153565b60405180910390a15050565b600082821115611f6a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600082611f7f57506000610b8b565b82820282848281611f8c57fe5b0414610cdd5760405162461bcd60e51b81526004018080602001828103825260218152602001806149cb6021913960400191505060405180910390fd5b600080821161201f576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161202857fe5b049392505050565b600082820183811015610cdd576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b3390565b6001600160a01b0383166120d35760405162461bcd60e51b8152600401808060200182810382526024815260200180614a5a6024913960400191505060405180910390fd5b6001600160a01b0382166121185760405162461bcd60e51b815260040180806020018281038252602281526020018061490a6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260346020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b03811660009081526067602090815260408083205460689092528220909190606090826121ad826130d9565b90508015612311578067ffffffffffffffff811180156121cc57600080fd5b506040519080825280602002602001820160405280156121f6578160200160208202803683370190505b50925060005b8181101561230f57600061221084836130e4565b9050600061221d826111aa565b9050600081600681111561222d57fe5b14806122445750600181600681111561224257fe5b145b15612250575050612307565b600381600681111561225e57fe5b14806122755750600581600681111561227357fe5b145b8061228b5750600481600681111561228957fe5b145b806122a15750600681600681111561229f57fe5b145b156122e65760006122d66122be6122b6610ac4565b610a5c6114f5565b6000858152606a602052604090206006015490612030565b9050888111156122e4578098505b505b818688815181106122f357fe5b602090810291909101015250506001909401935b6001016121fc565b505b50509193909250565b6000828152606a602090815260408083206001600160a01b0387168452600b8101909252909120805460ff16156123635760405162461bcd60e51b8152600401610be990614373565b600061236e86611455565b9050831561238f5760088301546123859082612030565b60088401556123a4565b600983015461239e9082612030565b60098401555b8154600160ff19909116811761ff0019166101008615150217835580830182905560068401546123de9188916123d991612030565b612454565b508315612409576001600160a01b038616600090815260686020526040902061240790866130f0565b505b7f877856338e13f63d0c36822ff0ef736b80934cd90574a3a5bc9262c39d217c468686868460405161243e94939291906140fb565b60405180910390a1505050505050565b60355490565b6001600160a01b0382166000908152606860205260408120818060606124798761217a565b92509250925060005b828110156124bf57600082828151811061249857fe5b60200260200101519050806000146124b6576124b486826130fc565b505b50600101612482565b508286116124cd57826124cf565b855b6001600160a01b038816600090815260676020526040902081905594505050505092915050565b4390565b6001600160a01b03831661253f5760405162461bcd60e51b8152600401808060200182810382526025815260200180614a356025913960400191505060405180910390fd5b6001600160a01b0382166125845760405162461bcd60e51b81526004018080602001828103825260238152602001806148c56023913960400191505060405180910390fd5b61258f838383613108565b6125cc81604051806060016040528060268152602001614951602691396001600160a01b0386166000908152603360205260409020549190612657565b6001600160a01b0380851660009081526033602052604080822093909355908416815220546125fb9082612030565b6001600160a01b0380841660008181526033602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156126e65760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156126ab578181015183820152602001612693565b50505050905090810190601f1680156126d85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6126f66118ad565b60a35561270161179f565b60a2556001600160a01b038116156127485761271c816109fa565b6001600160a01b038216600090815260a6602090815260408083209390935560a35460a5909152919020555b50565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b03167fa9059cbb0000000000000000000000000000000000000000000000000000000017905261110890849061314b565b6001600160a01b038216612811576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61281d60008383613108565b60355461282a9082612030565b6035556001600160a01b0382166000908152603360205260409020546128509082612030565b6001600160a01b03831660008181526033602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6065546040517f8277c6510000000000000000000000000000000000000000000000000000000081526001600160a01b0390911690638277c651906128f1908490600401614153565b60206040518083038186803b15801561290957600080fd5b505afa15801561291d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129419190613cbc565b61295d5760405162461bcd60e51b8152600401610be99061459d565b6065546000906001600160a01b031663db7ca94b612979611bb8565b306040518363ffffffff1660e01b815260040161299792919061409b565b60206040518083038186803b1580156129af57600080fd5b505afa1580156129c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129e79190613d95565b6065546040517f3c597ff60000000000000000000000000000000000000000000000000000000081529192506001600160a01b031690633c597ff690612a33908590859060040161415c565b60206040518083038186803b158015612a4b57600080fd5b505afa158015612a5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a839190613cbc565b610c045760405162461bcd60e51b8152600401610be9906145fa565b6000612aaa866131fc565b6000612abf612ab7610ebd565b610a5c6124f6565b90506000612ad5612ace610ac4565b8390612030565b606980546001908101918290556000828152606a6020908152604090912083815591820180546001600160a01b03808e166001600160a01b031992831617909255600284018054928f1692909116919091179055895193945091929091612b439160038401918b0190613796565b508651612b5990600483019060208a01906137f3565b5060058101849055600681018390556000612b7383611bc2565b90508082600701819055507fc98917001dd55381b0307302ec6f8b757eb673e54d241fdddd6f722e847340bf838c8c8c8c8a8a888f604051612bbd99989796959493929190614710565b60405180910390a150909998505050505050505050565b6001600160a01b031660009081526033602052604090205490565b6001600160a01b038216612c345760405162461bcd60e51b8152600401808060200182810382526021815260200180614a146021913960400191505060405180910390fd5b612c4082600083613108565b612c7d816040518060600160405280602281526020016148e8602291396001600160a01b0385166000908152603360205260409020549190612657565b6001600160a01b038316600090815260336020526040902055603554612ca39082611f13565b6035556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6000612cf630613316565b15905090565b600054610100900460ff1680612d155750612d15612ceb565b80612d23575060005460ff16155b612d5e5760405162461bcd60e51b815260040180806020018281038252602e81526020018061499d602e913960400191505060405180910390fd5b600054610100900460ff16158015612d89576000805460ff1961ff0019909116610100171660011790555b8251612d9c90603690602086019061384c565b508151612db090603790602085019061384c565b506038805460ff191660121790558015611108576000805461ff0019169055505050565b600054610100900460ff1680612ded5750612ded612ceb565b80612dfb575060005460ff16155b612e365760405162461bcd60e51b815260040180806020018281038252602e81526020018061499d602e913960400191505060405180910390fd5b600054610100900460ff16158015612e61576000805460ff1961ff0019909116610100171660011790555b606680546001600160a01b0319166001600160a01b038416179055612e8461208a565b606580546001600160a01b0319166001600160a01b03929092169190911790558015610c04576000805461ff00191690555050565b600054610100900460ff1680612ed25750612ed2612ceb565b80612ee0575060005460ff16155b612f1b5760405162461bcd60e51b815260040180806020018281038252602e81526020018061499d602e913960400191505060405180910390fd5b600054610100900460ff16158015612f46576000805460ff1961ff0019909116610100171660011790555b609f80546001600160a01b038086166001600160a01b031992831617909255609e8054928516929091169190911790558015611108576000805461ff0019169055505050565b6066546001600160a01b031690565b6060600085858585604051602001612fb694939291906140b5565b6040516020818303038152906040528051906020012090506000612fd86124f6565b9050612fec612fe56114f5565b8590612030565b81101561300b5760405162461bcd60e51b8152600401610be99061444f565b613028613016610ac4565b610a5c6130216114f5565b8790612030565b8111156130475760405162461bcd60e51b8152600401610be9906146b4565b606061308687805190602001208760405160200161306692919061403f565b60408051601f198184030181529190526001600160a01b038a169061331c565b9050876001600160a01b0316837f73bcadb73827ad9a900198359278e77086ae03e9e17ef173ad7de9e7e39acaff8989896040516130c6939291906141f3565b60405180910390a3979650505050505050565b6000610a628261335e565b6000610cdd8383613362565b6000610cdd83836133c6565b6000610cdd8383613410565b61311183611316565b1561312e5760405162461bcd60e51b8152600401610be9906143aa565b613137836126ee565b613140826126ee565b611108838383611108565b60606131a0826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166134d69092919063ffffffff16565b805190915015611108578080602001905160208110156131bf57600080fd5b50516111085760405162461bcd60e51b815260040180806020018281038252602a815260200180614aa6602a913960400191505060405180910390fd5b60006132066134ed565b90506001600160a01b0381161561324d57806001600160a01b0316826001600160a01b0316146132485760405162461bcd60e51b8152600401610be9906144ac565b61327c565b6132556114c4565b61325e83611455565b101561327c5760405162461bcd60e51b8152600401610be990614297565b6001600160a01b0382166000908152606b602052604090205415610c04576001600160a01b0382166000908152606b60205260408120546132bc906111aa565b905060008160068111156132cc57fe5b14156132ea5760405162461bcd60e51b8152600401610be99061433c565b60018160068111156132f857fe5b14156111085760405162461bcd60e51b8152600401610be990614418565b3b151590565b6060610cdd83836040518060400160405280601e81526020017f416464726573733a206c6f772d6c6576656c2063616c6c206661696c656400008152506134d6565b5490565b815460009082106133a45760405162461bcd60e51b81526004018080602001828103825260228152602001806148a36022913960400191505060405180910390fd5b8260000182815481106133b357fe5b9060005260206000200154905092915050565b60006133d2838361359c565b61340857508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610b8b565b506000610b8b565b600081815260018301602052604081205480156134cc578354600019808301919081019060009087908390811061344357fe5b906000526020600020015490508087600001848154811061346057fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061349057fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610b8b565b6000915050610b8b565b60606134e584846000856135b4565b949350505050565b60006134f76138d4565b606660009054906101000a90046001600160a01b03166001600160a01b0316630cdc105a6040518163ffffffff1660e01b81526004016102406040518083038186803b15801561354657600080fd5b505afa15801561355a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061357e9190613cd8565b5050925050508060016007811061359157fe5b602002015191505090565b60009081526001919091016020526040902054151590565b6060824710156135f55760405162461bcd60e51b81526004018080602001828103825260268152602001806149776026913960400191505060405180910390fd5b6135fe85613316565b61364f576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b6020831061368e5780518252601f19909201916020918201910161366f565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146136f0576040519150601f19603f3d011682016040523d82523d6000602084013e6136f5565b606091505b5091509150613705828286613710565b979650505050505050565b6060831561371f575081610cdd565b82511561372f5782518084602001fd5b60405162461bcd60e51b81526020600482018181528451602484015284518593919283926044019190850190808383600083156126ab578181015183820152602001612693565b604080516060810182526000808252602082018190529181019190915290565b8280548282559060005260206000209081019282156137e3579160200282015b828111156137e357825180516137d391849160209091019061384c565b50916020019190600101906137b6565b506137ef9291506138f2565b5090565b828054828255906000526020600020908101928215613840579160200282015b82811115613840578251805161383091849160209091019061384c565b5091602001919060010190613813565b506137ef92915061390f565b828054600181600116156101000203166002900490600052602060002090601f01602090048101928261388257600085556138c8565b82601f1061389b57805160ff19168380011785556138c8565b828001600101855582156138c8579182015b828111156138c85782518255916020019190600101906138ad565b506137ef92915061392c565b6040518060e001604052806007906020820280368337509192915050565b808211156137ef5760006139068282613941565b506001016138f2565b808211156137ef5760006139238282613941565b5060010161390f565b5b808211156137ef576000815560010161392d565b50805460018160011615610100020316600290046000825580601f106139675750612748565b601f016020900490600052602060002090810190612748919061392c565b600082601f830112613995578081fd5b81356139a86139a38261480d565b6147e9565b818152915060208083019084810160005b848110156139e2576139d0888484358a0101613ac2565b845292820192908201906001016139b9565b505050505092915050565b600082601f8301126139fd578081fd5b60405160a0810181811067ffffffffffffffff82111715613a1a57fe5b6040529050808260a08101851015613a3157600080fd5b60005b6005811015613a53578151835260209283019290910190600101613a34565b50505092915050565b600082601f830112613a6c578081fd5b6040516080810181811067ffffffffffffffff82111715613a8957fe5b6040529050808260808101851015613aa057600080fd5b60005b6004811015613a53578151835260209283019290910190600101613aa3565b600082601f830112613ad2578081fd5b813567ffffffffffffffff811115613ae657fe5b613af9601f8201601f19166020016147e9565b9150808252836020828501011115613b1057600080fd5b8060208401602084013760009082016020015292915050565b600060208284031215613b3a578081fd5b8135610cdd8161485b565b60008060408385031215613b57578081fd5b8235613b628161485b565b91506020830135613b728161485b565b809150509250929050565b600080600060608486031215613b91578081fd5b8335613b9c8161485b565b92506020840135613bac8161485b565b929592945050506040919091013590565b60008060408385031215613bcf578182fd5b8235613bda8161485b565b946020939093013593505050565b600080600060608486031215613bfc578283fd5b833567ffffffffffffffff80821115613c13578485fd5b818601915086601f830112613c26578485fd5b8135613c346139a38261480d565b81815260208082019190858101895b85811015613c6c57613c5a8d8484358b0101613ac2565b85529382019390820190600101613c43565b50919850890135945050505080821115613c84578384fd5b613c9087838801613985565b93506040860135915080821115613ca5578283fd5b50613cb286828701613ac2565b9150509250925092565b600060208284031215613ccd578081fd5b8151610cdd81614870565b60008060008060006102408688031215613cf0578283fd5b8551613cfb81614870565b80955050602080870151613d0e81614870565b9450605f87018813613d1e578384fd5b613d2860e06147e9565b80604089016101208a018b811115613d3e578788fd5b875b6007811015613d66578251613d548161485b565b85529385019391850191600101613d40565b50829750613d748c826139ed565b96505050505050613d89876101c08801613a5c565b90509295509295909350565b600060208284031215613da6578081fd5b5051919050565b60008060008060808587031215613dc2578182fd5b84359350602085013567ffffffffffffffff80821115613de0578384fd5b613dec88838901613ac2565b94506040870135915080821115613e01578384fd5b613e0d88838901613ac2565b93506060870135915080821115613e22578283fd5b50613e2f87828801613ac2565b91505092959194509250565b600060208284031215613e4c578081fd5b813567ffffffffffffffff811115613e62578182fd5b6134e584828501613ac2565b60008060008060008060c08789031215613e86578384fd5b863567ffffffffffffffff80821115613e9d578586fd5b613ea98a838b01613ac2565b97506020890135915080821115613ebe578586fd5b50613ecb89828a01613ac2565b9550506040870135613edc8161485b565b93506060870135613eec8161485b565b92506080870135613efc8161485b565b915060a0870135613f0c8161485b565b809150509295509295509295565b600060208284031215613f2b578081fd5b5035919050565b60008060408385031215613f44578182fd5b823591506020830135613b728161485b565b60008060408385031215613f68578182fd5b823591506020830135613b7281614870565b6000815180845260208085018081965082840281019150828601855b85811015613fc0578284038952613fae848351614013565b98850198935090840190600101613f96565b5091979650505050505050565b6000815180845260208085018081965082840281019150828601855b85811015613fc0578284038952614001848351614013565b98850198935090840190600101613fe9565b6000815180845261402b81602086016020860161482b565b601f01601f19169290920160200192915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000084168252825161407981600485016020870161482b565b919091016004019392505050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b60006001600160a01b0386168252608060208301526140d76080830186614013565b82810360408401526140e98186614013565b91505082606083015295945050505050565b6001600160a01b03949094168452602084019290925215156040830152606082015260800190565b6000604082526141366040830185613fcd565b828103602084015261189e8185613f7a565b901515815260200190565b90815260200190565b918252602082015260400190565b6000848252606060208301526141836060830185614013565b82810360408401526141958185614013565b9695505050505050565b7fffffffff0000000000000000000000000000000000000000000000000000000091909116815260200190565b60208101600783106141da57fe5b91905290565b600060208252610cdd6020830184614013565b6000606082526142066060830186614013565b82810360208401526142188186614013565b915050826040830152949350505050565b60208082526013908201527f696e76616c69642070726f706f73616c20696400000000000000000000000000604082015260600190565b60208082526010908201527f746f6f206d616e7920616374696f6e7300000000000000000000000000000000604082015260600190565b60208082526018908201527f70726f706f73616c207468726573686f6c6420756e6d65740000000000000000604082015260600190565b60208082526014908201527f6d7573742070726f7669646520616374696f6e73000000000000000000000000604082015260600190565b60208082526016908201527f6d757374206265206d696e74657220746f206d696e7400000000000000000000604082015260600190565b60208082526018908201527f6c6173742070726f706f73616c2069732070656e64696e670000000000000000604082015260600190565b60208082526015908201527f6163636f756e7420616c726561647920766f7465640000000000000000000000604082015260600190565b60208082526010908201527f73656e646572206973206c6f636b656400000000000000000000000000000000604082015260600190565b60208082526010908201527f766f74696e6720697320636c6f73656400000000000000000000000000000000604082015260600190565b60208082526017908201527f6c6173742070726f706f73616c20697320616374697665000000000000000000604082015260600190565b60208082526027908201527f5472616e73616374696f6e206861736e2774207375727061737365642074696d60408201527f65206c6f636b2e00000000000000000000000000000000000000000000000000606082015260800190565b6020808252602e908201527f70726f706f736572206d757374206265206f70657261746f72207768656e206f60408201527f70657261746f7220657869737473000000000000000000000000000000000000606082015260800190565b60208082526016908201527f6d757374206265206d696e74657220746f206275726e00000000000000000000604082015260600190565b60208082526039908201527f70726f706f73616c2063616e206f6e6c7920626520657865637574656420696660408201527f206974206973207375636365737320616e642071756575656400000000000000606082015260800190565b60208082526022908201527f76657273696f6e20746f207570677261646520746f206973206e6f742076616c60408201527f6964000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526027908201527f76657273696f6e20746f207570677261646520746f206973206e6f7420636f6d60408201527f70617469626c6500000000000000000000000000000000000000000000000000606082015260800190565b60208082526023908201527f66756e6374696f6e20696e666f726d6174696f6e206172697479206d69736d6160408201527f7463680000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526015908201527f5472616e73616374696f6e206973207374616c652e0000000000000000000000604082015260600190565b8151151581526020808301511515908201526040918201519181019190915260600190565b60006101208b83526001600160a01b03808c166020850152808b166040850152508060608401526147438184018a613fcd565b905082810360808401526147578189613f7a565b90508660a08401528560c08401528460e084015282810361010084015261477e8185614013565b9c9b505050505050505050505050565b9889526001600160a01b0397881660208a01529590961660408801526060870193909352608086019190915260a085015260c084015260e083019190915215156101008201526101200190565b60ff91909116815260200190565b60405181810167ffffffffffffffff8111828210171561480557fe5b604052919050565b600067ffffffffffffffff82111561482157fe5b5060209081020190565b60005b8381101561484657818101518382015260200161482e565b83811115614855576000848401525b50505050565b6001600160a01b038116811461274857600080fd5b801515811461274857600080fdfe63616c6c6572206d757374206265206f776e6572206f6620706f6f6c2063726561746f72456e756d657261626c655365743a20696e646578206f7574206f6620626f756e647345524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737375706772616465546f416e6443616c6c28627974657333322c62797465732c62797465732945524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373666f726365546f536574456d657267656e637953746174652875696e743235362c696e74323536295361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220431d5e1e9a2b9be4cbadc06d60b3dd7f728c07316b96f956087a88c9ed36c97e64736f6c63430007040033

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