ETH Price: $3,274.49 (+0.44%)

Contract

0x489dC359F9f1799FBf388abf91cFe7cb37736D6a
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
PPIEDelegate

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, None license
File 1 of 14 : PPIEDelegate.sol
pragma solidity ^0.7.6;

import "./PPIE.sol";
import "./RegistryInterface.sol";

/**
 * @title DeFiPie's PPIEDelegate Contract
 * @notice PTokens which wrap an EIP-20 underlying and are delegated to
 * @author DeFiPie
 */
contract PPIEDelegate is PPIE {
    /**
     * @notice Construct an empty delegate
     */
    constructor() {}
}

File 2 of 14 : CarefulMath.sol
pragma solidity ^0.7.6;

/**
  * @title Careful Math
  * @author DeFiPie
  * @notice Derived from OpenZeppelin's SafeMath library
  *         https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
  */
contract CarefulMath {

    /**
     * @dev Possible error codes that we can return
     */
    enum MathError {
        NO_ERROR,
        DIVISION_BY_ZERO,
        INTEGER_OVERFLOW,
        INTEGER_UNDERFLOW
    }

    /**
    * @dev Multiplies two numbers, returns an error on overflow.
    */
    function mulUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (a == 0) {
            return (MathError.NO_ERROR, 0);
        }

        uint c = a * b;

        if (c / a != b) {
            return (MathError.INTEGER_OVERFLOW, 0);
        } else {
            return (MathError.NO_ERROR, c);
        }
    }

    /**
    * @dev Integer division of two numbers, truncating the quotient.
    */
    function divUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (b == 0) {
            return (MathError.DIVISION_BY_ZERO, 0);
        }

        return (MathError.NO_ERROR, a / b);
    }

    /**
    * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).
    */
    function subUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (b <= a) {
            return (MathError.NO_ERROR, a - b);
        } else {
            return (MathError.INTEGER_UNDERFLOW, 0);
        }
    }

    /**
    * @dev Adds two numbers, returns an error on overflow.
    */
    function addUInt(uint a, uint b) internal pure returns (MathError, uint) {
        uint c = a + b;

        if (c >= a) {
            return (MathError.NO_ERROR, c);
        } else {
            return (MathError.INTEGER_OVERFLOW, 0);
        }
    }

    /**
    * @dev add a and b and then subtract c
    */
    function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) {
        (MathError err0, uint sum) = addUInt(a, b);

        if (err0 != MathError.NO_ERROR) {
            return (err0, 0);
        }

        return subUInt(sum, c);
    }
}

File 3 of 14 : ControllerInterface.sol
pragma solidity ^0.7.6;

import "./PriceOracle.sol";

abstract contract ControllerInterface {
    /// @notice Indicator that this is a Controller contract (for inspection)
    bool public constant isController = true;

    /*** Assets You Are In ***/

    function enterMarkets(address[] calldata pTokens) external virtual returns (uint[] memory);
    function exitMarket(address pToken) external virtual returns (uint);

    /*** Policy Hooks ***/

    function mintAllowed(address pToken, address minter, uint mintAmount) external virtual returns (uint);
    function redeemAllowed(address pToken, address redeemer, uint redeemTokens) external virtual returns (uint);
    function redeemVerify(address pToken, address redeemer, uint redeemAmount, uint redeemTokens) external virtual;
    function borrowAllowed(address pToken, address borrower, uint borrowAmount) external virtual returns (uint);

    function repayBorrowAllowed(
        address pToken,
        address payer,
        address borrower,
        uint repayAmount) external virtual returns (uint);

    function liquidateBorrowAllowed(
        address pTokenBorrowed,
        address pTokenCollateral,
        address liquidator,
        address borrower,
        uint repayAmount) external virtual returns (uint);

    function seizeAllowed(
        address pTokenCollateral,
        address pTokenBorrowed,
        address liquidator,
        address borrower,
        uint seizeTokens) external virtual returns (uint);

    function transferAllowed(address pToken, address src, address dst, uint transferTokens) external virtual returns (uint);

    /*** Liquidity/Liquidation Calculations ***/

    function liquidateCalculateSeizeTokens(
        address pTokenBorrowed,
        address pTokenCollateral,
        uint repayAmount) external view virtual returns (uint, uint);

    function getOracle() external view virtual returns (PriceOracle);
}

File 4 of 14 : EIP20Interface.sol
pragma solidity ^0.7.6;

/**
 * @title ERC 20 Token Standard Interface
 *  https://eips.ethereum.org/EIPS/eip-20
 */
interface EIP20Interface {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);

    /**
      * @notice Get the total number of tokens in circulation
      * @return The supply of tokens
      */
    function totalSupply() external view returns (uint256);

    /**
     * @notice Gets the balance of the specified address
     * @param owner The address from which the balance will be retrieved
     * @return The balance
     */
    function balanceOf(address owner) external view returns (uint256);

    /**
      * @notice Transfer `amount` tokens from `msg.sender` to `dst`
      * @param dst The address of the destination account
      * @param amount The number of tokens to transfer
      * @return Whether or not the transfer succeeded
      */
    function transfer(address dst, uint256 amount) external returns (bool);

    /**
      * @notice Transfer `amount` tokens from `src` to `dst`
      * @param src The address of the source account
      * @param dst The address of the destination account
      * @param amount The number of tokens to transfer
      * @return Whether or not the transfer succeeded
      */
    function transferFrom(address src, address dst, uint256 amount) external returns (bool);

    /**
      * @notice Approve `spender` to transfer up to `amount` from `src`
      * @dev This will overwrite the approval amount for `spender`
      *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
      * @param spender The address of the account which may transfer tokens
      * @param amount The number of tokens that are approved (-1 means infinite)
      * @return Whether or not the approval succeeded
      */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
      * @notice Get the current allowance from `owner` for `spender`
      * @param owner The address of the account which owns the tokens to be spent
      * @param spender The address of the account which may transfer tokens
      * @return The number of tokens allowed to be spent (-1 means infinite)
      */
    function allowance(address owner, address spender) external view returns (uint256);

    event Transfer(address indexed from, address indexed to, uint256 amount);
    event Approval(address indexed owner, address indexed spender, uint256 amount);
}

File 5 of 14 : EIP20NonStandardInterface.sol
pragma solidity ^0.7.6;

/**
 * @title EIP20NonStandardInterface
 * @dev Version of ERC20 with no return values for `transfer` and `transferFrom`
 *  See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
 */
interface EIP20NonStandardInterface {

    /**
     * @notice Get the total number of tokens in circulation
     * @return The supply of tokens
     */
    function totalSupply() external view returns (uint256);

    /**
     * @notice Gets the balance of the specified address
     * @param owner The address from which the balance will be retrieved
     * @return The balance
     */
    function balanceOf(address owner) external view returns (uint256);

    ///
    /// !!!!!!!!!!!!!!
    /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification
    /// !!!!!!!!!!!!!!
    ///

    /**
      * @notice Transfer `amount` tokens from `msg.sender` to `dst`
      * @param dst The address of the destination account
      * @param amount The number of tokens to transfer
      */
    function transfer(address dst, uint256 amount) external;

    ///
    /// !!!!!!!!!!!!!!
    /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification
    /// !!!!!!!!!!!!!!
    ///

    /**
      * @notice Transfer `amount` tokens from `src` to `dst`
      * @param src The address of the source account
      * @param dst The address of the destination account
      * @param amount The number of tokens to transfer
      */
    function transferFrom(address src, address dst, uint256 amount) external;

    /**
      * @notice Approve `spender` to transfer up to `amount` from `src`
      * @dev This will overwrite the approval amount for `spender`
      *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
      * @param spender The address of the account which may transfer tokens
      * @param amount The number of tokens that are approved
      * @return Whether or not the approval succeeded
      */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
      * @notice Get the current allowance from `owner` for `spender`
      * @param owner The address of the account which owns the tokens to be spent
      * @param spender The address of the account which may transfer tokens
      * @return The number of tokens allowed to be spent
      */
    function allowance(address owner, address spender) external view returns (uint256);

    event Transfer(address indexed from, address indexed to, uint256 amount);
    event Approval(address indexed owner, address indexed spender, uint256 amount);
}

File 6 of 14 : ErrorReporter.sol
pragma solidity ^0.7.6;

contract ControllerErrorReporter {
    enum Error {
        NO_ERROR,
        UNAUTHORIZED,
        CONTROLLER_MISMATCH,
        INSUFFICIENT_SHORTFALL,
        INSUFFICIENT_LIQUIDITY,
        INVALID_CLOSE_FACTOR,
        INVALID_COLLATERAL_FACTOR,
        INVALID_LIQUIDATION_INCENTIVE,
        MARKET_NOT_ENTERED, // no longer possible
        MARKET_NOT_LISTED,
        MARKET_ALREADY_LISTED,
        MATH_ERROR,
        NONZERO_BORROW_BALANCE,
        PRICE_ERROR,
        PRICE_UPDATE_ERROR,
        REJECTION,
        SNAPSHOT_ERROR,
        TOO_MANY_ASSETS,
        TOO_MUCH_REPAY
    }

    enum FailureInfo {
        ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
        ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,
        EXIT_MARKET_BALANCE_OWED,
        EXIT_MARKET_REJECTION,
        SET_CLOSE_FACTOR_OWNER_CHECK,
        SET_CLOSE_FACTOR_VALIDATION,
        SET_COLLATERAL_FACTOR_OWNER_CHECK,
        SET_COLLATERAL_FACTOR_NO_EXISTS,
        SET_COLLATERAL_FACTOR_VALIDATION,
        SET_COLLATERAL_FACTOR_WITHOUT_PRICE,
        SET_IMPLEMENTATION_OWNER_CHECK,
        SET_LIQUIDATION_INCENTIVE_OWNER_CHECK,
        SET_LIQUIDATION_INCENTIVE_VALIDATION,
        SET_MAX_ASSETS_OWNER_CHECK,
        SET_PAUSE_GUARDIAN_OWNER_CHECK,
        SET_PENDING_ADMIN_OWNER_CHECK,
        SET_PENDING_IMPLEMENTATION_OWNER_CHECK,
        SET_PRICE_ORACLE_OWNER_CHECK,
        SUPPORT_MARKET_EXISTS,
        SUPPORT_MARKET_OWNER_CHECK
    }

    /**
      * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
      * contract-specific code that enables us to report opaque error codes from upgradeable contracts.
      **/
    event Failure(uint error, uint info, uint detail);

    /**
      * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
      */
    function fail(Error err, FailureInfo info) internal returns (uint) {
        emit Failure(uint(err), uint(info), 0);

        return uint(err);
    }

    /**
      * @dev use this when reporting an opaque error from an upgradeable collaborator contract
      */
    function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) {
        emit Failure(uint(err), uint(info), opaqueError);

        return uint(err);
    }
}

contract TokenErrorReporter {
    enum Error {
        NO_ERROR,
        UNAUTHORIZED,
        BAD_INPUT,
        CONTROLLER_REJECTION,
        CONTROLLER_CALCULATION_ERROR,
        INTEREST_RATE_MODEL_ERROR,
        INVALID_ACCOUNT_PAIR,
        INVALID_CLOSE_AMOUNT_REQUESTED,
        INVALID_COLLATERAL_FACTOR,
        MATH_ERROR,
        MARKET_NOT_FRESH,
        MARKET_NOT_LISTED,
        TOKEN_INSUFFICIENT_ALLOWANCE,
        TOKEN_INSUFFICIENT_BALANCE,
        TOKEN_INSUFFICIENT_CASH,
        TOKEN_TRANSFER_IN_FAILED,
        TOKEN_TRANSFER_OUT_FAILED
    }

    /*
     * Note: FailureInfo (but not Error) is kept in alphabetical order
     *       This is because FailureInfo grows significantly faster, and
     *       the order of Error has some meaning, while the order of FailureInfo
     *       is entirely arbitrary.
     */
    enum FailureInfo {
        ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
        ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED,
        ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED,
        ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED,
        ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED,
        ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED,
        ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED,
        BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
        BORROW_ACCRUE_INTEREST_FAILED,
        BORROW_CASH_NOT_AVAILABLE,
        BORROW_FRESHNESS_CHECK,
        BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,
        BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,
        BORROW_MARKET_NOT_LISTED,
        BORROW_CONTROLLER_REJECTION,
        LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED,
        LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED,
        LIQUIDATE_COLLATERAL_FRESHNESS_CHECK,
        LIQUIDATE_CONTROLLER_REJECTION,
        LIQUIDATE_CONTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED,
        LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX,
        LIQUIDATE_CLOSE_AMOUNT_IS_ZERO,
        LIQUIDATE_FRESHNESS_CHECK,
        LIQUIDATE_LIQUIDATOR_IS_BORROWER,
        LIQUIDATE_REPAY_BORROW_FRESH_FAILED,
        LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED,
        LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED,
        LIQUIDATE_SEIZE_CONTROLLER_REJECTION,
        LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER,
        LIQUIDATE_SEIZE_TOO_MUCH,
        MINT_ACCRUE_INTEREST_FAILED,
        MINT_CONTROLLER_REJECTION,
        MINT_EXCHANGE_CALCULATION_FAILED,
        MINT_EXCHANGE_RATE_READ_FAILED,
        MINT_FRESHNESS_CHECK,
        MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,
        MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,
        MINT_TRANSFER_IN_FAILED,
        MINT_TRANSFER_IN_NOT_POSSIBLE,
        REDEEM_ACCRUE_INTEREST_FAILED,
        REDEEM_CONTROLLER_REJECTION,
        REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED,
        REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED,
        REDEEM_EXCHANGE_RATE_READ_FAILED,
        REDEEM_FRESHNESS_CHECK,
        REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,
        REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,
        REDEEM_TRANSFER_OUT_NOT_POSSIBLE,
        REDUCE_RESERVES_ACCRUE_INTEREST_FAILED,
        REDUCE_RESERVES_ADMIN_CHECK,
        REDUCE_RESERVES_CASH_NOT_AVAILABLE,
        REDUCE_RESERVES_FRESH_CHECK,
        REDUCE_RESERVES_VALIDATION,
        REPAY_BEHALF_ACCRUE_INTEREST_FAILED,
        REPAY_BORROW_ACCRUE_INTEREST_FAILED,
        REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
        REPAY_BORROW_CONTROLLER_REJECTION,
        REPAY_BORROW_FRESHNESS_CHECK,
        REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,
        REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,
        REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE,
        SET_COLLATERAL_FACTOR_OWNER_CHECK,
        SET_COLLATERAL_FACTOR_VALIDATION,
        SET_CONTROLLER_OWNER_CHECK,
        SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED,
        SET_INTEREST_RATE_MODEL_FRESH_CHECK,
        SET_INTEREST_RATE_MODEL_OWNER_CHECK,
        SET_MAX_ASSETS_OWNER_CHECK,
        SET_ORACLE_MARKET_NOT_LISTED,
        SET_PENDING_ADMIN_OWNER_CHECK,
        SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED,
        SET_RESERVE_FACTOR_ADMIN_CHECK,
        SET_RESERVE_FACTOR_FRESH_CHECK,
        SET_RESERVE_FACTOR_BOUNDS_CHECK,
        TRANSFER_CONTROLLER_REJECTION,
        TRANSFER_NOT_ALLOWED,
        TRANSFER_NOT_ENOUGH,
        TRANSFER_TOO_MUCH,
        ADD_RESERVES_ACCRUE_INTEREST_FAILED,
        ADD_RESERVES_FRESH_CHECK,
        ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE,
        SET_NEW_IMPLEMENTATION
    }

    /**
      * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
      * contract-specific code that enables us to report opaque error codes from upgradeable contracts.
      **/
    event Failure(uint error, uint info, uint detail);

    /**
      * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
      */
    function fail(Error err, FailureInfo info) internal returns (uint) {
        emit Failure(uint(err), uint(info), 0);

        return uint(err);
    }

    /**
      * @dev use this when reporting an opaque error from an upgradeable collaborator contract
      */
    function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) {
        emit Failure(uint(err), uint(info), opaqueError);

        return uint(err);
    }
}

contract OracleErrorReporter {
    enum Error {
        NO_ERROR,
        POOL_OR_COIN_EXIST,
        UNAUTHORIZED,
        UPDATE_PRICE
    }

    enum FailureInfo {
        ADD_POOL_OR_COIN,
        NO_PAIR,
        NO_RESERVES,
        PERIOD_NOT_ELAPSED,
        SET_NEW_IMPLEMENTATION,
        UPDATE_DATA
    }

    /**
      * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
      * contract-specific code that enables us to report opaque error codes from upgradeable contracts.
      **/
    event Failure(uint error, uint info, uint detail);

    /**
      * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
      */
    function fail(Error err, FailureInfo info) internal returns (uint) {
        emit Failure(uint(err), uint(info), 0);

        return uint(err);
    }
}

contract FactoryErrorReporter {
    enum Error {
        NO_ERROR,
        INVALID_POOL,
        MARKET_NOT_LISTED,
        UNAUTHORIZED
    }

    enum FailureInfo {
        ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
        CREATE_PETH_POOL,
        CREATE_PPIE_POOL,
        DEFICIENCY_LIQUIDITY_IN_POOL_OR_PAIR_IS_NOT_EXIST,
        SET_MIN_LIQUIDITY_OWNER_CHECK,
        SET_NEW_CONTROLLER,
        SET_NEW_DECIMALS,
        SET_NEW_EXCHANGE_RATE,
        SET_NEW_IMPLEMENTATION,
        SET_NEW_INTEREST_RATE_MODEL,
        SET_NEW_ORACLE,
        SET_NEW_RESERVE_FACTOR,
        SET_PENDING_ADMIN_OWNER_CHECK,
        SUPPORT_MARKET_BAD_RESULT
    }

    /**
      * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
      * contract-specific code that enables us to report opaque error codes from upgradeable contracts.
      **/
    event Failure(uint error, uint info, uint detail);

    /**
      * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
      */
    function fail(Error err, FailureInfo info) internal returns (uint) {
        emit Failure(uint(err), uint(info), 0);

        return uint(err);
    }
}

contract RegistryErrorReporter {
    enum Error {
        NO_ERROR,
        UNAUTHORIZED
    }

    enum FailureInfo {
        ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
        SET_NEW_IMPLEMENTATION,
        SET_PENDING_ADMIN_OWNER_CHECK,
        SET_NEW_FACTORY
    }

    /**
      * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
      * contract-specific code that enables us to report opaque error codes from upgradeable contracts.
      **/
    event Failure(uint error, uint info, uint detail);

    /**
      * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
      */
    function fail(Error err, FailureInfo info) internal returns (uint) {
        emit Failure(uint(err), uint(info), 0);

        return uint(err);
    }
}

File 7 of 14 : Exponential.sol
pragma solidity ^0.7.6;

import "./CarefulMath.sol";

/**
 * @title Exponential module for storing fixed-precision decimals
 * @author DeFiPie
 * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places.
 *         Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is:
 *         `Exp({mantissa: 5100000000000000000})`.
 */
contract Exponential is CarefulMath {
    uint constant expScale = 1e18;
    uint constant doubleScale = 1e36;
    uint constant halfExpScale = expScale/2;
    uint constant mantissaOne = expScale;

    struct Exp {
        uint mantissa;
    }

    struct Double {
        uint mantissa;
    }

    /**
     * @dev Creates an exponential from numerator and denominator values.
     *      Note: Returns an error if (`num` * 10e18) > MAX_INT,
     *            or if `denom` is zero.
     */
    function getExp(uint num, uint denom) pure internal returns (MathError, Exp memory) {
        (MathError err0, uint scaledNumerator) = mulUInt(num, expScale);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        (MathError err1, uint rational) = divUInt(scaledNumerator, denom);
        if (err1 != MathError.NO_ERROR) {
            return (err1, Exp({mantissa: 0}));
        }

        return (MathError.NO_ERROR, Exp({mantissa: rational}));
    }

    /**
     * @dev Adds two exponentials, returning a new exponential.
     */
    function addExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
        (MathError error, uint result) = addUInt(a.mantissa, b.mantissa);

        return (error, Exp({mantissa: result}));
    }

    /**
     * @dev Subtracts two exponentials, returning a new exponential.
     */
    function subExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
        (MathError error, uint result) = subUInt(a.mantissa, b.mantissa);

        return (error, Exp({mantissa: result}));
    }

    /**
     * @dev Multiply an Exp by a scalar, returning a new Exp.
     */
    function mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {
        (MathError err0, uint scaledMantissa) = mulUInt(a.mantissa, scalar);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa}));
    }

    /**
     * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.
     */
    function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) {
        (MathError err, Exp memory product) = mulScalar(a, scalar);
        if (err != MathError.NO_ERROR) {
            return (err, 0);
        }

        return (MathError.NO_ERROR, truncate(product));
    }

    /**
     * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.
     */
    function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (MathError, uint) {
        (MathError err, Exp memory product) = mulScalar(a, scalar);
        if (err != MathError.NO_ERROR) {
            return (err, 0);
        }

        return addUInt(truncate(product), addend);
    }

    /**
     * @dev Divide an Exp by a scalar, returning a new Exp.
     */
    function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {
        (MathError err0, uint descaledMantissa) = divUInt(a.mantissa, scalar);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa}));
    }

    /**
     * @dev Divide a scalar by an Exp, returning a new Exp.
     */
    function divScalarByExp(uint scalar, Exp memory divisor) pure internal returns (MathError, Exp memory) {
        /*
          We are doing this as:
          getExp(mulUInt(expScale, scalar), divisor.mantissa)

          How it works:
          Exp = a / b;
          Scalar = s;
          `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`
        */
        (MathError err0, uint numerator) = mulUInt(expScale, scalar);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }
        return getExp(numerator, divisor.mantissa);
    }

    /**
     * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer.
     */
    function divScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) {
        (MathError err, Exp memory fraction_) = divScalarByExp(scalar, divisor);
        if (err != MathError.NO_ERROR) {
            return (err, 0);
        }

        return (MathError.NO_ERROR, truncate(fraction_));
    }

    /**
     * @dev Multiplies two exponentials, returning a new exponential.
     */
    function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {

        (MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        // We add half the scale before dividing so that we get rounding instead of truncation.
        //  See "Listing 6" and text above it at https://accu.org/index.php/journals/1717
        // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.
        (MathError err1, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct);
        if (err1 != MathError.NO_ERROR) {
            return (err1, Exp({mantissa: 0}));
        }

        (MathError err2, uint product) = divUInt(doubleScaledProductWithHalfScale, expScale);
        // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.
        assert(err2 == MathError.NO_ERROR);

        return (MathError.NO_ERROR, Exp({mantissa: product}));
    }

    /**
     * @dev Multiplies two exponentials given their mantissas, returning a new exponential.
     */
    function mulExp(uint a, uint b) pure internal returns (MathError, Exp memory) {
        return mulExp(Exp({mantissa: a}), Exp({mantissa: b}));
    }

    /**
     * @dev Multiplies three exponentials, returning a new exponential.
     */
    function mulExp3(Exp memory a, Exp memory b, Exp memory c) pure internal returns (MathError, Exp memory) {
        (MathError err, Exp memory ab) = mulExp(a, b);
        if (err != MathError.NO_ERROR) {
            return (err, ab);
        }
        return mulExp(ab, c);
    }

    /**
     * @dev Divides two exponentials, returning a new exponential.
     *     (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,
     *  which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
     */
    function divExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
        return getExp(a.mantissa, b.mantissa);
    }

    /**
     * @dev Truncates the given exp to a whole number value.
     *      For example, truncate(Exp{mantissa: 15 * expScale}) = 15
     */
    function truncate(Exp memory exp) pure internal returns (uint) {
        // Note: We are not using careful math here as we're performing a division that cannot fail
        return exp.mantissa / expScale;
    }

    /**
     * @dev Checks if first Exp is less than second Exp.
     */
    function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) {
        return left.mantissa < right.mantissa;
    }

    /**
     * @dev Checks if left Exp <= right Exp.
     */
    function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) {
        return left.mantissa <= right.mantissa;
    }

    /**
     * @dev Checks if left Exp > right Exp.
     */
    function greaterThanExp(Exp memory left, Exp memory right) pure internal returns (bool) {
        return left.mantissa > right.mantissa;
    }

    /**
     * @dev returns true if Exp is exactly zero
     */
    function isZeroExp(Exp memory value) pure internal returns (bool) {
        return value.mantissa == 0;
    }

    function safe224(uint n, string memory errorMessage) pure internal returns (uint224) {
        require(n < 2**224, errorMessage);
        return uint224(n);
    }

    function safe32(uint n, string memory errorMessage) pure internal returns (uint32) {
        require(n < 2**32, errorMessage);
        return uint32(n);
    }

    function add_(Exp memory a, Exp memory b) pure internal returns (Exp memory) {
        return Exp({mantissa: add_(a.mantissa, b.mantissa)});
    }

    function add_(Double memory a, Double memory b) pure internal returns (Double memory) {
        return Double({mantissa: add_(a.mantissa, b.mantissa)});
    }

    function add_(uint a, uint b) pure internal returns (uint) {
        return add_(a, b, "addition overflow");
    }

    function add_(uint a, uint b, string memory errorMessage) pure internal returns (uint) {
        uint c = a + b;
        require(c >= a, errorMessage);
        return c;
    }

    function sub_(Exp memory a, Exp memory b) pure internal returns (Exp memory) {
        return Exp({mantissa: sub_(a.mantissa, b.mantissa)});
    }

    function sub_(Double memory a, Double memory b) pure internal returns (Double memory) {
        return Double({mantissa: sub_(a.mantissa, b.mantissa)});
    }

    function sub_(uint a, uint b) pure internal returns (uint) {
        return sub_(a, b, "subtraction underflow");
    }

    function sub_(uint a, uint b, string memory errorMessage) pure internal returns (uint) {
        require(b <= a, errorMessage);
        return a - b;
    }

    function mul_(Exp memory a, Exp memory b) pure internal returns (Exp memory) {
        return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale});
    }

    function mul_(Exp memory a, uint b) pure internal returns (Exp memory) {
        return Exp({mantissa: mul_(a.mantissa, b)});
    }

    function mul_(uint a, Exp memory b) pure internal returns (uint) {
        return mul_(a, b.mantissa) / expScale;
    }

    function mul_(Double memory a, Double memory b) pure internal returns (Double memory) {
        return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale});
    }

    function mul_(Double memory a, uint b) pure internal returns (Double memory) {
        return Double({mantissa: mul_(a.mantissa, b)});
    }

    function mul_(uint a, Double memory b) pure internal returns (uint) {
        return mul_(a, b.mantissa) / doubleScale;
    }

    function mul_(uint a, uint b) pure internal returns (uint) {
        return mul_(a, b, "multiplication overflow");
    }

    function mul_(uint a, uint b, string memory errorMessage) pure internal returns (uint) {
        if (a == 0 || b == 0) {
            return 0;
        }
        uint c = a * b;
        require(c / a == b, errorMessage);
        return c;
    }

    function div_(Exp memory a, Exp memory b) pure internal returns (Exp memory) {
        return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)});
    }

    function div_(Exp memory a, uint b) pure internal returns (Exp memory) {
        return Exp({mantissa: div_(a.mantissa, b)});
    }

    function div_(uint a, Exp memory b) pure internal returns (uint) {
        return div_(mul_(a, expScale), b.mantissa);
    }

    function div_(Double memory a, Double memory b) pure internal returns (Double memory) {
        return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)});
    }

    function div_(Double memory a, uint b) pure internal returns (Double memory) {
        return Double({mantissa: div_(a.mantissa, b)});
    }

    function div_(uint a, Double memory b) pure internal returns (uint) {
        return div_(mul_(a, doubleScale), b.mantissa);
    }

    function div_(uint a, uint b) pure internal returns (uint) {
        return div_(a, b, "divide by zero");
    }

    function div_(uint a, uint b, string memory errorMessage) pure internal returns (uint) {
        require(b > 0, errorMessage);
        return a / b;
    }

    function fraction(uint a, uint b) pure internal returns (Double memory) {
        return Double({mantissa: div_(mul_(a, doubleScale), b)});
    }
}

File 8 of 14 : InterestRateModel.sol
pragma solidity ^0.7.6;

/**
  * @title DeFiPie's InterestRateModel Interface
  * @author DeFiPie
  */
abstract contract InterestRateModel {
    /// @notice Indicator that this is an InterestRateModel contract (for inspection)
    bool public constant isInterestRateModel = true;

    /**
      * @notice Calculates the current borrow interest rate per block
      * @param cash The total amount of cash the market has
      * @param borrows The total amount of borrows the market has outstanding
      * @param reserves The total amount of reserves the market has
      * @return The borrow rate per block (as a percentage, and scaled by 1e18)
      */
    function getBorrowRate(uint cash, uint borrows, uint reserves) external view virtual returns (uint);

    /**
      * @notice Calculates the current supply interest rate per block
      * @param cash The total amount of cash the market has
      * @param borrows The total amount of borrows the market has outstanding
      * @param reserves The total amount of reserves the market has
      * @param reserveFactorMantissa The current reserve factor the market has
      * @return The supply rate per block (as a percentage, and scaled by 1e18)
      */
    function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) external view virtual returns (uint);

}

File 9 of 14 : PPIE.sol
pragma solidity ^0.7.6;

import "./PToken.sol";
import "./RegistryInterface.sol";
import "./ProxyWithRegistry.sol";

/**
 * @title DeFiPie's PPIE Contract
 * @notice PTokens which wrap an EIP-20 underlying
 * @author DeFiPie
 */
contract PPIE is ImplementationStorage, PToken, PErc20Interface, PPIEInterface {
    /**
     * @notice Initialize the new money market
     * @param underlying_ The address of the underlying asset
     * @param registry_ The address of the Registry
     * @param controller_ The address of the Controller
     * @param interestRateModel_ The address of the interest rate model
     * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18
     * @param initialReserveFactorMantissa_ The initial reserve factor, scaled by 1e18
     * @param name_ ERC-20 name of this token
     * @param symbol_ ERC-20 symbol of this token
     * @param decimals_ ERC-20 decimal precision of this token
     */
    function initialize(
        address underlying_,
        RegistryInterface registry_,
        ControllerInterface controller_,
        InterestRateModel interestRateModel_,
        uint initialExchangeRateMantissa_,
        uint initialReserveFactorMantissa_,
        string memory name_,
        string memory symbol_,
        uint8 decimals_
    ) public {

        // PToken initialize does the bulk of the work
        super.initialize(registry_, controller_, interestRateModel_, initialExchangeRateMantissa_, initialReserveFactorMantissa_, name_, symbol_, decimals_);

        // Set underlying and sanity check it
        underlying = underlying_;
        EIP20Interface(underlying).totalSupply();
    }

    /*** User Interface ***/

    /**
     * @notice Sender supplies assets into the market and receives pTokens in exchange
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param mintAmount The amount of the underlying asset to supply
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function mint(uint mintAmount) external override returns (uint) {
        (uint err, , uint amount) = mintInternal(mintAmount);

        if (err == 0) {
            _moveDelegates(address(0), delegates[msg.sender], uint96(amount));
        }

        return err;
    }

    /**
     * @notice Sender redeems pTokens in exchange for the underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param redeemTokens The number of pTokens to redeem into underlying
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeem(uint redeemTokens) external override returns (uint) {
        (uint err, uint amount) = redeemInternal(redeemTokens);

        if (err == 0) {
            _moveDelegates(delegates[msg.sender], address(0), uint96(amount));
        }

        return err;
    }

    /**
     * @notice Sender redeems pTokens in exchange for a specified amount of underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param redeemAmount The amount of underlying to redeem
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeemUnderlying(uint redeemAmount) external override returns (uint) {
        (uint err, uint amount) = redeemUnderlyingInternal(redeemAmount);

        if (err == 0) {
            _moveDelegates(delegates[msg.sender], address(0), uint96(amount));
        }

        return err;
    }

    /**
      * @notice Sender borrows assets from the protocol to their own address
      * @param borrowAmount The amount of the underlying asset to borrow
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function borrow(uint borrowAmount) external override returns (uint) {
        return borrowInternal(borrowAmount);
    }

    /**
     * @notice Sender repays their own borrow
     * @param repayAmount The amount to repay
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function repayBorrow(uint repayAmount) external override returns (uint) {
        (uint err,) = repayBorrowInternal(repayAmount);
        return err;
    }

    /**
     * @notice Sender repays a borrow belonging to borrower
     * @param borrower the account with the debt being payed off
     * @param repayAmount The amount to repay
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function repayBorrowBehalf(address borrower, uint repayAmount) external override returns (uint) {
        (uint err,) = repayBorrowBehalfInternal(borrower, repayAmount);
        return err;
    }

    /**
     * @notice The sender liquidates the borrowers collateral.
     *  The collateral seized is transferred to the liquidator.
     * @param borrower The borrower of this pToken to be liquidated
     * @param repayAmount The amount of the underlying borrowed asset to repay
     * @param pTokenCollateral The market in which to seize collateral from the borrower
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function liquidateBorrow(address borrower, uint repayAmount, PTokenInterface pTokenCollateral) external override returns (uint) {
        (uint err,) = liquidateBorrowInternal(borrower, repayAmount, pTokenCollateral);

        return err;
    }

    /**
     * @notice Transfers collateral tokens (this market) to the liquidator.
     * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another PToken.
     *  Its absolutely critical to use msg.sender as the seizer pToken and not a parameter.
     * @param seizerToken The contract seizing the collateral (i.e. borrowed pToken)
     * @param liquidator The account receiving seized collateral
     * @param borrower The account having collateral seized
     * @param seizeTokens The number of pTokens to seize
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal override returns (uint) {
        uint err = super.seizeInternal(seizerToken, liquidator, borrower, seizeTokens);

        if (err == 0) {
            _moveDelegates(delegates[borrower], delegates[liquidator], uint96(seizeTokens));
        }

        return err;
    }
    /**
     * @notice The sender adds to reserves.
     * @param addAmount The amount fo underlying token to add as reserves
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _addReserves(uint addAmount) external override returns (uint) {
        return _addReservesInternal(addAmount);
    }

    /*** Safe Token ***/

    /**
     * @notice Gets balance of this contract in terms of the underlying
     * @dev This excludes the value of the current message, if any
     * @return The quantity of underlying tokens owned by this contract
     */
    function getCashPrior() internal view override returns (uint) {
        EIP20Interface token = EIP20Interface(underlying);
        return token.balanceOf(address(this));
    }

    /**
     * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case.
     *      This will revert due to insufficient balance or insufficient allowance.
     *      This function returns the actual amount received,
     *      which may be less than `amount` if there is a fee attached to the transfer.
     *
     *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.
     *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
     */
    function doTransferIn(address from, uint amount) internal override returns (uint) {
        EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);
        uint balanceBefore = EIP20Interface(underlying).balanceOf(address(this));
        token.transferFrom(from, address(this), amount);

        bool success;
        assembly {
            switch returndatasize()
            case 0 {                       // This is a non-standard ERC-20
                success := not(0)          // set success to true
            }
            case 32 {                      // This is a compliant ERC-20
                returndatacopy(0, 0, 32)
                success := mload(0)        // Set `success = returndata` of external call
            }
            default {                      // This is an excessively non-compliant ERC-20, revert.
                revert(0, 0)
            }
        }
        require(success, "TOKEN_TRANSFER_IN_FAILED");

        // Calculate the amount that was *actually* transferred
        uint balanceAfter = EIP20Interface(underlying).balanceOf(address(this));
        require(balanceAfter >= balanceBefore, "TOKEN_TRANSFER_IN_OVERFLOW");
        return balanceAfter - balanceBefore;   // underflow already checked above, just subtract
    }

    /**
     * @dev Similar to EIP20 transfer, except it handles a False success from `transfer` and returns an explanatory
     *      error code rather than reverting. If caller has not called checked protocol's balance, this may revert due to
     *      insufficient cash held in this contract. If caller has checked protocol's balance prior to this call, and verified
     *      it is >= amount, this should not revert in normal conditions.
     *
     *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.
     *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
     */
    function doTransferOut(address payable to, uint amount) internal virtual override {
        EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);
        token.transfer(to, amount);

        bool success;
        assembly {
            switch returndatasize()
            case 0 {                      // This is a non-standard ERC-20
                success := not(0)          // set success to true
            }
            case 32 {                     // This is a complaint ERC-20
                returndatacopy(0, 0, 32)
                success := mload(0)        // Set `success = returndata` of external call
            }
            default {                     // This is an excessively non-compliant ERC-20, revert.
                revert(0, 0)
            }
        }
        require(success, "TOKEN_TRANSFER_OUT_FAILED");
    }

    /**
     * @notice Transfer `amount` tokens from `msg.sender` to `dst`
     * @param dst The address of the destination account
     * @param amount The number of tokens to transfer
     * @return Whether or not the transfer succeeded
     */
    function transfer(address dst, uint256 amount) external override nonReentrant returns (bool) {
        if (transferTokens(msg.sender, msg.sender, dst, amount) != uint(Error.NO_ERROR)) {
            return false;
        }

        _moveDelegates(delegates[msg.sender], delegates[dst], uint96(amount));
        return true;
    }

    /**
     * @notice Transfer `amount` tokens from `src` to `dst`
     * @param src The address of the source account
     * @param dst The address of the destination account
     * @param amount The number of tokens to transfer
     * @return Whether or not the transfer succeeded
     */
    function transferFrom(address src, address dst, uint256 amount) external override nonReentrant returns (bool) {
        if (transferTokens(msg.sender, src, dst, amount) != uint(Error.NO_ERROR)) {
            return false;
        }

        _moveDelegates(delegates[src], delegates[dst], uint96(amount));
        return true;
    }

    /**
     * @notice Delegate votes from `msg.sender` to `delegatee`
     * @param delegatee The address to delegate votes to
     */
    function delegate(address delegatee) external override {
        _delegate(msg.sender, delegatee);
    }

   /**
    * @notice Delegates votes from signatory to `delegatee`
    * @param delegatee The address to delegate votes to
    * @param nonce The contract state required to match the signature
    * @param expiry The time at which to expire the signature
    * @param v The recovery byte of the signature
    * @param r Half of the ECDSA signature pair
    * @param s Half of the ECDSA signature pair
    */
   function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external override {
       bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this)));
       bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));
       bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
       address signatory = ecrecover(digest, v, r, s);
       require(signatory != address(0), "PPie::delegateBySig: invalid signature");
       require(nonce == nonces[signatory]++, "PPie::delegateBySig: invalid nonce");
       require(block.timestamp <= expiry, "PPie::delegateBySig: signature expired");
       _delegate(signatory, delegatee);
   }

    /**
     * @notice Gets the current votes balance for `account`
     * @param account The address to get votes balance
     * @return The number of current votes for `account`
     */
    function getCurrentVotes(address account) external view override returns (uint96) {
        uint32 nCheckpoints = numCheckpoints[account];
        return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
    }

    /**
     * @notice Determine the prior number of votes for an account as of a block number
     * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
     * @param account The address of the account to check
     * @param blockNumber The block number to get the vote balance at
     * @return The number of votes the account had as of the given block
     */
    function getPriorVotes(address account, uint blockNumber) external view override returns (uint96) {
        require(blockNumber < block.number, "PPie::getPriorVotes: not yet determined");

        uint32 nCheckpoints = numCheckpoints[account];
        if (nCheckpoints == 0) {
            return 0;
        }

        // First check most recent balance
        if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
            return checkpoints[account][nCheckpoints - 1].votes;
        }

        // Next check implicit zero balance
        if (checkpoints[account][0].fromBlock > blockNumber) {
            return 0;
        }

        uint32 lower = 0;
        uint32 upper = nCheckpoints - 1;
        while (upper > lower) {
            uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
            Checkpoint memory cp = checkpoints[account][center];
            if (cp.fromBlock == blockNumber) {
                return cp.votes;
            } else if (cp.fromBlock < blockNumber) {
                lower = center;
            } else {
                upper = center - 1;
            }
        }
        return checkpoints[account][lower].votes;
    }

    function _delegate(address delegator, address delegatee) internal {
        address currentDelegate = delegates[delegator];
        uint96 delegatorBalance = uint96(accountTokens[delegator]);
        delegates[delegator] = delegatee;

        emit DelegateChanged(delegator, currentDelegate, delegatee);

        _moveDelegates(currentDelegate, delegatee, delegatorBalance);
    }

    function _moveDelegates(address srcRep, address dstRep, uint96 amount) internal {
        if (srcRep != dstRep && amount > 0) {
            if (srcRep != address(0)) {
                uint32 srcRepNum = numCheckpoints[srcRep];
                uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
                uint96 srcRepNew = sub96(srcRepOld, amount, "PPie::_moveVotes: vote amount underflows");
                _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
            }

            if (dstRep != address(0)) {
                uint32 dstRepNum = numCheckpoints[dstRep];
                uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
                uint96 dstRepNew = add96(dstRepOld, amount, "PPie::_moveVotes: vote amount overflows");
                _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
            }
        }
    }

    function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint96 oldVotes, uint96 newVotes) internal {
        uint32 blockNumber = safe32(block.number, "PPie::_writeCheckpoint: block number exceeds 32 bits");

        if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
            checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
        } else {
            checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
            numCheckpoints[delegatee] = nCheckpoints + 1;
        }

        emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
    }

    function add96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) {
        uint96 c = a + b;
        require(c >= a, errorMessage);
        return c;
    }

    function sub96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) {
        require(b <= a, errorMessage);
        return a - b;
    }

   function getChainId() internal pure returns (uint) {
       uint256 chainId;
       assembly { chainId := chainid() }
       return chainId;
   }
}

File 10 of 14 : PToken.sol
pragma solidity ^0.7.6;

import "./ControllerInterface.sol";
import "./PTokenInterfaces.sol";
import "./ErrorReporter.sol";
import "./Exponential.sol";
import "./EIP20Interface.sol";
import "./EIP20NonStandardInterface.sol";
import "./InterestRateModel.sol";
import "./RegistryInterface.sol";
import "./PriceOracle.sol";

/**
 * @title DeFiPie's PToken Contract
 * @notice Abstract base for PTokens
 * @author DeFiPie
 */
abstract contract PToken is PTokenInterface, Exponential, TokenErrorReporter {

    /**
     * @notice Initialize the money market
     * @param registry_ The address of the Registry
     * @param controller_ The address of the Controller
     * @param interestRateModel_ The address of the interest rate model
     * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18
     * @param name_ EIP-20 name of this token
     * @param symbol_ EIP-20 symbol of this token
     * @param decimals_ EIP-20 decimal precision of this token
     */
    function initialize(
        RegistryInterface registry_,
        ControllerInterface controller_,
        InterestRateModel interestRateModel_,
        uint initialExchangeRateMantissa_,
        uint initialReserveFactorMantissa_,
        string memory name_,
        string memory symbol_,
        uint8 decimals_
    )
        public virtual
    {
        require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once");

        registry = address(registry_);

        // Set initial exchange rate
        initialExchangeRateMantissa = initialExchangeRateMantissa_;
        require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero.");

        reserveFactorMantissa = initialReserveFactorMantissa_;

        // Set the controller
        uint err = _setControllerInternal(controller_);
        require(err == uint(Error.NO_ERROR), "setting controller failed");

        // Initialize block number and borrow index (block number mocks depend on controller being set)
        accrualBlockNumber = getBlockNumber();
        borrowIndex = mantissaOne;

        // Set the interest rate model (depends on block number / borrow index)
        err = _setInterestRateModelFreshInternal(interestRateModel_);
        require(err == uint(Error.NO_ERROR), "setting interest rate model failed");

        name = name_;
        symbol = symbol_;
        decimals = decimals_;

        // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund)
        _notEntered = true;
    }

    /**
     * @notice Transfer `tokens` tokens from `src` to `dst` by `spender`
     * @dev Called by both `transfer` and `transferFrom` internally
     * @param spender The address of the account performing the transfer
     * @param src The address of the source account
     * @param dst The address of the destination account
     * @param tokens The number of tokens to transfer
     * @return Whether or not the transfer succeeded
     */
    function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint) {
        /* Fail if transfer not allowed */
        uint allowed = controller.transferAllowed(address(this), src, dst, tokens);
        if (allowed != 0) {
            return failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.TRANSFER_CONTROLLER_REJECTION, allowed);
        }

        /* Do not allow self-transfers */
        if (src == dst) {
            return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED);
        }

        /* Get the allowance, infinite for the account owner */
        uint startingAllowance = 0;
        if (spender == src) {
            startingAllowance = uint(-1);
        } else {
            startingAllowance = transferAllowances[src][spender];
        }

        /* Do the calculations, checking for {under,over}flow */
        MathError mathErr;
        uint allowanceNew;
        uint srcTokensNew;
        uint dstTokensNew;

        (mathErr, allowanceNew) = subUInt(startingAllowance, tokens);
        if (mathErr != MathError.NO_ERROR) {
            return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ALLOWED);
        }

        (mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens);
        if (mathErr != MathError.NO_ERROR) {
            return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ENOUGH);
        }

        (mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens);
        if (mathErr != MathError.NO_ERROR) {
            return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_TOO_MUCH);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        accountTokens[src] = srcTokensNew;
        accountTokens[dst] = dstTokensNew;

        /* Eat some of the allowance (if necessary) */
        if (startingAllowance != uint(-1)) {
            transferAllowances[src][spender] = allowanceNew;
        }

        /* We emit a Transfer event */
        emit Transfer(src, dst, tokens);

        return uint(Error.NO_ERROR);
    }

    /**
     * @notice Transfer `amount` tokens from `msg.sender` to `dst`
     * @param dst The address of the destination account
     * @param amount The number of tokens to transfer
     * @return Whether or not the transfer succeeded
     */
    function transfer(address dst, uint256 amount) external override virtual nonReentrant returns (bool) {
        return transferTokens(msg.sender, msg.sender, dst, amount) == uint(Error.NO_ERROR);
    }

    /**
     * @notice Transfer `amount` tokens from `src` to `dst`
     * @param src The address of the source account
     * @param dst The address of the destination account
     * @param amount The number of tokens to transfer
     * @return Whether or not the transfer succeeded
     */
    function transferFrom(address src, address dst, uint256 amount) external override virtual nonReentrant returns (bool) {
        return transferTokens(msg.sender, src, dst, amount) == uint(Error.NO_ERROR);
    }

    /**
     * @notice Approve `spender` to transfer up to `amount` from `src`
     * @dev This will overwrite the approval amount for `spender`
     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
     * @param spender The address of the account which may transfer tokens
     * @param amount The number of tokens that are approved (-1 means infinite)
     * @return Whether or not the approval succeeded
     */
    function approve(address spender, uint256 amount) external override returns (bool) {
        address src = msg.sender;
        transferAllowances[src][spender] = amount;
        emit Approval(src, spender, amount);
        return true;
    }

    /**
     * @notice Get the current allowance from `owner` for `spender`
     * @param owner The address of the account which owns the tokens to be spent
     * @param spender The address of the account which may transfer tokens
     * @return The number of tokens allowed to be spent (-1 means infinite)
     */
    function allowance(address owner, address spender) external view override returns (uint256) {
        return transferAllowances[owner][spender];
    }

    /**
     * @notice Get the token balance of the `owner`
     * @param owner The address of the account to query
     * @return The number of tokens owned by `owner`
     */
    function balanceOf(address owner) external view override returns (uint256) {
        return accountTokens[owner];
    }

    /**
     * @notice Get the underlying balance of the `owner`
     * @dev This also accrues interest in a transaction
     * @param owner The address of the account to query
     * @return The amount of underlying owned by `owner`
     */
    function balanceOfUnderlying(address owner) external override returns (uint) {
        Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()});
        (MathError mErr, uint balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]);
        require(mErr == MathError.NO_ERROR, "balance could not be calculated");
        return balance;
    }

    /**
     * @notice Get a snapshot of the account's balances, and the cached exchange rate
     * @dev This is used by controller to more efficiently perform liquidity checks.
     * @param account Address of the account to snapshot
     * @return (possible error, token balance, borrow balance, exchange rate mantissa)
     */
    function getAccountSnapshot(address account) external view override returns (uint, uint, uint, uint) {
        uint pTokenBalance = accountTokens[account];
        uint borrowBalance;
        uint exchangeRateMantissa;

        MathError mErr;

        (mErr, borrowBalance) = borrowBalanceStoredInternal(account);
        if (mErr != MathError.NO_ERROR) {
            return (uint(Error.MATH_ERROR), 0, 0, 0);
        }

        (mErr, exchangeRateMantissa) = exchangeRateStoredInternal();
        if (mErr != MathError.NO_ERROR) {
            return (uint(Error.MATH_ERROR), 0, 0, 0);
        }

        return (uint(Error.NO_ERROR), pTokenBalance, borrowBalance, exchangeRateMantissa);
    }

    function getBorrowSnapshot(address account) external view returns(uint, uint) {
        return (accountBorrows[account].principal, accountBorrows[account].interestIndex);
    }
    

    /**
     * @dev Function to simply retrieve block number
     *  This exists mainly for inheriting test contracts to stub this result.
     */
    function getBlockNumber() internal view virtual returns (uint) {
        return block.number;
    }

    /**
     * @notice Returns the current per-block borrow interest rate for this pToken
     * @return The borrow interest rate per block, scaled by 1e18
     */
    function borrowRatePerBlock() external view override returns (uint) {
        return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);
    }

    /**
     * @notice Returns the current per-block supply interest rate for this pToken
     * @return The supply interest rate per block, scaled by 1e18
     */
    function supplyRatePerBlock() external view override returns (uint) {
        return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa);
    }

    /**
     * @notice Returns the current total borrows plus accrued interest
     * @return The total borrows with interest
     */
    function totalBorrowsCurrent() external override nonReentrant returns (uint) {
        require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed");
        return totalBorrows;
    }

    /**
     * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex
     * @param account The address whose balance should be calculated after updating borrowIndex
     * @return The calculated balance
     */
    function borrowBalanceCurrent(address account) external override nonReentrant returns (uint) {
        require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed");
        return borrowBalanceStored(account);
    }

    /**
     * @notice Return the borrow balance of account based on stored data
     * @param account The address whose balance should be calculated
     * @return The calculated balance
     */
    function borrowBalanceStored(address account) public view override returns (uint) {
        (MathError err, uint result) = borrowBalanceStoredInternal(account);
        require(err == MathError.NO_ERROR, "borrowBalanceStored: borrowBalanceStoredInternal failed");
        return result;
    }

    /**
     * @notice Return the borrow balance of account based on stored data
     * @param account The address whose balance should be calculated
     * @return (error code, the calculated balance or 0 if error code is non-zero)
     */
    function borrowBalanceStoredInternal(address account) internal view returns (MathError, uint) {
        /* Note: we do not assert that the market is up to date */
        MathError mathErr;
        uint principalTimesIndex;
        uint result;

        /* Get borrowBalance and borrowIndex */
        BorrowSnapshot storage borrowSnapshot = accountBorrows[account];

        /* If borrowBalance = 0 then borrowIndex is likely also 0.
         * Rather than failing the calculation with a division by 0, we immediately return 0 in this case.
         */
        if (borrowSnapshot.principal == 0) {
            return (MathError.NO_ERROR, 0);
        }

        /* Calculate new borrow balance using the interest index:
         *  recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex
         */
        (mathErr, principalTimesIndex) = mulUInt(borrowSnapshot.principal, borrowIndex);
        if (mathErr != MathError.NO_ERROR) {
            return (mathErr, 0);
        }

        (mathErr, result) = divUInt(principalTimesIndex, borrowSnapshot.interestIndex);
        if (mathErr != MathError.NO_ERROR) {
            return (mathErr, 0);
        }

        return (MathError.NO_ERROR, result);
    }

    /**
     * @notice Accrue interest then return the up-to-date exchange rate
     * @return Calculated exchange rate scaled by 1e18
     */
    function exchangeRateCurrent() public override nonReentrant returns (uint) {
        require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed");
        return exchangeRateStored();
    }

    /**
     * @notice Calculates the exchange rate from the underlying to the PToken
     * @dev This function does not accrue interest before calculating the exchange rate
     * @return Calculated exchange rate scaled by 1e18
     */
    function exchangeRateStored() public view override returns (uint) {
        (MathError err, uint result) = exchangeRateStoredInternal();
        require(err == MathError.NO_ERROR, "exchangeRateStored: exchangeRateStoredInternal failed");
        return result;
    }

    /**
     * @notice Calculates the exchange rate from the underlying to the PToken
     * @dev This function does not accrue interest before calculating the exchange rate
     * @return (error code, calculated exchange rate scaled by 1e18)
     */
    function exchangeRateStoredInternal() internal view virtual returns (MathError, uint) {
        uint _totalSupply = totalSupply;
        if (_totalSupply == 0) {
            /*
             * If there are no tokens minted:
             *  exchangeRate = initialExchangeRate
             */
            return (MathError.NO_ERROR, initialExchangeRateMantissa);
        } else {
            /*
             * Otherwise:
             *  exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
             */
            uint totalCash = getCashPrior();
            uint cashPlusBorrowsMinusReserves;
            Exp memory exchangeRate;
            MathError mathErr;

            (mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt(totalCash, totalBorrows, totalReserves);
            if (mathErr != MathError.NO_ERROR) {
                return (mathErr, 0);
            }

            (mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, _totalSupply);
            if (mathErr != MathError.NO_ERROR) {
                return (mathErr, 0);
            }

            return (MathError.NO_ERROR, exchangeRate.mantissa);
        }
    }

    /**
     * @notice Get cash balance of this pToken in the underlying asset
     * @return The quantity of underlying asset owned by this contract
     */
    function getCash() external view override returns (uint) {
        return getCashPrior();
    }

    /**
     * @notice Applies accrued interest to total borrows and reserves
     * @dev This calculates interest accrued from the last checkpointed block
     *   up to the current block and writes new checkpoint to storage.
     */
    function accrueInterest() public override returns (uint) {
        controller.getOracle().updateUnderlyingPrice(address(this));

        /* Remember the initial block number */
        uint currentBlockNumber = getBlockNumber();
        uint accrualBlockNumberPrior = accrualBlockNumber;

        /* Short-circuit accumulating 0 interest */
        if (accrualBlockNumberPrior == currentBlockNumber) {
            return uint(Error.NO_ERROR);
        }

        /* Read the previous values out of storage */
        uint cashPrior = getCashPrior();
        uint borrowsPrior = totalBorrows;
        uint reservesPrior = totalReserves;
        uint borrowIndexPrior = borrowIndex;

        /* Calculate the current borrow interest rate */
        uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior);
        require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high");

        /* Calculate the number of blocks elapsed since the last accrual */
        (MathError mathErr, uint blockDelta) = subUInt(currentBlockNumber, accrualBlockNumberPrior);
        require(mathErr == MathError.NO_ERROR, "could not calculate block delta");

        /*
         * Calculate the interest accumulated into borrows and reserves and the new index:
         *  simpleInterestFactor = borrowRate * blockDelta
         *  interestAccumulated = simpleInterestFactor * totalBorrows
         *  totalBorrowsNew = interestAccumulated + totalBorrows
         *  totalReservesNew = interestAccumulated * reserveFactor + totalReserves
         *  borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
         */

        Exp memory simpleInterestFactor;
        uint interestAccumulated;
        uint totalBorrowsNew;
        uint totalReservesNew;
        uint borrowIndexNew;

        (mathErr, simpleInterestFactor) = mulScalar(Exp({mantissa: borrowRateMantissa}), blockDelta);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, uint(mathErr));
        }

        (mathErr, interestAccumulated) = mulScalarTruncate(simpleInterestFactor, borrowsPrior);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED, uint(mathErr));
        }

        (mathErr, totalBorrowsNew) = addUInt(interestAccumulated, borrowsPrior);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, uint(mathErr));
        }

        (mathErr, totalReservesNew) = mulScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, uint(mathErr));
        }

        (mathErr, borrowIndexNew) = mulScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, uint(mathErr));
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /* We write the previously calculated values into storage */
        accrualBlockNumber = currentBlockNumber;
        borrowIndex = borrowIndexNew;
        totalBorrows = totalBorrowsNew;
        totalReserves = totalReservesNew;

        /* We emit an AccrueInterest event */
        emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew, totalReservesNew);

        return uint(Error.NO_ERROR);
    }

    /**
     * @notice Sender supplies assets into the market and receives pTokens in exchange
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param mintAmount The amount of the underlying asset to supply
     * @return (uint, uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), the actual mint amount, and actual mint tokens.
     */
    function mintInternal(uint mintAmount) internal nonReentrant returns (uint, uint, uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
            return (fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED), 0, 0);
        }
        // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to
        return mintFresh(msg.sender, mintAmount);
    }

    struct MintLocalVars {
        Error err;
        MathError mathErr;
        uint exchangeRateMantissa;
        uint mintTokens;
        uint totalSupplyNew;
        uint accountTokensNew;
        uint actualMintAmount;
    }

    /**
     * @notice User supplies assets into the market and receives pTokens in exchange
     * @dev Assumes interest has already been accrued up to the current block
     * @param minter The address of the account which is supplying the assets
     * @param mintAmount The amount of the underlying asset to supply
     * @return (uint, uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), the actual mint amount, and actual mint tokens.
     */
    function mintFresh(address minter, uint mintAmount) internal returns (uint, uint, uint) {
        /* Fail if mint not allowed */
        uint allowed = controller.mintAllowed(address(this), minter, mintAmount);
        if (allowed != 0) {
            return (failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.MINT_CONTROLLER_REJECTION, allowed), 0, 0);
        }

        /* Verify market's block number equals current block number */
        if (accrualBlockNumber != getBlockNumber()) {
            return (fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK), 0, 0);
        }

        MintLocalVars memory vars;

        (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal();
        if (vars.mathErr != MathError.NO_ERROR) {
            return (failOpaque(Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr)), 0, 0);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /*
         *  We call `doTransferIn` for the minter and the mintAmount.
         *  Note: The pToken must handle variations between ERC-20 and ETH underlying.
         *  `doTransferIn` reverts if anything goes wrong, since we can't be sure if
         *  side-effects occurred. The function returns the amount actually transferred,
         *  in case of a fee. On success, the pToken holds an additional `actualMintAmount`
         *  of cash.
         */
        vars.actualMintAmount = doTransferIn(minter, mintAmount);

        /*
         * We get the current exchange rate and calculate the number of pTokens to be minted:
         *  mintTokens = actualMintAmount / exchangeRate
         */
        (vars.mathErr, vars.mintTokens) = divScalarByExpTruncate(vars.actualMintAmount, Exp({mantissa: vars.exchangeRateMantissa}));
        require(vars.mathErr == MathError.NO_ERROR, "MINT_EXCHANGE_CALCULATION_FAILED");

        /*
         * We calculate the new total supply of pTokens and minter token balance, checking for overflow:
         *  totalSupplyNew = totalSupply + mintTokens
         *  accountTokensNew = accountTokens[minter] + mintTokens
         */
        (vars.mathErr, vars.totalSupplyNew) = addUInt(totalSupply, vars.mintTokens);
        require(vars.mathErr == MathError.NO_ERROR, "MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED");

        (vars.mathErr, vars.accountTokensNew) = addUInt(accountTokens[minter], vars.mintTokens);
        require(vars.mathErr == MathError.NO_ERROR, "MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED");

        /* We write previously calculated values into storage */
        totalSupply = vars.totalSupplyNew;
        accountTokens[minter] = vars.accountTokensNew;

        /* We emit a Mint event, and a Transfer event */
        emit Mint(minter, vars.actualMintAmount, vars.mintTokens);
        emit Transfer(address(this), minter, vars.mintTokens);

        return (uint(Error.NO_ERROR), vars.actualMintAmount, vars.mintTokens);
    }

    /**
     * @notice Sender redeems PTokens in exchange for the underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param redeemTokens The number of pTokens to redeem into underlying
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the redeem tokens amount.
     */
    function redeemInternal(uint redeemTokens) internal nonReentrant returns (uint, uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed
            return (fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED), 0);
        }
        // redeemFresh emits redeem-specific logs on errors, so we don't need to
        return redeemFresh(msg.sender, redeemTokens, 0);
    }

    /**
     * @notice Sender redeems pTokens in exchange for a specified amount of underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param redeemAmount The amount of underlying to receive from redeeming pTokens
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the redeem tokens amount.
     */
    function redeemUnderlyingInternal(uint redeemAmount) internal nonReentrant returns (uint, uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed
            return (fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED), 0);
        }
        // redeemFresh emits redeem-specific logs on errors, so we don't need to
        return redeemFresh(msg.sender, 0, redeemAmount);
    }

    struct RedeemLocalVars {
        Error err;
        MathError mathErr;
        uint exchangeRateMantissa;
        uint redeemTokens;
        uint redeemAmount;
        uint totalSupplyNew;
        uint accountTokensNew;
    }

    /**
     * @notice User redeems pTokens in exchange for the underlying asset
     * @dev Assumes interest has already been accrued up to the current block
     * @param redeemer The address of the account which is redeeming the tokens
     * @param redeemTokensIn The number of pTokens to redeem into underlying (only one of redeemTokensIn or redeemAmountIn may be non-zero)
     * @param redeemAmountIn The number of underlying tokens to receive from redeeming pTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero)
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the redeem tokens amount.
     */
    function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal returns (uint, uint) {
        require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero");

        RedeemLocalVars memory vars;

        /* exchangeRate = invoke Exchange Rate Stored() */
        (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal();
        if (vars.mathErr != MathError.NO_ERROR) {
            return (failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr)), 0);
        }

        /* If redeemTokensIn > 0: */
        if (redeemTokensIn > 0) {
            /*
             * We calculate the exchange rate and the amount of underlying to be redeemed:
             *  redeemTokens = redeemTokensIn
             *  redeemAmount = redeemTokensIn x exchangeRateCurrent
             */
            vars.redeemTokens = redeemTokensIn;

            (vars.mathErr, vars.redeemAmount) = mulScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), redeemTokensIn);
            if (vars.mathErr != MathError.NO_ERROR) {
                return (failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint(vars.mathErr)), 0);
            }
        } else {
            /*
             * We get the current exchange rate and calculate the amount to be redeemed:
             *  redeemTokens = redeemAmountIn / exchangeRate
             *  redeemAmount = redeemAmountIn
             */

            (vars.mathErr, vars.redeemTokens) = divScalarByExpTruncate(redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa}));
            if (vars.mathErr != MathError.NO_ERROR) {
                return (failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, uint(vars.mathErr)), 0);
            }

            vars.redeemAmount = redeemAmountIn;
        }

        /* Fail if redeem not allowed */
        uint allowed = controller.redeemAllowed(address(this), redeemer, vars.redeemTokens);
        if (allowed != 0) {
            return (failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.REDEEM_CONTROLLER_REJECTION, allowed), 0);
        }

        /* Verify market's block number equals current block number */
        if (accrualBlockNumber != getBlockNumber()) {
            return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REDEEM_FRESHNESS_CHECK), 0);
        }

        /*
         * We calculate the new total supply and redeemer balance, checking for underflow:
         *  totalSupplyNew = totalSupply - redeemTokens
         *  accountTokensNew = accountTokens[redeemer] - redeemTokens
         */
        (vars.mathErr, vars.totalSupplyNew) = subUInt(totalSupply, vars.redeemTokens);
        if (vars.mathErr != MathError.NO_ERROR) {
            return (failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint(vars.mathErr)), 0);
        }

        (vars.mathErr, vars.accountTokensNew) = subUInt(accountTokens[redeemer], vars.redeemTokens);
        if (vars.mathErr != MathError.NO_ERROR) {
            return (failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)), 0);
        }

        /* Fail gracefully if protocol has insufficient cash */
        if (getCashPrior() < vars.redeemAmount) {
            return (fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDEEM_TRANSFER_OUT_NOT_POSSIBLE), 0);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /*
         * We invoke doTransferOut for the redeemer and the redeemAmount.
         *  Note: The pToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the pToken has redeemAmount less of cash.
         *  doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
         */
        doTransferOut(redeemer, vars.redeemAmount);

        /* We write previously calculated values into storage */
        totalSupply = vars.totalSupplyNew;
        accountTokens[redeemer] = vars.accountTokensNew;

        /* We emit a Transfer event, and a Redeem event */
        emit Transfer(redeemer, address(this), vars.redeemTokens);
        emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens);

        /* We call the defense hook */
        controller.redeemVerify(address(this), redeemer, vars.redeemAmount, vars.redeemTokens);

        return (uint(Error.NO_ERROR), vars.redeemTokens);
    }

    /**
      * @notice Sender borrows assets from the protocol to their own address
      * @param borrowAmount The amount of the underlying asset to borrow
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function borrowInternal(uint borrowAmount) internal nonReentrant returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
            return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED);
        }
        // borrowFresh emits borrow-specific logs on errors, so we don't need to
        return borrowFresh(msg.sender, borrowAmount);
    }

    struct BorrowLocalVars {
        MathError mathErr;
        uint accountBorrows;
        uint accountBorrowsNew;
        uint totalBorrowsNew;
    }

    /**
      * @notice Users borrow assets from the protocol to their own address
      * @param borrowAmount The amount of the underlying asset to borrow
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function borrowFresh(address payable borrower, uint borrowAmount) internal returns (uint) {
        /* Fail if borrow not allowed */
        uint allowed = controller.borrowAllowed(address(this), borrower, borrowAmount);
        if (allowed != 0) {
            return failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.BORROW_CONTROLLER_REJECTION, allowed);
        }

        /* Verify market's block number equals current block number */
        if (accrualBlockNumber != getBlockNumber()) {
            return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK);
        }

        /* Fail gracefully if protocol has insufficient underlying cash */
        if (getCashPrior() < borrowAmount) {
            return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE);
        }

        BorrowLocalVars memory vars;

        /*
         * We calculate the new borrower and total borrow balances, failing on overflow:
         *  accountBorrowsNew = accountBorrows + borrowAmount
         *  totalBorrowsNew = totalBorrows + borrowAmount
         */
        (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower);
        if (vars.mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));
        }

        (vars.mathErr, vars.accountBorrowsNew) = addUInt(vars.accountBorrows, borrowAmount);
        if (vars.mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));
        }

        (vars.mathErr, vars.totalBorrowsNew) = addUInt(totalBorrows, borrowAmount);
        if (vars.mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /*
         * We invoke doTransferOut for the borrower and the borrowAmount.
         *  Note: The pToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the pToken borrowAmount less of cash.
         *  doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
         */
        doTransferOut(borrower, borrowAmount);

        /* We write the previously calculated values into storage */
        accountBorrows[borrower].principal = vars.accountBorrowsNew;
        accountBorrows[borrower].interestIndex = borrowIndex;
        totalBorrows = vars.totalBorrowsNew;

        /* We emit a Borrow event */
        emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew);

        return uint(Error.NO_ERROR);
    }

    /**
     * @notice Sender repays their own borrow
     * @param repayAmount The amount to repay
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
     */
    function repayBorrowInternal(uint repayAmount) internal nonReentrant returns (uint, uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
            return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0);
        }
        // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to
        return repayBorrowFresh(msg.sender, msg.sender, repayAmount);
    }

    /**
     * @notice Sender repays a borrow belonging to borrower
     * @param borrower the account with the debt being payed off
     * @param repayAmount The amount to repay
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
     */
    function repayBorrowBehalfInternal(address borrower, uint repayAmount) internal nonReentrant returns (uint, uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
            return (fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED), 0);
        }
        // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to
        return repayBorrowFresh(msg.sender, borrower, repayAmount);
    }

    struct RepayBorrowLocalVars {
        Error err;
        MathError mathErr;
        uint repayAmount;
        uint borrowerIndex;
        uint accountBorrows;
        uint accountBorrowsNew;
        uint totalBorrowsNew;
        uint actualRepayAmount;
    }

    /**
     * @notice Borrows are repaid by another user (possibly the borrower).
     * @param payer the account paying off the borrow
     * @param borrower the account with the debt being payed off
     * @param repayAmount the amount of undelrying tokens being returned
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
     */
    function repayBorrowFresh(address payer, address borrower, uint repayAmount) internal returns (uint, uint) {
        /* Fail if repayBorrow not allowed */
        uint allowed = controller.repayBorrowAllowed(address(this), payer, borrower, repayAmount);
        if (allowed != 0) {
            return (failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.REPAY_BORROW_CONTROLLER_REJECTION, allowed), 0);
        }

        /* Verify market's block number equals current block number */
        if (accrualBlockNumber != getBlockNumber()) {
            return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK), 0);
        }

        RepayBorrowLocalVars memory vars;

        /* We remember the original borrowerIndex for verification purposes */
        vars.borrowerIndex = accountBorrows[borrower].interestIndex;

        /* We fetch the amount the borrower owes, with accumulated interest */
        (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower);
        if (vars.mathErr != MathError.NO_ERROR) {
            return (failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)), 0);
        }

        /*
         *  If totalBorrows < accountBorrows (result of rounding 1e-18), use totalBorrows
         */
        if (vars.accountBorrows > totalBorrows) {
            vars.accountBorrows = totalBorrows;
        }

        /* If repayAmount > accountBorrows, repayAmount = accountBorrows */
        if (repayAmount > vars.accountBorrows) {
            vars.repayAmount = vars.accountBorrows;
        } else {
            vars.repayAmount = repayAmount;
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /*
         * We call doTransferIn for the payer and the repayAmount
         *  Note: The pToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the pToken holds an additional repayAmount of cash.
         *  doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred.
         *   it returns the amount actually transferred, in case of a fee.
         */
        vars.actualRepayAmount = doTransferIn(payer, vars.repayAmount);

        /*
         * We calculate the new borrower and total borrow balances, failing on underflow:
         *  accountBorrowsNew = accountBorrows - actualRepayAmount
         *  totalBorrowsNew = totalBorrows - actualRepayAmount
         */
        (vars.mathErr, vars.accountBorrowsNew) = subUInt(vars.accountBorrows, vars.actualRepayAmount);
        require(vars.mathErr == MathError.NO_ERROR, "REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED");

        (vars.mathErr, vars.totalBorrowsNew) = subUInt(totalBorrows, vars.actualRepayAmount);
        require(vars.mathErr == MathError.NO_ERROR, "REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED");

        /* We write the previously calculated values into storage */
        accountBorrows[borrower].principal = vars.accountBorrowsNew;
        accountBorrows[borrower].interestIndex = borrowIndex;
        totalBorrows = vars.totalBorrowsNew;

        /* We emit a RepayBorrow event */
        emit RepayBorrow(payer, borrower, vars.actualRepayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew);

        return (uint(Error.NO_ERROR), vars.actualRepayAmount);
    }

    /**
     * @notice The sender liquidates the borrowers collateral.
     *  The collateral seized is transferred to the liquidator.
     * @param borrower The borrower of this pToken to be liquidated
     * @param pTokenCollateral The market in which to seize collateral from the borrower
     * @param repayAmount The amount of the underlying borrowed asset to repay
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
     */
    function liquidateBorrowInternal(address borrower, uint repayAmount, PTokenInterface pTokenCollateral) internal nonReentrant returns (uint, uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed
            return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0);
        }

        error = pTokenCollateral.accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed
            return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0);
        }

        // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to
        return liquidateBorrowFresh(msg.sender, borrower, repayAmount, pTokenCollateral);
    }

    /**
     * @notice The liquidator liquidates the borrowers collateral.
     *  The collateral seized is transferred to the liquidator.
     * @param borrower The borrower of this pToken to be liquidated
     * @param liquidator The address repaying the borrow and seizing collateral
     * @param pTokenCollateral The market in which to seize collateral from the borrower
     * @param repayAmount The amount of the underlying borrowed asset to repay
     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
     */
    function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, PTokenInterface pTokenCollateral) internal returns (uint, uint) {
        /* Fail if liquidate not allowed */
        uint allowed = controller.liquidateBorrowAllowed(address(this), address(pTokenCollateral), liquidator, borrower, repayAmount);
        if (allowed != 0) {
            return (failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.LIQUIDATE_CONTROLLER_REJECTION, allowed), 0);
        }

        /* Verify market's block number equals current block number */
        if (accrualBlockNumber != getBlockNumber()) {
            return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0);
        }

        /* Verify pTokenCollateral market's block number equals current block number */
        if (pTokenCollateral.accrualBlockNumber() != getBlockNumber()) {
            return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0);
        }

        /* Fail if borrower = liquidator */
        if (borrower == liquidator) {
            return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0);
        }

        /* Fail if repayAmount = 0 */
        if (repayAmount == 0) {
            return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0);
        }

        /* Fail if repayAmount = -1 */
        if (repayAmount == uint(-1)) {
            return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0);
        }

        /* Fail if repayBorrow fails */
        (uint repayBorrowError, uint actualRepayAmount) = repayBorrowFresh(liquidator, borrower, repayAmount);
        if (repayBorrowError != uint(Error.NO_ERROR)) {
            return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /* We calculate the number of collateral tokens that will be seized */
        (uint amountSeizeError, uint seizeTokens) = controller.liquidateCalculateSeizeTokens(address(this), address(pTokenCollateral), actualRepayAmount);
        require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_CONTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED");

        /* Revert if borrower collateral token balance < seizeTokens */
        require(pTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH");

        // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call
        uint seizeError;
        if (address(pTokenCollateral) == address(this)) {
            seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens);
        } else {
            seizeError = pTokenCollateral.seize(liquidator, borrower, seizeTokens);
        }

        /* Revert if seize tokens fails (since we cannot be sure of side effects) */
        require(seizeError == uint(Error.NO_ERROR), "token seizure failed");

        /* We emit a LiquidateBorrow event */
        emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(pTokenCollateral), seizeTokens);

        return (uint(Error.NO_ERROR), actualRepayAmount);
    }

    /**
     * @notice Transfers collateral tokens (this market) to the liquidator.
     * @dev Will fail unless called by another pToken during the process of liquidation.
     *  Its absolutely critical to use msg.sender as the borrowed pToken and not a parameter.
     * @param liquidator The account receiving seized collateral
     * @param borrower The account having collateral seized
     * @param seizeTokens The number of pTokens to seize
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function seize(address liquidator, address borrower, uint seizeTokens) external override nonReentrant returns (uint) {
        return seizeInternal(msg.sender, liquidator, borrower, seizeTokens);
    }

    /**
     * @notice Transfers collateral tokens (this market) to the liquidator.
     * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another PToken.
     *  Its absolutely critical to use msg.sender as the seizer pToken and not a parameter.
     * @param seizerToken The contract seizing the collateral (i.e. borrowed pToken)
     * @param liquidator The account receiving seized collateral
     * @param borrower The account having collateral seized
     * @param seizeTokens The number of pTokens to seize
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal virtual returns (uint) {
        /* Fail if seize not allowed */
        uint allowed = controller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens);
        if (allowed != 0) {
            return failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_CONTROLLER_REJECTION, allowed);
        }

        /* Fail if borrower = liquidator */
        if (borrower == liquidator) {
            return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER);
        }

        MathError mathErr;
        uint borrowerTokensNew;
        uint liquidatorTokensNew;

        /*
         * We calculate the new borrower and liquidator token balances, failing on underflow/overflow:
         *  borrowerTokensNew = accountTokens[borrower] - seizeTokens
         *  liquidatorTokensNew = accountTokens[liquidator] + seizeTokens
         */
        (mathErr, borrowerTokensNew) = subUInt(accountTokens[borrower], seizeTokens);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, uint(mathErr));
        }

        (mathErr, liquidatorTokensNew) = addUInt(accountTokens[liquidator], seizeTokens);
        if (mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED, uint(mathErr));
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /* We write the previously calculated values into storage */
        accountTokens[borrower] = borrowerTokensNew;
        accountTokens[liquidator] = liquidatorTokensNew;

        /* Emit a Transfer event */
        emit Transfer(borrower, liquidator, seizeTokens);

        return uint(Error.NO_ERROR);
    }

    /*** Admin Functions ***/

    /**
      * @notice Sets a new controller for the market
      * @dev Admin function to set a new controller
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function _setController(ControllerInterface newController) public override returns (uint) {
        // Check caller is admin
        if (msg.sender != getMyAdmin()) {
            return fail(Error.UNAUTHORIZED, FailureInfo.SET_CONTROLLER_OWNER_CHECK);
        }

        return _setControllerInternal(newController);
    }

    function _setControllerInternal(ControllerInterface newController) internal returns (uint) {
        ControllerInterface oldController = controller;
        // Ensure invoke controller.isController() returns true
        require(newController.isController(), "marker method returned false");

        // Set market's controller to newController
        controller = newController;

        // Emit NewController(oldController, newController)
        emit NewController(oldController, newController);

        return uint(Error.NO_ERROR);
    }

    /**
      * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh
      * @dev Admin function to accrue interest and set a new reserve factor
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function _setReserveFactor(uint newReserveFactorMantissa) external override nonReentrant returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed.
            return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED);
        }
        // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to.
        return _setReserveFactorFresh(newReserveFactorMantissa);
    }

    /**
      * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual)
      * @dev Admin function to set a new reserve factor
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function _setReserveFactorFresh(uint newReserveFactorMantissa) internal returns (uint) {
        // Check caller is admin
        if (msg.sender != getMyAdmin()) {
            return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK);
        }

        // Verify market's block number equals current block number
        if (accrualBlockNumber != getBlockNumber()) {
            return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK);
        }

        // Check newReserveFactor ≤ maxReserveFactor
        if (newReserveFactorMantissa > reserveFactorMaxMantissa) {
            return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK);
        }

        uint oldReserveFactorMantissa = reserveFactorMantissa;
        reserveFactorMantissa = newReserveFactorMantissa;

        emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa);

        return uint(Error.NO_ERROR);
    }

    /**
     * @notice Accrues interest and reduces reserves by transferring from msg.sender
     * @param addAmount Amount of addition to reserves
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _addReservesInternal(uint addAmount) internal nonReentrant returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed.
            return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED);
        }

        // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to.
        (error, ) = _addReservesFresh(addAmount);
        return error;
    }

    /**
     * @notice Add reserves by transferring from caller
     * @dev Requires fresh interest accrual
     * @param addAmount Amount of addition to reserves
     * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees
     */
    function _addReservesFresh(uint addAmount) internal returns (uint, uint) {
        // totalReserves + actualAddAmount
        uint totalReservesNew;
        uint actualAddAmount;

        // We fail gracefully unless market's block number equals current block number
        if (accrualBlockNumber != getBlockNumber()) {
            return (fail(Error.MARKET_NOT_FRESH, FailureInfo.ADD_RESERVES_FRESH_CHECK), actualAddAmount);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        /*
         * We call doTransferIn for the caller and the addAmount
         *  Note: The pToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the pToken holds an additional addAmount of cash.
         *  doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred.
         *  it returns the amount actually transferred, in case of a fee.
         */

        actualAddAmount = doTransferIn(msg.sender, addAmount);

        totalReservesNew = totalReserves + actualAddAmount;

        /* Revert on overflow */
        require(totalReservesNew >= totalReserves, "add reserves unexpected overflow");

        // Store reserves[n+1] = reserves[n] + actualAddAmount
        totalReserves = totalReservesNew;

        /* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */
        emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew);

        /* Return (NO_ERROR, actualAddAmount) */
        return (uint(Error.NO_ERROR), actualAddAmount);
    }


    /**
     * @notice Accrues interest and reduces reserves by transferring to admin
     * @param reduceAmount Amount of reduction to reserves
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _reduceReserves(uint reduceAmount) external override nonReentrant returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed.
            return fail(Error(error), FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED);
        }
        // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to.
        return _reduceReservesFresh(reduceAmount);
    }

    /**
     * @notice Reduces reserves by transferring to admin
     * @dev Requires fresh interest accrual
     * @param reduceAmount Amount of reduction to reserves
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _reduceReservesFresh(uint reduceAmount) internal returns (uint) {
        // totalReserves - reduceAmount
        uint totalReservesNew;

        address payable admin = getMyAdmin();

        // Check caller is admin
        if (msg.sender != admin) {
            return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK);
        }

        // We fail gracefully unless market's block number equals current block number
        if (accrualBlockNumber != getBlockNumber()) {
            return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK);
        }

        // Fail gracefully if protocol has insufficient underlying cash
        if (getCashPrior() < reduceAmount) {
            return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE);
        }

        // Check reduceAmount ≤ reserves[n] (totalReserves)
        if (reduceAmount > totalReserves) {
            return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        totalReservesNew = totalReserves - reduceAmount;
        // We checked reduceAmount <= totalReserves above, so this should never revert.
        require(totalReservesNew <= totalReserves, "reduce reserves unexpected underflow");

        // Store reserves[n+1] = reserves[n] - reduceAmount
        totalReserves = totalReservesNew;

        // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
        doTransferOut(admin, reduceAmount);

        emit ReservesReduced(admin, reduceAmount, totalReservesNew);

        return uint(Error.NO_ERROR);
    }

    /**
     * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh
     * @dev Admin function to accrue interest and update the interest rate model
     * @param newInterestRateModel the new interest rate model to use
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _setInterestRateModel(InterestRateModel newInterestRateModel) public override returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed
            return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED);
        }
        // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to.
        return _setInterestRateModelFresh(newInterestRateModel);
    }

    /**
     * @notice updates the interest rate model (*requires fresh interest accrual)
     * @dev Admin function to update the interest rate model
     * @param newInterestRateModel the new interest rate model to use
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) {
        // Check caller is admin
        if (msg.sender != getMyAdmin()) {
            return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK);
        }

        return _setInterestRateModelFreshInternal(newInterestRateModel);
    }

    function _setInterestRateModelFreshInternal(InterestRateModel newInterestRateModel) internal returns (uint) {
        // Used to store old model for use in the event that is emitted on success
        InterestRateModel oldInterestRateModel;

        // We fail gracefully unless market's block number equals current block number
        if (accrualBlockNumber != getBlockNumber()) {
            return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK);
        }

        // Track the market's current interest rate model
        oldInterestRateModel = interestRateModel;

        // Ensure invoke newInterestRateModel.isInterestRateModel() returns true
        require(newInterestRateModel.isInterestRateModel(), "marker method returned false");

        // Set the interest rate model to newInterestRateModel
        interestRateModel = newInterestRateModel;

        // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel)
        emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel);

        return uint(Error.NO_ERROR);
    }

    function getMyAdmin() public view returns (address payable) {
        return RegistryInterface(registry).admin();
    }

    /*** Safe Token ***/

    /**
     * @notice Gets balance of this contract in terms of the underlying
     * @dev This excludes the value of the current message, if any
     * @return The quantity of underlying owned by this contract
     */
    function getCashPrior() internal view virtual returns (uint);

    /**
     * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee.
     *  This may revert due to insufficient balance or insufficient allowance.
     */
    function doTransferIn(address from, uint amount) internal virtual returns (uint);

    /**
     * @dev Performs a transfer out, ideally returning an explanatory error code upon failure tather than reverting.
     *  If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract.
     *  If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions.
     */
    function doTransferOut(address payable to, uint amount) internal virtual;

    /*** Reentrancy Guard ***/

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     */
    modifier nonReentrant() {
        require(_notEntered, "re-entered");
        _notEntered = false;
        _;
        _notEntered = true; // get a gas-refund post-Istanbul
    }
}

File 11 of 14 : PTokenInterfaces.sol
pragma solidity ^0.7.6;

import "./ControllerInterface.sol";
import "./InterestRateModel.sol";
import "./ProxyWithRegistry.sol";

contract PTokenStorage is ProxyWithRegistryStorage {
    /**
     * @dev Guard variable for re-entrancy checks
     */
    bool internal _notEntered;

    /**
     * @notice EIP-20 token name for this token
     */
    string public name;

    /**
     * @notice EIP-20 token symbol for this token
     */
    string public symbol;

    /**
     * @notice EIP-20 token decimals for this token
     */
    uint8 public decimals;

    /**
     * @dev Maximum borrow rate that can ever be applied (.0005% / block)
     */

    uint internal constant borrowRateMaxMantissa = 0.0005e16;

    /**
     * @dev Maximum fraction of interest that can be set aside for reserves
     */
    uint internal constant reserveFactorMaxMantissa = 1e18;

    /**
     * @notice Contract which oversees inter-pToken operations
     */
    ControllerInterface public controller;

    /**
     * @notice Model which tells what the current interest rate should be
     */
    InterestRateModel public interestRateModel;

    /**
     * @dev Initial exchange rate used when minting the first PTokens (used when totalSupply = 0)
     */
    uint internal initialExchangeRateMantissa;

    /**
     * @notice Fraction of interest currently set aside for reserves
     */
    uint public reserveFactorMantissa;

    /**
     * @notice Block number that interest was last accrued at
     */
    uint public accrualBlockNumber;

    /**
     * @notice Accumulator of the total earned interest rate since the opening of the market
     */
    uint public borrowIndex;

    /**
     * @notice Total amount of outstanding borrows of the underlying in this market
     */
    uint public totalBorrows;

    /**
     * @notice Total amount of reserves of the underlying held in this market
     */
    uint public totalReserves;

    /**
     * @notice Total number of tokens in circulation
     */
    uint public totalSupply;

    /**
     * @dev Official record of token balances for each account
     */
    mapping (address => uint) internal accountTokens;

    /**
     * @dev Approved token transfer amounts on behalf of others
     */
    mapping (address => mapping (address => uint)) internal transferAllowances;

    /**
     * @notice Container for borrow balance information
     * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action
     * @member interestIndex Global borrowIndex as of the most recent balance-changing action
     */
    struct BorrowSnapshot {
        uint principal;
        uint interestIndex;
    }

    /**
     * @dev Mapping of account addresses to outstanding borrow balances
     */
    mapping(address => BorrowSnapshot) internal accountBorrows;
}

abstract contract PTokenInterface is PTokenStorage {
    /**
     * @notice Indicator that this is a PToken contract (for inspection)
     */
    bool public constant isPToken = true;


    /*** Market Events ***/

    /**
     * @notice Event emitted when interest is accrued
     */
    event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows, uint totalReserves);

    /**
     * @notice Event emitted when tokens are minted
     */
    event Mint(address minter, uint mintAmount, uint mintTokens);

    /**
     * @notice Event emitted when tokens are redeemed
     */
    event Redeem(address redeemer, uint redeemAmount, uint redeemTokens);

    /**
     * @notice Event emitted when underlying is borrowed
     */
    event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows);

    /**
     * @notice Event emitted when a borrow is repaid
     */
    event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows);

    /**
     * @notice Event emitted when a borrow is liquidated
     */
    event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address pTokenCollateral, uint seizeTokens);


    /*** Admin Events ***/

    /**
     * @notice Event emitted when controller is changed
     */
    event NewController(ControllerInterface oldController, ControllerInterface newController);

    /**
     * @notice Event emitted when interestRateModel is changed
     */
    event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel);

    /**
     * @notice Event emitted when the reserve factor is changed
     */
    event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);

    /**
     * @notice Event emitted when the reserves are added
     */
    event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves);

    /**
     * @notice Event emitted when the reserves are reduced
     */
    event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves);

    /**
     * @notice EIP20 Transfer event
     */
    event Transfer(address indexed from, address indexed to, uint amount);

    /**
     * @notice EIP20 Approval event
     */
    event Approval(address indexed owner, address indexed spender, uint amount);

    /*** User Interface ***/

    function transfer(address dst, uint amount) external virtual returns (bool);
    function transferFrom(address src, address dst, uint amount) external virtual returns (bool);
    function approve(address spender, uint amount) external virtual returns (bool);
    function allowance(address owner, address spender) external view virtual returns (uint);
    function balanceOf(address owner) external view virtual returns (uint);
    function balanceOfUnderlying(address owner) external virtual returns (uint);
    function getAccountSnapshot(address account) external view virtual returns (uint, uint, uint, uint);
    function borrowRatePerBlock() external view virtual returns (uint);
    function supplyRatePerBlock() external view virtual returns (uint);
    function totalBorrowsCurrent() external virtual returns (uint);
    function borrowBalanceCurrent(address account) external virtual returns (uint);
    function borrowBalanceStored(address account) public view virtual returns (uint);
    function exchangeRateCurrent() public virtual returns (uint);
    function exchangeRateStored() public view virtual returns (uint);
    function getCash() external view virtual returns (uint);
    function accrueInterest() public virtual returns (uint);
    function seize(address liquidator, address borrower, uint seizeTokens) external virtual returns (uint);

    /*** Admin Functions ***/

    function _setController(ControllerInterface newController) public virtual returns (uint);
    function _setReserveFactor(uint newReserveFactorMantissa) external virtual returns (uint);
    function _reduceReserves(uint reduceAmount) external virtual returns (uint);
    function _setInterestRateModel(InterestRateModel newInterestRateModel) public virtual returns (uint);
}

contract PErc20Storage {
    /**
     * @notice Underlying asset for this PToken
     */
    address public underlying;
}

abstract contract PErc20Interface is PErc20Storage {

    /*** User Interface ***/

    function mint(uint mintAmount) external virtual returns (uint);
    function redeem(uint redeemTokens) external virtual returns (uint);
    function redeemUnderlying(uint redeemAmount) external virtual returns (uint);
    function borrow(uint borrowAmount) external virtual returns (uint);
    function repayBorrow(uint repayAmount) external virtual returns (uint);
    function repayBorrowBehalf(address borrower, uint repayAmount) external virtual returns (uint);
    function liquidateBorrow(address borrower, uint repayAmount, PTokenInterface pTokenCollateral) external virtual returns (uint);

    /*** Admin Functions ***/

    function _addReserves(uint addAmount) external virtual returns (uint);
}

contract PPIEStorage {
    /// @notice A record of each accounts delegate
    mapping (address => address) public delegates;

    /// @notice A checkpoint for marking number of votes from a given block
    struct Checkpoint {
        uint32 fromBlock;
        uint96 votes;
    }

    /// @notice A record of votes checkpoints for each account, by index
    mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;

    /// @notice The number of checkpoints for each account
    mapping (address => uint32) public numCheckpoints;

    /// @notice The EIP-712 typehash for the contract's domain
    bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

    /// @notice The EIP-712 typehash for the delegation struct used by the contract
    bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");

    /// @notice A record of states for signing / validating signatures
    mapping (address => uint) public nonces;
}

abstract contract PPIEInterface is PPIEStorage {
    /// @notice An event thats emitted when an account changes its delegate
    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);

    /// @notice An event thats emitted when a delegate account's vote balance changes
    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);

    function delegate(address delegatee) external virtual;
    function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external virtual;
    function getCurrentVotes(address account) external view virtual returns (uint96);
    function getPriorVotes(address account, uint blockNumber) external view virtual returns (uint96);
}

File 12 of 14 : PriceOracle.sol
pragma solidity ^0.7.6;

abstract contract PriceOracle {
    /// @notice Indicator that this is a PriceOracle contract (for inspection)
    bool public constant isPriceOracle = true;

    event PriceUpdated(address asset, uint price);

    /**
      * @notice Get the underlying price of a pToken asset
      * @param pToken The pToken to get the underlying price of
      * @return The underlying asset price mantissa (scaled by 1e18).
      *  Zero means the price is unavailable.
      */
    function getUnderlyingPrice(address pToken) external view virtual returns (uint);

    function updateUnderlyingPrice(address pToken) external virtual returns (uint);
}

File 13 of 14 : ProxyWithRegistry.sol
pragma solidity ^0.7.6;

import "./RegistryInterface.sol";

contract ProxyWithRegistryStorage {

    /**
     * @notice Address of the registry contract
     */
    address public registry;
}

abstract contract ProxyWithRegistryInterface is ProxyWithRegistryStorage {
    function _setRegistry(address _registry) internal virtual;
    function _pTokenImplementation() internal view virtual returns (address);
}

contract ProxyWithRegistry is ProxyWithRegistryInterface {
    /**
     *  Returns actual address of the implementation contract from current registry
     *  @return registry Address of the registry
     */
    function _pTokenImplementation() internal view override returns (address) {
        return RegistryInterface(registry).pTokenImplementation();
    }

    function _setRegistry(address _registry) internal override {
        registry = _registry;
    }
}

contract ImplementationStorage {

    address public implementation;

    function _setImplementation(address implementation_) internal {
        implementation = implementation_;
    }
}

File 14 of 14 : RegistryInterface.sol
pragma solidity ^0.7.6;

interface RegistryInterface {

    /**
     *  Returns admin address for cToken contracts
     *  @return admin address
     */
    function admin() external view returns (address payable);

    /**
     *  Returns address of actual PToken implementation contract
     *  @return Address of contract
     */
    function pTokenImplementation() external view returns (address);

    function addPToken(address underlying, address pToken) external returns(uint);
    function addPETH(address pETH_) external returns(uint);
    function addPPIE(address pPIE_) external returns(uint);
}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"cashPrior","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interestAccumulated","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"borrowIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalBorrows","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalReserves","type":"uint256"}],"name":"AccrueInterest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"accountBorrows","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalBorrows","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"fromDelegate","type":"address"},{"indexed":true,"internalType":"address","name":"toDelegate","type":"address"}],"name":"DelegateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"uint256","name":"previousBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"DelegateVotesChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"error","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"info","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"detail","type":"uint256"}],"name":"Failure","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"repayAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"pTokenCollateral","type":"address"},{"indexed":false,"internalType":"uint256","name":"seizeTokens","type":"uint256"}],"name":"LiquidateBorrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"minter","type":"address"},{"indexed":false,"internalType":"uint256","name":"mintAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mintTokens","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ControllerInterface","name":"oldController","type":"address"},{"indexed":false,"internalType":"contract ControllerInterface","name":"newController","type":"address"}],"name":"NewController","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract InterestRateModel","name":"oldInterestRateModel","type":"address"},{"indexed":false,"internalType":"contract InterestRateModel","name":"newInterestRateModel","type":"address"}],"name":"NewMarketInterestRateModel","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldReserveFactorMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newReserveFactorMantissa","type":"uint256"}],"name":"NewReserveFactor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"redeemer","type":"address"},{"indexed":false,"internalType":"uint256","name":"redeemAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"redeemTokens","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"payer","type":"address"},{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"repayAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"accountBorrows","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalBorrows","type":"uint256"}],"name":"RepayBorrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"benefactor","type":"address"},{"indexed":false,"internalType":"uint256","name":"addAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTotalReserves","type":"uint256"}],"name":"ReservesAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"admin","type":"address"},{"indexed":false,"internalType":"uint256","name":"reduceAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTotalReserves","type":"uint256"}],"name":"ReservesReduced","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":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DELEGATION_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"addAmount","type":"uint256"}],"name":"_addReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reduceAmount","type":"uint256"}],"name":"_reduceReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ControllerInterface","name":"newController","type":"address"}],"name":"_setController","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract InterestRateModel","name":"newInterestRateModel","type":"address"}],"name":"_setInterestRateModel","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newReserveFactorMantissa","type":"uint256"}],"name":"_setReserveFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"accrualBlockNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accrueInterest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","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":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOfUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"borrowAmount","type":"uint256"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"borrowBalanceCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"borrowBalanceStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowRatePerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint32","name":"","type":"uint32"}],"name":"checkpoints","outputs":[{"internalType":"uint32","name":"fromBlock","type":"uint32"},{"internalType":"uint96","name":"votes","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"contract ControllerInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"delegateBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"delegates","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exchangeRateCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exchangeRateStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getAccountSnapshot","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getBorrowSnapshot","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCash","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getCurrentVotes","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMyAdmin","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getPriorVotes","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RegistryInterface","name":"registry_","type":"address"},{"internalType":"contract ControllerInterface","name":"controller_","type":"address"},{"internalType":"contract InterestRateModel","name":"interestRateModel_","type":"address"},{"internalType":"uint256","name":"initialExchangeRateMantissa_","type":"uint256"},{"internalType":"uint256","name":"initialReserveFactorMantissa_","type":"uint256"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"uint8","name":"decimals_","type":"uint8"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"underlying_","type":"address"},{"internalType":"contract RegistryInterface","name":"registry_","type":"address"},{"internalType":"contract ControllerInterface","name":"controller_","type":"address"},{"internalType":"contract InterestRateModel","name":"interestRateModel_","type":"address"},{"internalType":"uint256","name":"initialExchangeRateMantissa_","type":"uint256"},{"internalType":"uint256","name":"initialReserveFactorMantissa_","type":"uint256"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"uint8","name":"decimals_","type":"uint8"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"interestRateModel","outputs":[{"internalType":"contract InterestRateModel","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"repayAmount","type":"uint256"},{"internalType":"contract PTokenInterface","name":"pTokenCollateral","type":"address"}],"name":"liquidateBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"mintAmount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"numCheckpoints","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"redeemTokens","type":"uint256"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"redeemAmount","type":"uint256"}],"name":"redeemUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"repayBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"repayBorrowBehalf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reserveFactorMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"liquidator","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"seizeTokens","type":"uint256"}],"name":"seize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"supplyRatePerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBorrows","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBorrowsCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50615e5980620000216000396000f3fe608060405234801561001057600080fd5b506004361061038e5760003560e01c806383de424e116101de578063bd6d894d1161010f578063eedf9c72116100ad578063f5e3c4621161007c578063f5e3c46214610cf1578063f77c479114610d27578063f8f9da2814610d2f578063fca7820b14610d375761038e565b8063eedf9c7214610b06578063f1127ed814610c69578063f2b3abbd14610cc3578063f3fdb15a14610ce95761038e565b8063c5ebeaec116100e9578063c5ebeaec14610a96578063db006a7514610ab3578063dd62ed3e14610ad0578063e7a324dc14610afe5761038e565b8063bd6d894d146109fb578063c37f68e214610a03578063c3cda52014610a4f5761038e565b8063a3e94ddd1161017c578063aa5af0fd11610156578063aa5af0fd1461098f578063ae9d70b014610997578063b2a02ff11461099f578063b4b5ea57146109d55761038e565b8063a3e94ddd1461091c578063a6afed951461095b578063a9059cbb146109635761038e565b806395d89b41116101b857806395d89b411461077557806395dd91931461077d5780639ea21c3d146107a3578063a0712d68146108ff5761038e565b806383de424e1461072a578063852a12e3146107505780638f840ddd1461076d5761038e565b80633e941010116102c35780636c540baf1161026157806373acee981161023057806373acee98146106ac578063782d6fe1146106b45780637b103999146106fc5780637ecebe00146107045761038e565b80636c540baf146106375780636f307dc31461063f5780636fcfff451461064757806370a08231146106865761038e565b80635a890c0e1161029d5780635a890c0e146105e25780635c19a95c146105ea5780635c60da1b14610612578063601a0bf11461061a5761038e565b80633e9410101461059757806347bd3718146105b4578063587cde1e146105bc5761038e565b806320606b7011610330578063313ce5671161030a578063313ce567146105275780633176b739146105455780633af9e669146105695780633b1d21a21461058f5761038e565b806320606b70146104bd57806323b872dd146104c55780632608f818146104fb5761038e565b8063173b99041161036c578063173b99041461047f57806317bfdfbc1461048757806318160ddd146104ad578063182df0f5146104b55761038e565b806306fdde0314610393578063095ea7b3146104105780630e75270214610450575b600080fd5b61039b610d54565b6040805160208082528351818301528351919283929083019185019080838360005b838110156103d55781810151838201526020016103bd565b50505050905090810190601f1680156104025780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61043c6004803603604081101561042657600080fd5b506001600160a01b038135169060200135610ddf565b604080519115158252519081900360200190f35b61046d6004803603602081101561046657600080fd5b5035610e4c565b60408051918252519081900360200190f35b61046d610e62565b61046d6004803603602081101561049d57600080fd5b50356001600160a01b0316610e68565b61046d610f3c565b61046d610f42565b61046d610fa5565b61043c600480360360608110156104db57600080fd5b506001600160a01b03813581169160208101359091169060400135610fc9565b61046d6004803603604081101561051157600080fd5b506001600160a01b03813516906020013561108f565b61052f6110a5565b6040805160ff9092168252519081900360200190f35b61054d6110ae565b604080516001600160a01b039092168252519081900360200190f35b61046d6004803603602081101561057f57600080fd5b50356001600160a01b0316611124565b61046d6111d3565b61046d600480360360208110156105ad57600080fd5b50356111e2565b61046d6111ed565b61054d600480360360208110156105d257600080fd5b50356001600160a01b03166111f3565b61043c61120e565b6106106004803603602081101561060057600080fd5b50356001600160a01b0316611213565b005b61054d611220565b61046d6004803603602081101561063057600080fd5b503561122f565b61046d6112de565b61054d6112e4565b61066d6004803603602081101561065d57600080fd5b50356001600160a01b03166112f3565b6040805163ffffffff9092168252519081900360200190f35b61046d6004803603602081101561069c57600080fd5b50356001600160a01b031661130b565b61046d611326565b6106e0600480360360408110156106ca57600080fd5b506001600160a01b0381351690602001356113f0565b604080516001600160601b039092168252519081900360200190f35b61054d611618565b61046d6004803603602081101561071a57600080fd5b50356001600160a01b0316611627565b61046d6004803603602081101561074057600080fd5b50356001600160a01b0316611639565b61046d6004803603602081101561076657600080fd5b5035611677565b61046d6116bf565b61039b6116c5565b61046d6004803603602081101561079357600080fd5b50356001600160a01b0316611720565b61061060048036036101008110156107ba57600080fd5b6001600160a01b038235811692602081013582169260408201359092169160608201359160808101359181019060c0810160a0820135600160201b81111561080157600080fd5b82018360208201111561081357600080fd5b803590602001918460018302840111600160201b8311171561083457600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b81111561088657600080fd5b82018360208201111561089857600080fd5b803590602001918460018302840111600160201b831117156108b957600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050903560ff1691506117849050565b61046d6004803603602081101561091557600080fd5b5035611949565b6109426004803603602081101561093257600080fd5b50356001600160a01b0316611989565b6040805192835260208301919091528051918290030190f35b61046d6119af565b61043c6004803603604081101561097957600080fd5b506001600160a01b038135169060200135611e00565b61046d611ec4565b61046d611eca565b61046d600480360360608110156109b557600080fd5b506001600160a01b03813581169160208101359091169060400135611f38565b6106e0600480360360208110156109eb57600080fd5b50356001600160a01b0316611fbb565b61046d61202b565b610a2960048036036020811015610a1957600080fd5b50356001600160a01b03166120fb565b604080519485526020850193909352838301919091526060830152519081900360800190f35b610610600480360360c0811015610a6557600080fd5b506001600160a01b038135169060208101359060408101359060ff6060820135169060808101359060a00135612190565b61046d60048036036020811015610aac57600080fd5b503561245d565b61046d60048036036020811015610ac957600080fd5b5035612468565b61046d60048036036040811015610ae657600080fd5b506001600160a01b0381358116916020013516612476565b61046d6124a1565b6106106004803603610120811015610b1d57600080fd5b6001600160a01b038235811692602081013582169260408201358316926060830135169160808101359160a0820135919081019060e0810160c0820135600160201b811115610b6b57600080fd5b820183602082011115610b7d57600080fd5b803590602001918460018302840111600160201b83111715610b9e57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b811115610bf057600080fd5b820183602082011115610c0257600080fd5b803590602001918460018302840111600160201b83111715610c2357600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050903560ff1691506124c59050565b610c9b60048036036040811015610c7f57600080fd5b5080356001600160a01b0316906020013563ffffffff16612568565b6040805163ffffffff90931683526001600160601b0390911660208301528051918290030190f35b61046d60048036036020811015610cd957600080fd5b50356001600160a01b031661259d565b61054d6125d7565b61046d60048036036060811015610d0757600080fd5b506001600160a01b038135811691602081013591604090910135166125e6565b61054d6125fe565b61046d612612565b61046d60048036036020811015610d4d57600080fd5b5035612676565b6002805460408051602060018416156101000260001901909316849004601f81018490048402820184019092528181529291830182828015610dd75780601f10610dac57610100808354040283529160200191610dd7565b820191906000526020600020905b815481529060010190602001808311610dba57829003601f168201915b505050505081565b336000818152600e602090815260408083206001600160a01b03871680855290835281842086905581518681529151939493909284927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a360019150505b92915050565b600080610e5883612702565b509150505b919050565b60075481565b600154600090600160a01b900460ff16610eb6576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000610ecd6119af565b14610f18576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b610f2182611720565b90505b6001805460ff60a01b1916600160a01b179055919050565b600c5481565b6000806000610f4f6127be565b90925090506000826003811115610f6257fe5b14610f9e5760405162461bcd60e51b8152600401808060200182810382526035815260200180615d6f6035913960400191505060405180910390fd5b9150505b90565b7f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86681565b600154600090600160a01b900460ff16611017576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006110323386868661286d565b1461103f57506000611075565b6001600160a01b0380851660009081526011602052604080822054868416835291205461107192918216911684612b09565b5060015b6001805460ff60a01b1916600160a01b1790559392505050565b60008061109c8484612ca4565b50949350505050565b60045460ff1681565b600154604080516303e1469160e61b815290516000926001600160a01b03169163f851a440916004808301926020929190829003018186803b1580156110f357600080fd5b505afa158015611107573d6000803e3d6000fd5b505050506040513d602081101561111d57600080fd5b5051905090565b600080604051806020016040528061113a61202b565b90526001600160a01b0384166000908152600d6020526040812054919250908190611166908490612d62565b9092509050600082600381111561117957fe5b146111cb576040805162461bcd60e51b815260206004820152601f60248201527f62616c616e636520636f756c64206e6f742062652063616c63756c6174656400604482015290519081900360640190fd5b949350505050565b60006111dd612daf565b905090565b6000610e4682612e2f565b600a5481565b6011602052600090815260409020546001600160a01b031681565b600181565b61121d3382612ed7565b50565b6000546001600160a01b031681565b600154600090600160a01b900460ff1661127d576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006112946119af565b905080156112ba576112b28160108111156112ab57fe5b6030612f57565b915050610f24565b6112c383612fbd565b9150506001805460ff60a01b1916600160a01b179055919050565b60085481565b6010546001600160a01b031681565b60136020526000908152604090205463ffffffff1681565b6001600160a01b03166000908152600d602052604090205490565b600154600090600160a01b900460ff16611374576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b19169055600061138b6119af565b146113d6576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b50600a546001805460ff60a01b1916600160a01b17905590565b60004382106114305760405162461bcd60e51b8152600401808060200182810382526027815260200180615c486027913960400191505060405180910390fd5b6001600160a01b03831660009081526013602052604090205463ffffffff168061145e576000915050610e46565b6001600160a01b038416600090815260126020908152604080832063ffffffff6000198601811685529252909120541683106114da576001600160a01b03841660009081526012602090815260408083206000199490940163ffffffff1683529290522054600160201b90046001600160601b03169050610e46565b6001600160a01b038416600090815260126020908152604080832083805290915290205463ffffffff16831015611515576000915050610e46565b600060001982015b8163ffffffff168163ffffffff1611156115d3576000600263ffffffff848403166001600160a01b038916600090815260126020908152604080832094909304860363ffffffff818116845294825291839020835180850190945254938416808452600160201b9094046001600160601b0316908301529250908714156115ae57602001519450610e469350505050565b805163ffffffff168711156115c5578193506115cc565b6001820392505b505061151d565b506001600160a01b038516600090815260126020908152604080832063ffffffff909416835292905220546001600160601b03600160201b9091041691505092915050565b6001546001600160a01b031681565b60146020526000908152604090205481565b60006116436110ae565b6001600160a01b0316336001600160a01b03161461166e576116676001603f612f57565b9050610e5d565b610e46826130e6565b600080600061168584613223565b9150915081600014156116b857336000908152601160205260408120546116b8916001600160a01b039091169083612b09565b5092915050565b600b5481565b6003805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610dd75780601f10610dac57610100808354040283529160200191610dd7565b600080600061172e846132b4565b9092509050600082600381111561174157fe5b1461177d5760405162461bcd60e51b8152600401808060200182810382526037815260200180615bdf6037913960400191505060405180910390fd5b9392505050565b6008541580156117945750600954155b6117cf5760405162461bcd60e51b8152600401808060200182810382526023815260200180615ae56023913960400191505060405180910390fd5b600180546001600160a01b0319166001600160a01b038a1617905560068590558461182b5760405162461bcd60e51b8152600401808060200182810382526030815260200180615b3c6030913960400191505060405180910390fd5b6007849055600061183b886130e6565b90508015611890576040805162461bcd60e51b815260206004820152601960248201527f73657474696e6720636f6e74726f6c6c6572206661696c656400000000000000604482015290519081900360640190fd5b611898613366565b600855670de0b6b3a76400006009556118b08761336a565b905080156118ef5760405162461bcd60e51b8152600401808060200182810382526022815260200180615b926022913960400191505060405180910390fd5b8351611902906002906020870190615961565b508251611916906003906020860190615961565b50506004805460ff90921660ff1990921691909117905550506001805460ff60a01b1916600160a01b1790555050505050565b6000806000611957846134ba565b925050915081600014156116b857336000908152601160205260408120546116b891906001600160a01b031683612b09565b6001600160a01b0381166000908152600f6020526040902080546001909101545b915091565b6000600460019054906101000a90046001600160a01b03166001600160a01b031663833b1fce6040518163ffffffff1660e01b815260040160206040518083038186803b1580156119ff57600080fd5b505afa158015611a13573d6000803e3d6000fd5b505050506040513d6020811015611a2957600080fd5b50516040805163e0849bfd60e01b815230600482015290516001600160a01b039092169163e0849bfd916024808201926020929091908290030181600087803b158015611a7557600080fd5b505af1158015611a89573d6000803e3d6000fd5b505050506040513d6020811015611a9f57600080fd5b5060009050611aac613366565b60085490915080821415611ac557600092505050610fa2565b6000611acf612daf565b600a54600b54600954600554604080516315f2405360e01b815260048101879052602481018690526044810185905290519596509394929391926000926001600160a01b03909216916315f24053916064808301926020929190829003018186803b158015611b3d57600080fd5b505afa158015611b51573d6000803e3d6000fd5b505050506040513d6020811015611b6757600080fd5b5051905065048c27395000811115611bc6576040805162461bcd60e51b815260206004820152601c60248201527f626f72726f772072617465206973206162737572646c79206869676800000000604482015290519081900360640190fd5b600080611bd3898961357d565b90925090506000826003811115611be657fe5b14611c38576040805162461bcd60e51b815260206004820152601f60248201527f636f756c64206e6f742063616c63756c61746520626c6f636b2064656c746100604482015290519081900360640190fd5b611c406159ed565b600080600080611c5e60405180602001604052808a815250876135a0565b90975094506000876003811115611c7157fe5b14611ca357611c8e60096006896003811115611c8957fe5b613608565b9e505050505050505050505050505050610fa2565b611cad858c612d62565b90975093506000876003811115611cc057fe5b14611cd857611c8e60096001896003811115611c8957fe5b611ce2848c61366e565b90975092506000876003811115611cf557fe5b14611d0d57611c8e60096004896003811115611c8957fe5b611d286040518060200160405280600754815250858c613694565b90975091506000876003811115611d3b57fe5b14611d5357611c8e60096005896003811115611c8957fe5b611d5e858a8b613694565b90975090506000876003811115611d7157fe5b14611d8957611c8e60096003896003811115611c8957fe5b60088e90556009819055600a839055600b829055604080518d815260208101869052808201839052606081018590526080810184905290517f717fee053884ab1935ba6d0140f6ed225371439611d9674ff445419d6a0fa1b79181900360a00190a160009e50505050505050505050505050505090565b600154600090600160a01b900460ff16611e4e576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000611e693333868661286d565b14611e7657506000611eab565b33600090815260116020526040808220546001600160a01b0386811684529190922054611ea7928216911684612b09565b5060015b6001805460ff60a01b1916600160a01b17905592915050565b60095481565b6005546000906001600160a01b031663b8168816611ee6612daf565b600a54600b546007546040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060206040518083038186803b1580156110f357600080fd5b600154600090600160a01b900460ff16611f86576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b19169055611f9f338585856136e9565b90506001805460ff60a01b1916600160a01b1790559392505050565b6001600160a01b03811660009081526013602052604081205463ffffffff1680611fe657600061177d565b6001600160a01b0383166000908152601260209081526040808320600019850163ffffffff168452909152902054600160201b90046001600160601b03169392505050565b600154600090600160a01b900460ff16612079576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006120906119af565b146120db576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b6120e3610f42565b90506001805460ff60a01b1916600160a01b17905590565b6001600160a01b0381166000908152600d6020526040812054819081908190818080612126896132b4565b93509050600081600381111561213857fe5b146121565760095b6000806000975097509750975050505050612189565b61215e6127be565b92509050600081600381111561217057fe5b1461217c576009612140565b5060009650919450925090505b9193509193565b60007f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866600260405180828054600181600116156101000203166002900480156122105780601f106121ee576101008083540402835291820191612210565b820191906000526020600020905b8154815290600101906020018083116121fc575b5050915050604051809103902061222561373a565b60408051602080820195909552808201939093526060830191909152306080808401919091528151808403909101815260a0830182528051908401207fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf60c08401526001600160a01b038b1660e084015261010083018a90526101208084018a9052825180850390910181526101408401835280519085012061190160f01b6101608501526101628401829052610182808501829052835180860390910181526101a285018085528151918701919091206000918290526101c2860180865281905260ff8b166101e287015261020286018a90526102228601899052935192965090949293909260019261024280840193601f198301929081900390910190855afa158015612358573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166123aa5760405162461bcd60e51b8152600401808060200182810382526026815260200180615d496026913960400191505060405180910390fd5b6001600160a01b038116600090815260146020526040902080546001810190915589146124085760405162461bcd60e51b8152600401808060200182810382526022815260200180615ac36022913960400191505060405180910390fd5b874211156124475760405162461bcd60e51b8152600401808060200182810382526026815260200180615b6c6026913960400191505060405180910390fd5b612451818b612ed7565b50505050505050505050565b6000610e468261373e565b6000806000611685846137cb565b6001600160a01b039182166000908152600e6020908152604080832093909416825291909152205490565b7fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf81565b6124d58888888888888888611784565b601080546001600160a01b0319166001600160a01b038b81169190911791829055604080516318160ddd60e01b8152905192909116916318160ddd91600480820192602092909190829003018186803b15801561253157600080fd5b505afa158015612545573d6000803e3d6000fd5b505050506040513d602081101561255b57600080fd5b5050505050505050505050565b601260209081526000928352604080842090915290825290205463ffffffff811690600160201b90046001600160601b031682565b6000806125a86119af565b905080156125ce576125c68160108111156125bf57fe5b6040612f57565b915050610e5d565b61177d83613855565b6005546001600160a01b031681565b6000806125f485858561388c565b5095945050505050565b60045461010090046001600160a01b031681565b6005546000906001600160a01b03166315f2405361262e612daf565b600a54600b546040518463ffffffff1660e01b815260040180848152602001838152602001828152602001935050505060206040518083038186803b1580156110f357600080fd5b600154600090600160a01b900460ff166126c4576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006126db6119af565b905080156126f9576112b28160108111156126f257fe5b6046612f57565b6112c3836139d1565b6001546000908190600160a01b900460ff16612752576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006127696119af565b905080156127935761278781601081111561278057fe5b6036612f57565b600092509250506127a4565b61279e333386613a81565b92509250505b6001805460ff60a01b1916600160a01b1790559092909150565b600c546000908190806127d957505060065460009150612869565b60006127e3612daf565b905060006127ef6159ed565b600061280084600a54600b54613dee565b93509050600081600381111561281257fe5b14612827579550600094506128699350505050565b6128318386613e2c565b92509050600081600381111561284357fe5b14612858579550600094506128699350505050565b505160009550935061286992505050565b9091565b60048054604080516317b9b84b60e31b815230938101939093526001600160a01b0386811660248501528581166044850152606484018590529051600093849361010090049092169163bdcdc25891608480830192602092919082900301818787803b1580156128dc57600080fd5b505af11580156128f0573d6000803e3d6000fd5b505050506040513d602081101561290657600080fd5b5051905080156129255761291d6003604a83613608565b9150506111cb565b836001600160a01b0316856001600160a01b0316141561294b5761291d6002604b612f57565b6000856001600160a01b0316876001600160a01b031614156129705750600019612998565b506001600160a01b038086166000908152600e60209081526040808320938a16835292905220545b6000806000806129a8858961357d565b909450925060008460038111156129bb57fe5b146129d9576129cc6009604b612f57565b96505050505050506111cb565b6001600160a01b038a166000908152600d60205260409020546129fc908961357d565b90945091506000846003811115612a0f57fe5b14612a20576129cc6009604c612f57565b6001600160a01b0389166000908152600d6020526040902054612a43908961366e565b90945090506000846003811115612a5657fe5b14612a67576129cc6009604d612f57565b6001600160a01b03808b166000908152600d6020526040808220859055918b168152208190556000198514612abf576001600160a01b03808b166000908152600e60209081526040808320938f168352929052208390555b886001600160a01b03168a6001600160a01b0316600080516020615cd08339815191528a6040518082815260200191505060405180910390a35060009a9950505050505050505050565b816001600160a01b0316836001600160a01b031614158015612b3457506000816001600160601b0316115b15612c9f576001600160a01b03831615612bec576001600160a01b03831660009081526013602052604081205463ffffffff169081612b74576000612bb3565b6001600160a01b0385166000908152601260209081526040808320600019860163ffffffff168452909152902054600160201b90046001600160601b03165b90506000612bda8285604051806060016040528060288152602001615d2160289139613edd565b9050612be886848484613f87565b5050505b6001600160a01b03821615612c9f576001600160a01b03821660009081526013602052604081205463ffffffff169081612c27576000612c66565b6001600160a01b0384166000908152601260209081526040808320600019860163ffffffff168452909152902054600160201b90046001600160601b03165b90506000612c8d8285604051806060016040528060278152602001615ca960279139614146565b9050612c9b85848484613f87565b5050505b505050565b6001546000908190600160a01b900460ff16612cf4576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000612d0b6119af565b90508015612d3557612d29816010811115612d2257fe5b6035612f57565b60009250925050612d46565b612d40338686613a81565b92509250505b6001805460ff60a01b1916600160a01b17905590939092509050565b600080600080612d7286866135a0565b90925090506000826003811115612d8557fe5b14612d965750915060009050612da8565b6000612da1826141a7565b9350935050505b9250929050565b601054604080516370a0823160e01b815230600482015290516000926001600160a01b03169182916370a0823191602480820192602092909190829003018186803b158015612dfd57600080fd5b505afa158015612e11573d6000803e3d6000fd5b505050506040513d6020811015612e2757600080fd5b505191505090565b600154600090600160a01b900460ff16612e7d576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000612e946119af565b90508015612eb2576112b2816010811115612eab57fe5b604e612f57565b612ebb836141b6565b509150506001805460ff60a01b1916600160a01b179055919050565b6001600160a01b0380831660008181526011602081815260408084208054600d845282862054949093528787166001600160a01b03198416811790915590519190951694919391928592917f3134e8a2e6d97e929a7e54011ea5485d7d196dd5f0ba4d4ef95803e8e3fc257f9190a4612f51828483612b09565b50505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0836010811115612f8657fe5b836051811115612f9257fe5b604080519283526020830191909152600082820152519081900360600190a182601081111561177d57fe5b6000806000612fca6110ae565b9050336001600160a01b03821614612ff157612fe860016031612f57565b92505050610e5d565b612ff9613366565b6008541461300d57612fe8600a6033612f57565b83613016612daf565b101561302857612fe8600e6032612f57565b600b5484111561303e57612fe860026034612f57565b600b5484810392508211156130845760405162461bcd60e51b8152600401808060200182810382526024815260200180615e006024913960400191505060405180910390fd5b600b829055613093818561429e565b604080516001600160a01b03831681526020810186905280820184905290517f3bad0c59cf2f06e7314077049f48a93578cd16f5ef92329f1dab1420a99c177e9181900360600190a16000949350505050565b600080600460019054906101000a90046001600160a01b03169050826001600160a01b0316634e1647fb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561313a57600080fd5b505afa15801561314e573d6000803e3d6000fd5b505050506040513d602081101561316457600080fd5b50516131b7576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b600480546001600160a01b038086166101008102610100600160a81b031990931692909217909255604080519284168352602083019190915280517ff9b6a28700579d5c8fab50f0ac2dcaa52109b85c369c4f511fcc873330ab6cbb9281900390910190a1600061177d565b6001546000908190600160a01b900460ff16613273576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b19169055600061328a6119af565b905080156132a8576127878160108111156132a157fe5b6027612f57565b61279e3360008661438f565b6001600160a01b0381166000908152600f60205260408120805482918291829182916132ea5760008095509550505050506119aa565b6132fa8160000154600954614876565b9094509250600084600381111561330d57fe5b146133225783600095509550505050506119aa565b6133308382600101546148b5565b9094509150600084600381111561334357fe5b146133585783600095509550505050506119aa565b506000945092505050915091565b4390565b600080613375613366565b60085414613389576125c6600a6041612f57565b600560009054906101000a90046001600160a01b03169050826001600160a01b0316632191f92a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156133da57600080fd5b505afa1580156133ee573d6000803e3d6000fd5b505050506040513d602081101561340457600080fd5b5051613457576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b600580546001600160a01b0319166001600160a01b03858116918217909255604080519284168352602083019190915280517fedffc32e068c7c95dfd4bdfd5c4d939a084d6b11c4199eac8436ed234d72f9269281900390910190a1600061177d565b6000806000600160149054906101000a900460ff1661350d576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006135246119af565b905080156135515761354281601081111561353b57fe5b601e612f57565b60008093509350935050613563565b61355b33866148e0565b935093509350505b6001805460ff60a01b1916600160a01b1790559193909250565b600080838311613594575060009050818303612da8565b50600390506000612da8565b60006135aa6159ed565b6000806135bb866000015186614876565b909250905060008260038111156135ce57fe5b146135ed57506040805160208101909152600081529092509050612da8565b60408051602081019091529081526000969095509350505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa084601081111561363757fe5b84605181111561364357fe5b604080519283526020830191909152818101859052519081900360600190a18360108111156111cb57fe5b60008083830184811061368657600092509050612da8565b600260009250925050612da8565b6000806000806136a487876135a0565b909250905060008260038111156136b757fe5b146136c857509150600090506136e1565b6136da6136d4826141a7565b8661366e565b9350935050505b935093915050565b6000806136f886868686614cc8565b905080613731576001600160a01b0380851660009081526011602052604080822054888416835291205461373192918216911685612b09565b95945050505050565b4690565b600154600090600160a01b900460ff1661378c576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006137a36119af565b905080156137c1576112b28160108111156137ba57fe5b6008612f57565b6112c33384614eae565b6001546000908190600160a01b900460ff1661381b576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006138326119af565b90508015613849576127878160108111156132a157fe5b61279e3385600061438f565b600061385f6110ae565b6001600160a01b0316336001600160a01b0316146138835761166760016042612f57565b610e468261336a565b6001546000908190600160a01b900460ff166138dc576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006138f36119af565b9050801561391d5761391181601081111561390a57fe5b600f612f57565b600092509250506139b4565b836001600160a01b031663a6afed956040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561395857600080fd5b505af115801561396c573d6000803e3d6000fd5b505050506040513d602081101561398257600080fd5b5051905080156139a25761391181601081111561399b57fe5b6010612f57565b6139ae3387878761514c565b92509250505b6001805460ff60a01b1916600160a01b1790559094909350915050565b60006139db6110ae565b6001600160a01b0316336001600160a01b0316146139ff5761166760016047612f57565b613a07613366565b60085414613a1b57611667600a6048612f57565b670de0b6b3a7640000821115613a375761166760026049612f57565b6007805490839055604080518281526020810185905281517faaa68312e2ea9d50e16af5068410ab56e1a1fd06037b1a35664812c30f821460929181900390910190a1600061177d565b6004805460408051631200453160e11b815230938101939093526001600160a01b03868116602485015285811660448501526064840185905290516000938493849361010090910416916324008a629160848082019260209290919082900301818787803b158015613af257600080fd5b505af1158015613b06573d6000803e3d6000fd5b505050506040513d6020811015613b1c57600080fd5b505190508015613b3f57613b336003603883613608565b600092509250506136e1565b613b47613366565b60085414613b5b57613b33600a6039612f57565b613b63615a00565b6001600160a01b0386166000908152600f60205260409020600101546060820152613b8d866132b4565b6080830181905260208301826003811115613ba457fe5b6003811115613baf57fe5b9052506000905081602001516003811115613bc657fe5b14613bef57613be26009603783602001516003811115611c8957fe5b60009350935050506136e1565b600a5481608001511115613c0657600a5460808201525b8060800151851115613c215760808101516040820152613c29565b604081018590525b613c37878260400151615650565b60e082018190526080820151613c4c9161357d565b60a0830181905260208301826003811115613c6357fe5b6003811115613c6e57fe5b9052506000905081602001516003811115613c8557fe5b14613cc15760405162461bcd60e51b815260040180806020018281038252603a815260200180615c6f603a913960400191505060405180910390fd5b613cd1600a548260e0015161357d565b60c0830181905260208301826003811115613ce857fe5b6003811115613cf357fe5b9052506000905081602001516003811115613d0a57fe5b14613d465760405162461bcd60e51b8152600401808060200182810382526031815260200180615cf06031913960400191505060405180910390fd5b60a080820180516001600160a01b03808a166000818152600f602090815260409182902094855560095460019095019490945560c0870151600a81905560e088015195518251948f16855294840192909252828101949094526060820192909252608081019190915290517f1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1929181900390910190a160e00151600097909650945050505050565b600080600080613dfe878761366e565b90925090506000826003811115613e1157fe5b14613e2257509150600090506136e1565b6136da818661357d565b6000613e366159ed565b600080613e4b86670de0b6b3a7640000614876565b90925090506000826003811115613e5e57fe5b14613e7d57506040805160208101909152600081529092509050612da8565b600080613e8a83886148b5565b90925090506000826003811115613e9d57fe5b14613ec05781604051806020016040528060008152509550955050505050612da8565b604080516020810190915290815260009890975095505050505050565b6000836001600160601b0316836001600160601b031611158290613f7f5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613f44578181015183820152602001613f2c565b50505050905090810190601f168015613f715780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000613fab43604051806060016040528060348152602001615b086034913961589a565b905060008463ffffffff16118015613ff457506001600160a01b038516600090815260126020908152604080832063ffffffff6000198901811685529252909120548282169116145b15614053576001600160a01b0385166000908152601260209081526040808320600019880163ffffffff168452909152902080546fffffffffffffffffffffffff000000001916600160201b6001600160601b038516021790556140f2565b60408051808201825263ffffffff80841682526001600160601b0380861660208085019182526001600160a01b038b166000818152601283528781208c871682528352878120965187549451909516600160201b026fffffffffffffffffffffffff000000001995871663ffffffff19958616179590951694909417909555938252601390935292909220805460018801909316929091169190911790555b604080516001600160601b0380861682528416602082015281516001600160a01b038816927fdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a724928290030190a25050505050565b6000838301826001600160601b03808716908316101561109c5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315613f44578181015183820152602001613f2c565b51670de0b6b3a7640000900490565b6000806000806141c4613366565b600854146141e3576141d8600a604f612f57565b935091506119aa9050565b6141ed3386615650565b905080600b54019150600b5482101561424d576040805162461bcd60e51b815260206004820181905260248201527f61646420726573657276657320756e6578706563746564206f766572666c6f77604482015290519081900360640190fd5b600b829055604080513381526020810183905280820184905290517fa91e67c5ea634cd43a12c5a482724b03de01e85ca68702a53d0c2f45cb7c1dc59181900360600190a160009350915050915091565b6010546040805163a9059cbb60e01b81526001600160a01b0385811660048301526024820185905291519190921691829163a9059cbb9160448082019260009290919082900301818387803b1580156142f657600080fd5b505af115801561430a573d6000803e3d6000fd5b5050505060003d60008114614326576020811461433057600080fd5b600019915061433c565b60206000803e60005191505b5080612f51576040805162461bcd60e51b815260206004820152601960248201527f544f4b454e5f5452414e534645525f4f55545f4641494c454400000000000000604482015290519081900360640190fd5b60008083158061439d575082155b6143d85760405162461bcd60e51b8152600401808060200182810382526034815260200180615dcc6034913960400191505060405180910390fd5b6143e0615a46565b6143e86127be565b60408301819052602083018260038111156143ff57fe5b600381111561440a57fe5b905250600090508160200151600381111561442157fe5b1461443d57613b336009602b83602001516003811115611c8957fe5b84156144be5760608101859052604080516020810182529082015181526144649086612d62565b608083018190526020830182600381111561447b57fe5b600381111561448657fe5b905250600090508160200151600381111561449d57fe5b146144b957613b336009602983602001516003811115611c8957fe5b614537565b6144da84604051806020016040528084604001518152506158f7565b60608301819052602083018260038111156144f157fe5b60038111156144fc57fe5b905250600090508160200151600381111561451357fe5b1461452f57613b336009602a83602001516003811115611c8957fe5b608081018490525b6000600460019054906101000a90046001600160a01b03166001600160a01b031663eabe7d91308985606001516040518463ffffffff1660e01b815260040180846001600160a01b03168152602001836001600160a01b031681526020018281526020019350505050602060405180830381600087803b1580156145ba57600080fd5b505af11580156145ce573d6000803e3d6000fd5b505050506040513d60208110156145e457600080fd5b5051905080156145fb57613be26003602883613608565b614603613366565b6008541461461757613be2600a602c612f57565b614627600c54836060015161357d565b60a084018190526020840182600381111561463e57fe5b600381111561464957fe5b905250600090508260200151600381111561466057fe5b1461467c57613be26009602e84602001516003811115611c8957fe5b6001600160a01b0387166000908152600d602052604090205460608301516146a4919061357d565b60c08401819052602084018260038111156146bb57fe5b60038111156146c657fe5b90525060009050826020015160038111156146dd57fe5b146146f957613be26009602d84602001516003811115611c8957fe5b8160800151614706612daf565b101561471857613be2600e602f612f57565b61472687836080015161429e565b60a0820151600c5560c08201516001600160a01b0388166000818152600d6020908152604091829020939093556060850151815190815290513093600080516020615cd0833981519152928290030190a37fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929878360800151846060015160405180846001600160a01b03168152602001838152602001828152602001935050505060405180910390a16004805460808401516060850151604080516351dff98960e01b815230958101959095526001600160a01b038c81166024870152604486019390935260648501919091525161010090920416916351dff98991608480830192600092919082900301818387803b15801561484257600080fd5b505af1158015614856573d6000803e3d6000fd5b5060009250614863915050565b8260600151935093505050935093915050565b6000808361488957506000905080612da8565b8383028385828161489657fe5b04146148aa57600260009250925050612da8565b600092509050612da8565b600080826148c95750600190506000612da8565b60008385816148d457fe5b04915091509250929050565b6004805460408051634ef4c3e160e01b815230938101939093526001600160a01b0385811660248501526044840185905290516000938493849384936101009092041691634ef4c3e191606480830192602092919082900301818787803b15801561494a57600080fd5b505af115801561495e573d6000803e3d6000fd5b505050506040513d602081101561497457600080fd5b50519050801561499a5761498b6003601f83613608565b60008093509350935050614cc1565b6149a2613366565b600854146149b65761498b600a6022612f57565b6149be615a46565b6149c66127be565b60408301819052602083018260038111156149dd57fe5b60038111156149e857fe5b90525060009050816020015160038111156149ff57fe5b14614a2b57614a1b6009602183602001516003811115611c8957fe5b6000809450945094505050614cc1565b614a358787615650565b60c0820181905260408051602081018252908301518152614a5691906158f7565b6060830181905260208301826003811115614a6d57fe5b6003811115614a7857fe5b9052506000905081602001516003811115614a8f57fe5b14614ae1576040805162461bcd60e51b815260206004820181905260248201527f4d494e545f45584348414e47455f43414c43554c4154494f4e5f4641494c4544604482015290519081900360640190fd5b614af1600c54826060015161366e565b6080830181905260208301826003811115614b0857fe5b6003811115614b1357fe5b9052506000905081602001516003811115614b2a57fe5b14614b665760405162461bcd60e51b8152600401808060200182810382526028815260200180615da46028913960400191505060405180910390fd5b6001600160a01b0387166000908152600d60205260409020546060820151614b8e919061366e565b60a0830181905260208301826003811115614ba557fe5b6003811115614bb057fe5b9052506000905081602001516003811115614bc757fe5b14614c035760405162461bcd60e51b815260040180806020018281038252602b815260200180615bb4602b913960400191505060405180910390fd5b6080810151600c5560a08101516001600160a01b0388166000818152600d60209081526040918290209390935560c084015160608086015183519485529484019190915282820193909352517f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f929181900390910190a1606081015160408051918252516001600160a01b038916913091600080516020615cd08339815191529181900360200190a360008160c00151826060015194509450945050505b9250925092565b600480546040805163d02f735160e01b815230938101939093526001600160a01b03878116602485015286811660448501528581166064850152608484018590529051600093849361010090049092169163d02f73519160a480830192602092919082900301818787803b158015614d3f57600080fd5b505af1158015614d53573d6000803e3d6000fd5b505050506040513d6020811015614d6957600080fd5b505190508015614d805761291d6003601b83613608565b846001600160a01b0316846001600160a01b03161415614da65761291d6006601c612f57565b6001600160a01b0384166000908152600d602052604081205481908190614dcd908761357d565b90935091506000836003811115614de057fe5b14614e0357614df86009601a856003811115611c8957fe5b9450505050506111cb565b6001600160a01b0388166000908152600d6020526040902054614e26908761366e565b90935090506000836003811115614e3957fe5b14614e5157614df860096019856003811115611c8957fe5b6001600160a01b038088166000818152600d60209081526040808320879055938c168083529184902085905583518a815293519193600080516020615cd0833981519152929081900390910190a360009998505050505050505050565b600480546040805163368f515360e21b815230938101939093526001600160a01b038581166024850152604484018590529051600093849361010090049092169163da3d454c91606480830192602092919082900301818787803b158015614f1557600080fd5b505af1158015614f29573d6000803e3d6000fd5b505050506040513d6020811015614f3f57600080fd5b505190508015614f5e57614f566003600e83613608565b915050610e46565b614f66613366565b60085414614f7957614f56600a80612f57565b82614f82612daf565b1015614f9457614f56600e6009612f57565b614f9c615a84565b614fa5856132b4565b6020830181905282826003811115614fb957fe5b6003811115614fc457fe5b9052506000905081516003811115614fd857fe5b14614ffd57614ff46009600783600001516003811115611c8957fe5b92505050610e46565b61500b81602001518561366e565b604083018190528282600381111561501f57fe5b600381111561502a57fe5b905250600090508151600381111561503e57fe5b1461505a57614ff46009600c83600001516003811115611c8957fe5b615066600a548561366e565b606083018190528282600381111561507a57fe5b600381111561508557fe5b905250600090508151600381111561509957fe5b146150b557614ff46009600b83600001516003811115611c8957fe5b6150bf858561429e565b604080820180516001600160a01b0388166000818152600f602090815290859020928355600954600190930192909255606080860151600a81905593518551928352928201899052818501929092529081019190915290517f13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab809181900360800190a1600095945050505050565b6004805460408051632fe3f38f60e11b815230938101939093526001600160a01b03848116602485015287811660448501528681166064850152608484018690529051600093849384936101009091041691635fc7e71e9160a48082019260209290919082900301818787803b1580156151c557600080fd5b505af11580156151d9573d6000803e3d6000fd5b505050506040513d60208110156151ef57600080fd5b505190508015615212576152066003601283613608565b60009250925050615647565b61521a613366565b6008541461522e57615206600a6016612f57565b615236613366565b846001600160a01b0316636c540baf6040518163ffffffff1660e01b815260040160206040518083038186803b15801561526f57600080fd5b505afa158015615283573d6000803e3d6000fd5b505050506040513d602081101561529957600080fd5b5051146152ac57615206600a6011612f57565b866001600160a01b0316866001600160a01b031614156152d25761520660066017612f57565b846152e35761520660076015612f57565b6000198514156152f95761520660076014612f57565b600080615307898989613a81565b909250905081156153365761532882601081111561532157fe5b6018612f57565b600094509450505050615647565b600480546040805163c488847b60e01b815230938101939093526001600160a01b038981166024850152604484018590528151600094859461010090049092169263c488847b9260648082019391829003018186803b15801561539857600080fd5b505afa1580156153ac573d6000803e3d6000fd5b505050506040513d60408110156153c257600080fd5b5080516020909101519092509050811561540d5760405162461bcd60e51b8152600401808060200182810382526032815260200180615c166032913960400191505060405180910390fd5b80886001600160a01b03166370a082318c6040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561545b57600080fd5b505afa15801561546f573d6000803e3d6000fd5b505050506040513d602081101561548557600080fd5b505110156154da576040805162461bcd60e51b815260206004820152601860248201527f4c49515549444154455f5345495a455f544f4f5f4d5543480000000000000000604482015290519081900360640190fd5b60006001600160a01b038916301415615500576154f9308d8d856136e9565b9050615597565b886001600160a01b031663b2a02ff18d8d856040518463ffffffff1660e01b815260040180846001600160a01b03168152602001836001600160a01b031681526020018281526020019350505050602060405180830381600087803b15801561556857600080fd5b505af115801561557c573d6000803e3d6000fd5b505050506040513d602081101561559257600080fd5b505190505b80156155e1576040805162461bcd60e51b81526020600482015260146024820152731d1bdad95b881cd95a5e9d5c994819985a5b195960621b604482015290519081900360640190fd5b604080516001600160a01b03808f168252808e1660208301528183018790528b1660608201526080810184905290517f298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb529181900360a00190a16000975092955050505050505b94509492505050565b601054604080516370a0823160e01b815230600482015290516000926001600160a01b031691839183916370a08231916024808301926020929190829003018186803b15801561569f57600080fd5b505afa1580156156b3573d6000803e3d6000fd5b505050506040513d60208110156156c957600080fd5b5051604080516323b872dd60e01b81526001600160a01b038881166004830152306024830152604482018890529151929350908416916323b872dd9160648082019260009290919082900301818387803b15801561572657600080fd5b505af115801561573a573d6000803e3d6000fd5b5050505060003d60008114615756576020811461576057600080fd5b600019915061576c565b60206000803e60005191505b50806157bf576040805162461bcd60e51b815260206004820152601860248201527f544f4b454e5f5452414e534645525f494e5f4641494c45440000000000000000604482015290519081900360640190fd5b601054604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561580a57600080fd5b505afa15801561581e573d6000803e3d6000fd5b505050506040513d602081101561583457600080fd5b505190508281101561588d576040805162461bcd60e51b815260206004820152601a60248201527f544f4b454e5f5452414e534645525f494e5f4f564552464c4f57000000000000604482015290519081900360640190fd5b9190910395945050505050565b600081600160201b84106158ef5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315613f44578181015183820152602001613f2c565b509192915050565b600080600080612d728686600061590c6159ed565b600080615921670de0b6b3a764000087614876565b9092509050600082600381111561593457fe5b1461595357506040805160208101909152600081529092509050612da8565b612da1818660000151613e2c565b828054600181600116156101000203166002900490600052602060002090601f01602090048101928261599757600085556159dd565b82601f106159b057805160ff19168380011785556159dd565b828001600101855582156159dd579182015b828111156159dd5782518255916020019190600101906159c2565b506159e9929150615aad565b5090565b6040518060200160405280600081525090565b6040805161010081019091528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805160e0810190915280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b604080516080810190915280600081526020016000815260200160008152602001600081525090565b5b808211156159e95760008155600101615aae56fe505069653a3a64656c656761746542795369673a20696e76616c6964206e6f6e63656d61726b6574206d6179206f6e6c7920626520696e697469616c697a6564206f6e6365505069653a3a5f7772697465436865636b706f696e743a20626c6f636b206e756d62657220657863656564732033322062697473696e697469616c2065786368616e67652072617465206d7573742062652067726561746572207468616e207a65726f2e505069653a3a64656c656761746542795369673a207369676e6174757265206578706972656473657474696e6720696e7465726573742072617465206d6f64656c206661696c65644d494e545f4e45575f4143434f554e545f42414c414e43455f43414c43554c4154494f4e5f4641494c4544626f72726f7742616c616e636553746f7265643a20626f72726f7742616c616e636553746f726564496e7465726e616c206661696c65644c49515549444154455f434f4e54524f4c4c45525f43414c43554c4154455f414d4f554e545f5345495a455f4641494c4544505069653a3a6765745072696f72566f7465733a206e6f74207965742064657465726d696e656452455041595f424f52524f575f4e45575f4143434f554e545f424f52524f575f42414c414e43455f43414c43554c4154494f4e5f4641494c4544505069653a3a5f6d6f7665566f7465733a20766f746520616d6f756e74206f766572666c6f7773ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef52455041595f424f52524f575f4e45575f544f54414c5f42414c414e43455f43414c43554c4154494f4e5f4641494c4544505069653a3a5f6d6f7665566f7465733a20766f746520616d6f756e7420756e646572666c6f7773505069653a3a64656c656761746542795369673a20696e76616c6964207369676e617475726565786368616e67655261746553746f7265643a2065786368616e67655261746553746f726564496e7465726e616c206661696c65644d494e545f4e45575f544f54414c5f535550504c595f43414c43554c4154494f4e5f4641494c45446f6e65206f662072656465656d546f6b656e73496e206f722072656465656d416d6f756e74496e206d757374206265207a65726f72656475636520726573657276657320756e657870656374656420756e646572666c6f77a264697066735822122020f3a885f3c5cf9d8fbae18c3a1bdc5360e118c179c4b8969ee2d17dab45fd5a64736f6c63430007060033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061038e5760003560e01c806383de424e116101de578063bd6d894d1161010f578063eedf9c72116100ad578063f5e3c4621161007c578063f5e3c46214610cf1578063f77c479114610d27578063f8f9da2814610d2f578063fca7820b14610d375761038e565b8063eedf9c7214610b06578063f1127ed814610c69578063f2b3abbd14610cc3578063f3fdb15a14610ce95761038e565b8063c5ebeaec116100e9578063c5ebeaec14610a96578063db006a7514610ab3578063dd62ed3e14610ad0578063e7a324dc14610afe5761038e565b8063bd6d894d146109fb578063c37f68e214610a03578063c3cda52014610a4f5761038e565b8063a3e94ddd1161017c578063aa5af0fd11610156578063aa5af0fd1461098f578063ae9d70b014610997578063b2a02ff11461099f578063b4b5ea57146109d55761038e565b8063a3e94ddd1461091c578063a6afed951461095b578063a9059cbb146109635761038e565b806395d89b41116101b857806395d89b411461077557806395dd91931461077d5780639ea21c3d146107a3578063a0712d68146108ff5761038e565b806383de424e1461072a578063852a12e3146107505780638f840ddd1461076d5761038e565b80633e941010116102c35780636c540baf1161026157806373acee981161023057806373acee98146106ac578063782d6fe1146106b45780637b103999146106fc5780637ecebe00146107045761038e565b80636c540baf146106375780636f307dc31461063f5780636fcfff451461064757806370a08231146106865761038e565b80635a890c0e1161029d5780635a890c0e146105e25780635c19a95c146105ea5780635c60da1b14610612578063601a0bf11461061a5761038e565b80633e9410101461059757806347bd3718146105b4578063587cde1e146105bc5761038e565b806320606b7011610330578063313ce5671161030a578063313ce567146105275780633176b739146105455780633af9e669146105695780633b1d21a21461058f5761038e565b806320606b70146104bd57806323b872dd146104c55780632608f818146104fb5761038e565b8063173b99041161036c578063173b99041461047f57806317bfdfbc1461048757806318160ddd146104ad578063182df0f5146104b55761038e565b806306fdde0314610393578063095ea7b3146104105780630e75270214610450575b600080fd5b61039b610d54565b6040805160208082528351818301528351919283929083019185019080838360005b838110156103d55781810151838201526020016103bd565b50505050905090810190601f1680156104025780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61043c6004803603604081101561042657600080fd5b506001600160a01b038135169060200135610ddf565b604080519115158252519081900360200190f35b61046d6004803603602081101561046657600080fd5b5035610e4c565b60408051918252519081900360200190f35b61046d610e62565b61046d6004803603602081101561049d57600080fd5b50356001600160a01b0316610e68565b61046d610f3c565b61046d610f42565b61046d610fa5565b61043c600480360360608110156104db57600080fd5b506001600160a01b03813581169160208101359091169060400135610fc9565b61046d6004803603604081101561051157600080fd5b506001600160a01b03813516906020013561108f565b61052f6110a5565b6040805160ff9092168252519081900360200190f35b61054d6110ae565b604080516001600160a01b039092168252519081900360200190f35b61046d6004803603602081101561057f57600080fd5b50356001600160a01b0316611124565b61046d6111d3565b61046d600480360360208110156105ad57600080fd5b50356111e2565b61046d6111ed565b61054d600480360360208110156105d257600080fd5b50356001600160a01b03166111f3565b61043c61120e565b6106106004803603602081101561060057600080fd5b50356001600160a01b0316611213565b005b61054d611220565b61046d6004803603602081101561063057600080fd5b503561122f565b61046d6112de565b61054d6112e4565b61066d6004803603602081101561065d57600080fd5b50356001600160a01b03166112f3565b6040805163ffffffff9092168252519081900360200190f35b61046d6004803603602081101561069c57600080fd5b50356001600160a01b031661130b565b61046d611326565b6106e0600480360360408110156106ca57600080fd5b506001600160a01b0381351690602001356113f0565b604080516001600160601b039092168252519081900360200190f35b61054d611618565b61046d6004803603602081101561071a57600080fd5b50356001600160a01b0316611627565b61046d6004803603602081101561074057600080fd5b50356001600160a01b0316611639565b61046d6004803603602081101561076657600080fd5b5035611677565b61046d6116bf565b61039b6116c5565b61046d6004803603602081101561079357600080fd5b50356001600160a01b0316611720565b61061060048036036101008110156107ba57600080fd5b6001600160a01b038235811692602081013582169260408201359092169160608201359160808101359181019060c0810160a0820135600160201b81111561080157600080fd5b82018360208201111561081357600080fd5b803590602001918460018302840111600160201b8311171561083457600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b81111561088657600080fd5b82018360208201111561089857600080fd5b803590602001918460018302840111600160201b831117156108b957600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050903560ff1691506117849050565b61046d6004803603602081101561091557600080fd5b5035611949565b6109426004803603602081101561093257600080fd5b50356001600160a01b0316611989565b6040805192835260208301919091528051918290030190f35b61046d6119af565b61043c6004803603604081101561097957600080fd5b506001600160a01b038135169060200135611e00565b61046d611ec4565b61046d611eca565b61046d600480360360608110156109b557600080fd5b506001600160a01b03813581169160208101359091169060400135611f38565b6106e0600480360360208110156109eb57600080fd5b50356001600160a01b0316611fbb565b61046d61202b565b610a2960048036036020811015610a1957600080fd5b50356001600160a01b03166120fb565b604080519485526020850193909352838301919091526060830152519081900360800190f35b610610600480360360c0811015610a6557600080fd5b506001600160a01b038135169060208101359060408101359060ff6060820135169060808101359060a00135612190565b61046d60048036036020811015610aac57600080fd5b503561245d565b61046d60048036036020811015610ac957600080fd5b5035612468565b61046d60048036036040811015610ae657600080fd5b506001600160a01b0381358116916020013516612476565b61046d6124a1565b6106106004803603610120811015610b1d57600080fd5b6001600160a01b038235811692602081013582169260408201358316926060830135169160808101359160a0820135919081019060e0810160c0820135600160201b811115610b6b57600080fd5b820183602082011115610b7d57600080fd5b803590602001918460018302840111600160201b83111715610b9e57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b811115610bf057600080fd5b820183602082011115610c0257600080fd5b803590602001918460018302840111600160201b83111715610c2357600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050903560ff1691506124c59050565b610c9b60048036036040811015610c7f57600080fd5b5080356001600160a01b0316906020013563ffffffff16612568565b6040805163ffffffff90931683526001600160601b0390911660208301528051918290030190f35b61046d60048036036020811015610cd957600080fd5b50356001600160a01b031661259d565b61054d6125d7565b61046d60048036036060811015610d0757600080fd5b506001600160a01b038135811691602081013591604090910135166125e6565b61054d6125fe565b61046d612612565b61046d60048036036020811015610d4d57600080fd5b5035612676565b6002805460408051602060018416156101000260001901909316849004601f81018490048402820184019092528181529291830182828015610dd75780601f10610dac57610100808354040283529160200191610dd7565b820191906000526020600020905b815481529060010190602001808311610dba57829003601f168201915b505050505081565b336000818152600e602090815260408083206001600160a01b03871680855290835281842086905581518681529151939493909284927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a360019150505b92915050565b600080610e5883612702565b509150505b919050565b60075481565b600154600090600160a01b900460ff16610eb6576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000610ecd6119af565b14610f18576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b610f2182611720565b90505b6001805460ff60a01b1916600160a01b179055919050565b600c5481565b6000806000610f4f6127be565b90925090506000826003811115610f6257fe5b14610f9e5760405162461bcd60e51b8152600401808060200182810382526035815260200180615d6f6035913960400191505060405180910390fd5b9150505b90565b7f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86681565b600154600090600160a01b900460ff16611017576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006110323386868661286d565b1461103f57506000611075565b6001600160a01b0380851660009081526011602052604080822054868416835291205461107192918216911684612b09565b5060015b6001805460ff60a01b1916600160a01b1790559392505050565b60008061109c8484612ca4565b50949350505050565b60045460ff1681565b600154604080516303e1469160e61b815290516000926001600160a01b03169163f851a440916004808301926020929190829003018186803b1580156110f357600080fd5b505afa158015611107573d6000803e3d6000fd5b505050506040513d602081101561111d57600080fd5b5051905090565b600080604051806020016040528061113a61202b565b90526001600160a01b0384166000908152600d6020526040812054919250908190611166908490612d62565b9092509050600082600381111561117957fe5b146111cb576040805162461bcd60e51b815260206004820152601f60248201527f62616c616e636520636f756c64206e6f742062652063616c63756c6174656400604482015290519081900360640190fd5b949350505050565b60006111dd612daf565b905090565b6000610e4682612e2f565b600a5481565b6011602052600090815260409020546001600160a01b031681565b600181565b61121d3382612ed7565b50565b6000546001600160a01b031681565b600154600090600160a01b900460ff1661127d576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006112946119af565b905080156112ba576112b28160108111156112ab57fe5b6030612f57565b915050610f24565b6112c383612fbd565b9150506001805460ff60a01b1916600160a01b179055919050565b60085481565b6010546001600160a01b031681565b60136020526000908152604090205463ffffffff1681565b6001600160a01b03166000908152600d602052604090205490565b600154600090600160a01b900460ff16611374576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b19169055600061138b6119af565b146113d6576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b50600a546001805460ff60a01b1916600160a01b17905590565b60004382106114305760405162461bcd60e51b8152600401808060200182810382526027815260200180615c486027913960400191505060405180910390fd5b6001600160a01b03831660009081526013602052604090205463ffffffff168061145e576000915050610e46565b6001600160a01b038416600090815260126020908152604080832063ffffffff6000198601811685529252909120541683106114da576001600160a01b03841660009081526012602090815260408083206000199490940163ffffffff1683529290522054600160201b90046001600160601b03169050610e46565b6001600160a01b038416600090815260126020908152604080832083805290915290205463ffffffff16831015611515576000915050610e46565b600060001982015b8163ffffffff168163ffffffff1611156115d3576000600263ffffffff848403166001600160a01b038916600090815260126020908152604080832094909304860363ffffffff818116845294825291839020835180850190945254938416808452600160201b9094046001600160601b0316908301529250908714156115ae57602001519450610e469350505050565b805163ffffffff168711156115c5578193506115cc565b6001820392505b505061151d565b506001600160a01b038516600090815260126020908152604080832063ffffffff909416835292905220546001600160601b03600160201b9091041691505092915050565b6001546001600160a01b031681565b60146020526000908152604090205481565b60006116436110ae565b6001600160a01b0316336001600160a01b03161461166e576116676001603f612f57565b9050610e5d565b610e46826130e6565b600080600061168584613223565b9150915081600014156116b857336000908152601160205260408120546116b8916001600160a01b039091169083612b09565b5092915050565b600b5481565b6003805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610dd75780601f10610dac57610100808354040283529160200191610dd7565b600080600061172e846132b4565b9092509050600082600381111561174157fe5b1461177d5760405162461bcd60e51b8152600401808060200182810382526037815260200180615bdf6037913960400191505060405180910390fd5b9392505050565b6008541580156117945750600954155b6117cf5760405162461bcd60e51b8152600401808060200182810382526023815260200180615ae56023913960400191505060405180910390fd5b600180546001600160a01b0319166001600160a01b038a1617905560068590558461182b5760405162461bcd60e51b8152600401808060200182810382526030815260200180615b3c6030913960400191505060405180910390fd5b6007849055600061183b886130e6565b90508015611890576040805162461bcd60e51b815260206004820152601960248201527f73657474696e6720636f6e74726f6c6c6572206661696c656400000000000000604482015290519081900360640190fd5b611898613366565b600855670de0b6b3a76400006009556118b08761336a565b905080156118ef5760405162461bcd60e51b8152600401808060200182810382526022815260200180615b926022913960400191505060405180910390fd5b8351611902906002906020870190615961565b508251611916906003906020860190615961565b50506004805460ff90921660ff1990921691909117905550506001805460ff60a01b1916600160a01b1790555050505050565b6000806000611957846134ba565b925050915081600014156116b857336000908152601160205260408120546116b891906001600160a01b031683612b09565b6001600160a01b0381166000908152600f6020526040902080546001909101545b915091565b6000600460019054906101000a90046001600160a01b03166001600160a01b031663833b1fce6040518163ffffffff1660e01b815260040160206040518083038186803b1580156119ff57600080fd5b505afa158015611a13573d6000803e3d6000fd5b505050506040513d6020811015611a2957600080fd5b50516040805163e0849bfd60e01b815230600482015290516001600160a01b039092169163e0849bfd916024808201926020929091908290030181600087803b158015611a7557600080fd5b505af1158015611a89573d6000803e3d6000fd5b505050506040513d6020811015611a9f57600080fd5b5060009050611aac613366565b60085490915080821415611ac557600092505050610fa2565b6000611acf612daf565b600a54600b54600954600554604080516315f2405360e01b815260048101879052602481018690526044810185905290519596509394929391926000926001600160a01b03909216916315f24053916064808301926020929190829003018186803b158015611b3d57600080fd5b505afa158015611b51573d6000803e3d6000fd5b505050506040513d6020811015611b6757600080fd5b5051905065048c27395000811115611bc6576040805162461bcd60e51b815260206004820152601c60248201527f626f72726f772072617465206973206162737572646c79206869676800000000604482015290519081900360640190fd5b600080611bd3898961357d565b90925090506000826003811115611be657fe5b14611c38576040805162461bcd60e51b815260206004820152601f60248201527f636f756c64206e6f742063616c63756c61746520626c6f636b2064656c746100604482015290519081900360640190fd5b611c406159ed565b600080600080611c5e60405180602001604052808a815250876135a0565b90975094506000876003811115611c7157fe5b14611ca357611c8e60096006896003811115611c8957fe5b613608565b9e505050505050505050505050505050610fa2565b611cad858c612d62565b90975093506000876003811115611cc057fe5b14611cd857611c8e60096001896003811115611c8957fe5b611ce2848c61366e565b90975092506000876003811115611cf557fe5b14611d0d57611c8e60096004896003811115611c8957fe5b611d286040518060200160405280600754815250858c613694565b90975091506000876003811115611d3b57fe5b14611d5357611c8e60096005896003811115611c8957fe5b611d5e858a8b613694565b90975090506000876003811115611d7157fe5b14611d8957611c8e60096003896003811115611c8957fe5b60088e90556009819055600a839055600b829055604080518d815260208101869052808201839052606081018590526080810184905290517f717fee053884ab1935ba6d0140f6ed225371439611d9674ff445419d6a0fa1b79181900360a00190a160009e50505050505050505050505050505090565b600154600090600160a01b900460ff16611e4e576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000611e693333868661286d565b14611e7657506000611eab565b33600090815260116020526040808220546001600160a01b0386811684529190922054611ea7928216911684612b09565b5060015b6001805460ff60a01b1916600160a01b17905592915050565b60095481565b6005546000906001600160a01b031663b8168816611ee6612daf565b600a54600b546007546040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060206040518083038186803b1580156110f357600080fd5b600154600090600160a01b900460ff16611f86576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b19169055611f9f338585856136e9565b90506001805460ff60a01b1916600160a01b1790559392505050565b6001600160a01b03811660009081526013602052604081205463ffffffff1680611fe657600061177d565b6001600160a01b0383166000908152601260209081526040808320600019850163ffffffff168452909152902054600160201b90046001600160601b03169392505050565b600154600090600160a01b900460ff16612079576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006120906119af565b146120db576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b6120e3610f42565b90506001805460ff60a01b1916600160a01b17905590565b6001600160a01b0381166000908152600d6020526040812054819081908190818080612126896132b4565b93509050600081600381111561213857fe5b146121565760095b6000806000975097509750975050505050612189565b61215e6127be565b92509050600081600381111561217057fe5b1461217c576009612140565b5060009650919450925090505b9193509193565b60007f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866600260405180828054600181600116156101000203166002900480156122105780601f106121ee576101008083540402835291820191612210565b820191906000526020600020905b8154815290600101906020018083116121fc575b5050915050604051809103902061222561373a565b60408051602080820195909552808201939093526060830191909152306080808401919091528151808403909101815260a0830182528051908401207fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf60c08401526001600160a01b038b1660e084015261010083018a90526101208084018a9052825180850390910181526101408401835280519085012061190160f01b6101608501526101628401829052610182808501829052835180860390910181526101a285018085528151918701919091206000918290526101c2860180865281905260ff8b166101e287015261020286018a90526102228601899052935192965090949293909260019261024280840193601f198301929081900390910190855afa158015612358573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166123aa5760405162461bcd60e51b8152600401808060200182810382526026815260200180615d496026913960400191505060405180910390fd5b6001600160a01b038116600090815260146020526040902080546001810190915589146124085760405162461bcd60e51b8152600401808060200182810382526022815260200180615ac36022913960400191505060405180910390fd5b874211156124475760405162461bcd60e51b8152600401808060200182810382526026815260200180615b6c6026913960400191505060405180910390fd5b612451818b612ed7565b50505050505050505050565b6000610e468261373e565b6000806000611685846137cb565b6001600160a01b039182166000908152600e6020908152604080832093909416825291909152205490565b7fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf81565b6124d58888888888888888611784565b601080546001600160a01b0319166001600160a01b038b81169190911791829055604080516318160ddd60e01b8152905192909116916318160ddd91600480820192602092909190829003018186803b15801561253157600080fd5b505afa158015612545573d6000803e3d6000fd5b505050506040513d602081101561255b57600080fd5b5050505050505050505050565b601260209081526000928352604080842090915290825290205463ffffffff811690600160201b90046001600160601b031682565b6000806125a86119af565b905080156125ce576125c68160108111156125bf57fe5b6040612f57565b915050610e5d565b61177d83613855565b6005546001600160a01b031681565b6000806125f485858561388c565b5095945050505050565b60045461010090046001600160a01b031681565b6005546000906001600160a01b03166315f2405361262e612daf565b600a54600b546040518463ffffffff1660e01b815260040180848152602001838152602001828152602001935050505060206040518083038186803b1580156110f357600080fd5b600154600090600160a01b900460ff166126c4576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006126db6119af565b905080156126f9576112b28160108111156126f257fe5b6046612f57565b6112c3836139d1565b6001546000908190600160a01b900460ff16612752576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006127696119af565b905080156127935761278781601081111561278057fe5b6036612f57565b600092509250506127a4565b61279e333386613a81565b92509250505b6001805460ff60a01b1916600160a01b1790559092909150565b600c546000908190806127d957505060065460009150612869565b60006127e3612daf565b905060006127ef6159ed565b600061280084600a54600b54613dee565b93509050600081600381111561281257fe5b14612827579550600094506128699350505050565b6128318386613e2c565b92509050600081600381111561284357fe5b14612858579550600094506128699350505050565b505160009550935061286992505050565b9091565b60048054604080516317b9b84b60e31b815230938101939093526001600160a01b0386811660248501528581166044850152606484018590529051600093849361010090049092169163bdcdc25891608480830192602092919082900301818787803b1580156128dc57600080fd5b505af11580156128f0573d6000803e3d6000fd5b505050506040513d602081101561290657600080fd5b5051905080156129255761291d6003604a83613608565b9150506111cb565b836001600160a01b0316856001600160a01b0316141561294b5761291d6002604b612f57565b6000856001600160a01b0316876001600160a01b031614156129705750600019612998565b506001600160a01b038086166000908152600e60209081526040808320938a16835292905220545b6000806000806129a8858961357d565b909450925060008460038111156129bb57fe5b146129d9576129cc6009604b612f57565b96505050505050506111cb565b6001600160a01b038a166000908152600d60205260409020546129fc908961357d565b90945091506000846003811115612a0f57fe5b14612a20576129cc6009604c612f57565b6001600160a01b0389166000908152600d6020526040902054612a43908961366e565b90945090506000846003811115612a5657fe5b14612a67576129cc6009604d612f57565b6001600160a01b03808b166000908152600d6020526040808220859055918b168152208190556000198514612abf576001600160a01b03808b166000908152600e60209081526040808320938f168352929052208390555b886001600160a01b03168a6001600160a01b0316600080516020615cd08339815191528a6040518082815260200191505060405180910390a35060009a9950505050505050505050565b816001600160a01b0316836001600160a01b031614158015612b3457506000816001600160601b0316115b15612c9f576001600160a01b03831615612bec576001600160a01b03831660009081526013602052604081205463ffffffff169081612b74576000612bb3565b6001600160a01b0385166000908152601260209081526040808320600019860163ffffffff168452909152902054600160201b90046001600160601b03165b90506000612bda8285604051806060016040528060288152602001615d2160289139613edd565b9050612be886848484613f87565b5050505b6001600160a01b03821615612c9f576001600160a01b03821660009081526013602052604081205463ffffffff169081612c27576000612c66565b6001600160a01b0384166000908152601260209081526040808320600019860163ffffffff168452909152902054600160201b90046001600160601b03165b90506000612c8d8285604051806060016040528060278152602001615ca960279139614146565b9050612c9b85848484613f87565b5050505b505050565b6001546000908190600160a01b900460ff16612cf4576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000612d0b6119af565b90508015612d3557612d29816010811115612d2257fe5b6035612f57565b60009250925050612d46565b612d40338686613a81565b92509250505b6001805460ff60a01b1916600160a01b17905590939092509050565b600080600080612d7286866135a0565b90925090506000826003811115612d8557fe5b14612d965750915060009050612da8565b6000612da1826141a7565b9350935050505b9250929050565b601054604080516370a0823160e01b815230600482015290516000926001600160a01b03169182916370a0823191602480820192602092909190829003018186803b158015612dfd57600080fd5b505afa158015612e11573d6000803e3d6000fd5b505050506040513d6020811015612e2757600080fd5b505191505090565b600154600090600160a01b900460ff16612e7d576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b191690556000612e946119af565b90508015612eb2576112b2816010811115612eab57fe5b604e612f57565b612ebb836141b6565b509150506001805460ff60a01b1916600160a01b179055919050565b6001600160a01b0380831660008181526011602081815260408084208054600d845282862054949093528787166001600160a01b03198416811790915590519190951694919391928592917f3134e8a2e6d97e929a7e54011ea5485d7d196dd5f0ba4d4ef95803e8e3fc257f9190a4612f51828483612b09565b50505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0836010811115612f8657fe5b836051811115612f9257fe5b604080519283526020830191909152600082820152519081900360600190a182601081111561177d57fe5b6000806000612fca6110ae565b9050336001600160a01b03821614612ff157612fe860016031612f57565b92505050610e5d565b612ff9613366565b6008541461300d57612fe8600a6033612f57565b83613016612daf565b101561302857612fe8600e6032612f57565b600b5484111561303e57612fe860026034612f57565b600b5484810392508211156130845760405162461bcd60e51b8152600401808060200182810382526024815260200180615e006024913960400191505060405180910390fd5b600b829055613093818561429e565b604080516001600160a01b03831681526020810186905280820184905290517f3bad0c59cf2f06e7314077049f48a93578cd16f5ef92329f1dab1420a99c177e9181900360600190a16000949350505050565b600080600460019054906101000a90046001600160a01b03169050826001600160a01b0316634e1647fb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561313a57600080fd5b505afa15801561314e573d6000803e3d6000fd5b505050506040513d602081101561316457600080fd5b50516131b7576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b600480546001600160a01b038086166101008102610100600160a81b031990931692909217909255604080519284168352602083019190915280517ff9b6a28700579d5c8fab50f0ac2dcaa52109b85c369c4f511fcc873330ab6cbb9281900390910190a1600061177d565b6001546000908190600160a01b900460ff16613273576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b19169055600061328a6119af565b905080156132a8576127878160108111156132a157fe5b6027612f57565b61279e3360008661438f565b6001600160a01b0381166000908152600f60205260408120805482918291829182916132ea5760008095509550505050506119aa565b6132fa8160000154600954614876565b9094509250600084600381111561330d57fe5b146133225783600095509550505050506119aa565b6133308382600101546148b5565b9094509150600084600381111561334357fe5b146133585783600095509550505050506119aa565b506000945092505050915091565b4390565b600080613375613366565b60085414613389576125c6600a6041612f57565b600560009054906101000a90046001600160a01b03169050826001600160a01b0316632191f92a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156133da57600080fd5b505afa1580156133ee573d6000803e3d6000fd5b505050506040513d602081101561340457600080fd5b5051613457576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b600580546001600160a01b0319166001600160a01b03858116918217909255604080519284168352602083019190915280517fedffc32e068c7c95dfd4bdfd5c4d939a084d6b11c4199eac8436ed234d72f9269281900390910190a1600061177d565b6000806000600160149054906101000a900460ff1661350d576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006135246119af565b905080156135515761354281601081111561353b57fe5b601e612f57565b60008093509350935050613563565b61355b33866148e0565b935093509350505b6001805460ff60a01b1916600160a01b1790559193909250565b600080838311613594575060009050818303612da8565b50600390506000612da8565b60006135aa6159ed565b6000806135bb866000015186614876565b909250905060008260038111156135ce57fe5b146135ed57506040805160208101909152600081529092509050612da8565b60408051602081019091529081526000969095509350505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa084601081111561363757fe5b84605181111561364357fe5b604080519283526020830191909152818101859052519081900360600190a18360108111156111cb57fe5b60008083830184811061368657600092509050612da8565b600260009250925050612da8565b6000806000806136a487876135a0565b909250905060008260038111156136b757fe5b146136c857509150600090506136e1565b6136da6136d4826141a7565b8661366e565b9350935050505b935093915050565b6000806136f886868686614cc8565b905080613731576001600160a01b0380851660009081526011602052604080822054888416835291205461373192918216911685612b09565b95945050505050565b4690565b600154600090600160a01b900460ff1661378c576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006137a36119af565b905080156137c1576112b28160108111156137ba57fe5b6008612f57565b6112c33384614eae565b6001546000908190600160a01b900460ff1661381b576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006138326119af565b90508015613849576127878160108111156132a157fe5b61279e3385600061438f565b600061385f6110ae565b6001600160a01b0316336001600160a01b0316146138835761166760016042612f57565b610e468261336a565b6001546000908190600160a01b900460ff166138dc576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001805460ff60a01b1916905560006138f36119af565b9050801561391d5761391181601081111561390a57fe5b600f612f57565b600092509250506139b4565b836001600160a01b031663a6afed956040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561395857600080fd5b505af115801561396c573d6000803e3d6000fd5b505050506040513d602081101561398257600080fd5b5051905080156139a25761391181601081111561399b57fe5b6010612f57565b6139ae3387878761514c565b92509250505b6001805460ff60a01b1916600160a01b1790559094909350915050565b60006139db6110ae565b6001600160a01b0316336001600160a01b0316146139ff5761166760016047612f57565b613a07613366565b60085414613a1b57611667600a6048612f57565b670de0b6b3a7640000821115613a375761166760026049612f57565b6007805490839055604080518281526020810185905281517faaa68312e2ea9d50e16af5068410ab56e1a1fd06037b1a35664812c30f821460929181900390910190a1600061177d565b6004805460408051631200453160e11b815230938101939093526001600160a01b03868116602485015285811660448501526064840185905290516000938493849361010090910416916324008a629160848082019260209290919082900301818787803b158015613af257600080fd5b505af1158015613b06573d6000803e3d6000fd5b505050506040513d6020811015613b1c57600080fd5b505190508015613b3f57613b336003603883613608565b600092509250506136e1565b613b47613366565b60085414613b5b57613b33600a6039612f57565b613b63615a00565b6001600160a01b0386166000908152600f60205260409020600101546060820152613b8d866132b4565b6080830181905260208301826003811115613ba457fe5b6003811115613baf57fe5b9052506000905081602001516003811115613bc657fe5b14613bef57613be26009603783602001516003811115611c8957fe5b60009350935050506136e1565b600a5481608001511115613c0657600a5460808201525b8060800151851115613c215760808101516040820152613c29565b604081018590525b613c37878260400151615650565b60e082018190526080820151613c4c9161357d565b60a0830181905260208301826003811115613c6357fe5b6003811115613c6e57fe5b9052506000905081602001516003811115613c8557fe5b14613cc15760405162461bcd60e51b815260040180806020018281038252603a815260200180615c6f603a913960400191505060405180910390fd5b613cd1600a548260e0015161357d565b60c0830181905260208301826003811115613ce857fe5b6003811115613cf357fe5b9052506000905081602001516003811115613d0a57fe5b14613d465760405162461bcd60e51b8152600401808060200182810382526031815260200180615cf06031913960400191505060405180910390fd5b60a080820180516001600160a01b03808a166000818152600f602090815260409182902094855560095460019095019490945560c0870151600a81905560e088015195518251948f16855294840192909252828101949094526060820192909252608081019190915290517f1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1929181900390910190a160e00151600097909650945050505050565b600080600080613dfe878761366e565b90925090506000826003811115613e1157fe5b14613e2257509150600090506136e1565b6136da818661357d565b6000613e366159ed565b600080613e4b86670de0b6b3a7640000614876565b90925090506000826003811115613e5e57fe5b14613e7d57506040805160208101909152600081529092509050612da8565b600080613e8a83886148b5565b90925090506000826003811115613e9d57fe5b14613ec05781604051806020016040528060008152509550955050505050612da8565b604080516020810190915290815260009890975095505050505050565b6000836001600160601b0316836001600160601b031611158290613f7f5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613f44578181015183820152602001613f2c565b50505050905090810190601f168015613f715780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000613fab43604051806060016040528060348152602001615b086034913961589a565b905060008463ffffffff16118015613ff457506001600160a01b038516600090815260126020908152604080832063ffffffff6000198901811685529252909120548282169116145b15614053576001600160a01b0385166000908152601260209081526040808320600019880163ffffffff168452909152902080546fffffffffffffffffffffffff000000001916600160201b6001600160601b038516021790556140f2565b60408051808201825263ffffffff80841682526001600160601b0380861660208085019182526001600160a01b038b166000818152601283528781208c871682528352878120965187549451909516600160201b026fffffffffffffffffffffffff000000001995871663ffffffff19958616179590951694909417909555938252601390935292909220805460018801909316929091169190911790555b604080516001600160601b0380861682528416602082015281516001600160a01b038816927fdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a724928290030190a25050505050565b6000838301826001600160601b03808716908316101561109c5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315613f44578181015183820152602001613f2c565b51670de0b6b3a7640000900490565b6000806000806141c4613366565b600854146141e3576141d8600a604f612f57565b935091506119aa9050565b6141ed3386615650565b905080600b54019150600b5482101561424d576040805162461bcd60e51b815260206004820181905260248201527f61646420726573657276657320756e6578706563746564206f766572666c6f77604482015290519081900360640190fd5b600b829055604080513381526020810183905280820184905290517fa91e67c5ea634cd43a12c5a482724b03de01e85ca68702a53d0c2f45cb7c1dc59181900360600190a160009350915050915091565b6010546040805163a9059cbb60e01b81526001600160a01b0385811660048301526024820185905291519190921691829163a9059cbb9160448082019260009290919082900301818387803b1580156142f657600080fd5b505af115801561430a573d6000803e3d6000fd5b5050505060003d60008114614326576020811461433057600080fd5b600019915061433c565b60206000803e60005191505b5080612f51576040805162461bcd60e51b815260206004820152601960248201527f544f4b454e5f5452414e534645525f4f55545f4641494c454400000000000000604482015290519081900360640190fd5b60008083158061439d575082155b6143d85760405162461bcd60e51b8152600401808060200182810382526034815260200180615dcc6034913960400191505060405180910390fd5b6143e0615a46565b6143e86127be565b60408301819052602083018260038111156143ff57fe5b600381111561440a57fe5b905250600090508160200151600381111561442157fe5b1461443d57613b336009602b83602001516003811115611c8957fe5b84156144be5760608101859052604080516020810182529082015181526144649086612d62565b608083018190526020830182600381111561447b57fe5b600381111561448657fe5b905250600090508160200151600381111561449d57fe5b146144b957613b336009602983602001516003811115611c8957fe5b614537565b6144da84604051806020016040528084604001518152506158f7565b60608301819052602083018260038111156144f157fe5b60038111156144fc57fe5b905250600090508160200151600381111561451357fe5b1461452f57613b336009602a83602001516003811115611c8957fe5b608081018490525b6000600460019054906101000a90046001600160a01b03166001600160a01b031663eabe7d91308985606001516040518463ffffffff1660e01b815260040180846001600160a01b03168152602001836001600160a01b031681526020018281526020019350505050602060405180830381600087803b1580156145ba57600080fd5b505af11580156145ce573d6000803e3d6000fd5b505050506040513d60208110156145e457600080fd5b5051905080156145fb57613be26003602883613608565b614603613366565b6008541461461757613be2600a602c612f57565b614627600c54836060015161357d565b60a084018190526020840182600381111561463e57fe5b600381111561464957fe5b905250600090508260200151600381111561466057fe5b1461467c57613be26009602e84602001516003811115611c8957fe5b6001600160a01b0387166000908152600d602052604090205460608301516146a4919061357d565b60c08401819052602084018260038111156146bb57fe5b60038111156146c657fe5b90525060009050826020015160038111156146dd57fe5b146146f957613be26009602d84602001516003811115611c8957fe5b8160800151614706612daf565b101561471857613be2600e602f612f57565b61472687836080015161429e565b60a0820151600c5560c08201516001600160a01b0388166000818152600d6020908152604091829020939093556060850151815190815290513093600080516020615cd0833981519152928290030190a37fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929878360800151846060015160405180846001600160a01b03168152602001838152602001828152602001935050505060405180910390a16004805460808401516060850151604080516351dff98960e01b815230958101959095526001600160a01b038c81166024870152604486019390935260648501919091525161010090920416916351dff98991608480830192600092919082900301818387803b15801561484257600080fd5b505af1158015614856573d6000803e3d6000fd5b5060009250614863915050565b8260600151935093505050935093915050565b6000808361488957506000905080612da8565b8383028385828161489657fe5b04146148aa57600260009250925050612da8565b600092509050612da8565b600080826148c95750600190506000612da8565b60008385816148d457fe5b04915091509250929050565b6004805460408051634ef4c3e160e01b815230938101939093526001600160a01b0385811660248501526044840185905290516000938493849384936101009092041691634ef4c3e191606480830192602092919082900301818787803b15801561494a57600080fd5b505af115801561495e573d6000803e3d6000fd5b505050506040513d602081101561497457600080fd5b50519050801561499a5761498b6003601f83613608565b60008093509350935050614cc1565b6149a2613366565b600854146149b65761498b600a6022612f57565b6149be615a46565b6149c66127be565b60408301819052602083018260038111156149dd57fe5b60038111156149e857fe5b90525060009050816020015160038111156149ff57fe5b14614a2b57614a1b6009602183602001516003811115611c8957fe5b6000809450945094505050614cc1565b614a358787615650565b60c0820181905260408051602081018252908301518152614a5691906158f7565b6060830181905260208301826003811115614a6d57fe5b6003811115614a7857fe5b9052506000905081602001516003811115614a8f57fe5b14614ae1576040805162461bcd60e51b815260206004820181905260248201527f4d494e545f45584348414e47455f43414c43554c4154494f4e5f4641494c4544604482015290519081900360640190fd5b614af1600c54826060015161366e565b6080830181905260208301826003811115614b0857fe5b6003811115614b1357fe5b9052506000905081602001516003811115614b2a57fe5b14614b665760405162461bcd60e51b8152600401808060200182810382526028815260200180615da46028913960400191505060405180910390fd5b6001600160a01b0387166000908152600d60205260409020546060820151614b8e919061366e565b60a0830181905260208301826003811115614ba557fe5b6003811115614bb057fe5b9052506000905081602001516003811115614bc757fe5b14614c035760405162461bcd60e51b815260040180806020018281038252602b815260200180615bb4602b913960400191505060405180910390fd5b6080810151600c5560a08101516001600160a01b0388166000818152600d60209081526040918290209390935560c084015160608086015183519485529484019190915282820193909352517f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f929181900390910190a1606081015160408051918252516001600160a01b038916913091600080516020615cd08339815191529181900360200190a360008160c00151826060015194509450945050505b9250925092565b600480546040805163d02f735160e01b815230938101939093526001600160a01b03878116602485015286811660448501528581166064850152608484018590529051600093849361010090049092169163d02f73519160a480830192602092919082900301818787803b158015614d3f57600080fd5b505af1158015614d53573d6000803e3d6000fd5b505050506040513d6020811015614d6957600080fd5b505190508015614d805761291d6003601b83613608565b846001600160a01b0316846001600160a01b03161415614da65761291d6006601c612f57565b6001600160a01b0384166000908152600d602052604081205481908190614dcd908761357d565b90935091506000836003811115614de057fe5b14614e0357614df86009601a856003811115611c8957fe5b9450505050506111cb565b6001600160a01b0388166000908152600d6020526040902054614e26908761366e565b90935090506000836003811115614e3957fe5b14614e5157614df860096019856003811115611c8957fe5b6001600160a01b038088166000818152600d60209081526040808320879055938c168083529184902085905583518a815293519193600080516020615cd0833981519152929081900390910190a360009998505050505050505050565b600480546040805163368f515360e21b815230938101939093526001600160a01b038581166024850152604484018590529051600093849361010090049092169163da3d454c91606480830192602092919082900301818787803b158015614f1557600080fd5b505af1158015614f29573d6000803e3d6000fd5b505050506040513d6020811015614f3f57600080fd5b505190508015614f5e57614f566003600e83613608565b915050610e46565b614f66613366565b60085414614f7957614f56600a80612f57565b82614f82612daf565b1015614f9457614f56600e6009612f57565b614f9c615a84565b614fa5856132b4565b6020830181905282826003811115614fb957fe5b6003811115614fc457fe5b9052506000905081516003811115614fd857fe5b14614ffd57614ff46009600783600001516003811115611c8957fe5b92505050610e46565b61500b81602001518561366e565b604083018190528282600381111561501f57fe5b600381111561502a57fe5b905250600090508151600381111561503e57fe5b1461505a57614ff46009600c83600001516003811115611c8957fe5b615066600a548561366e565b606083018190528282600381111561507a57fe5b600381111561508557fe5b905250600090508151600381111561509957fe5b146150b557614ff46009600b83600001516003811115611c8957fe5b6150bf858561429e565b604080820180516001600160a01b0388166000818152600f602090815290859020928355600954600190930192909255606080860151600a81905593518551928352928201899052818501929092529081019190915290517f13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab809181900360800190a1600095945050505050565b6004805460408051632fe3f38f60e11b815230938101939093526001600160a01b03848116602485015287811660448501528681166064850152608484018690529051600093849384936101009091041691635fc7e71e9160a48082019260209290919082900301818787803b1580156151c557600080fd5b505af11580156151d9573d6000803e3d6000fd5b505050506040513d60208110156151ef57600080fd5b505190508015615212576152066003601283613608565b60009250925050615647565b61521a613366565b6008541461522e57615206600a6016612f57565b615236613366565b846001600160a01b0316636c540baf6040518163ffffffff1660e01b815260040160206040518083038186803b15801561526f57600080fd5b505afa158015615283573d6000803e3d6000fd5b505050506040513d602081101561529957600080fd5b5051146152ac57615206600a6011612f57565b866001600160a01b0316866001600160a01b031614156152d25761520660066017612f57565b846152e35761520660076015612f57565b6000198514156152f95761520660076014612f57565b600080615307898989613a81565b909250905081156153365761532882601081111561532157fe5b6018612f57565b600094509450505050615647565b600480546040805163c488847b60e01b815230938101939093526001600160a01b038981166024850152604484018590528151600094859461010090049092169263c488847b9260648082019391829003018186803b15801561539857600080fd5b505afa1580156153ac573d6000803e3d6000fd5b505050506040513d60408110156153c257600080fd5b5080516020909101519092509050811561540d5760405162461bcd60e51b8152600401808060200182810382526032815260200180615c166032913960400191505060405180910390fd5b80886001600160a01b03166370a082318c6040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561545b57600080fd5b505afa15801561546f573d6000803e3d6000fd5b505050506040513d602081101561548557600080fd5b505110156154da576040805162461bcd60e51b815260206004820152601860248201527f4c49515549444154455f5345495a455f544f4f5f4d5543480000000000000000604482015290519081900360640190fd5b60006001600160a01b038916301415615500576154f9308d8d856136e9565b9050615597565b886001600160a01b031663b2a02ff18d8d856040518463ffffffff1660e01b815260040180846001600160a01b03168152602001836001600160a01b031681526020018281526020019350505050602060405180830381600087803b15801561556857600080fd5b505af115801561557c573d6000803e3d6000fd5b505050506040513d602081101561559257600080fd5b505190505b80156155e1576040805162461bcd60e51b81526020600482015260146024820152731d1bdad95b881cd95a5e9d5c994819985a5b195960621b604482015290519081900360640190fd5b604080516001600160a01b03808f168252808e1660208301528183018790528b1660608201526080810184905290517f298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb529181900360a00190a16000975092955050505050505b94509492505050565b601054604080516370a0823160e01b815230600482015290516000926001600160a01b031691839183916370a08231916024808301926020929190829003018186803b15801561569f57600080fd5b505afa1580156156b3573d6000803e3d6000fd5b505050506040513d60208110156156c957600080fd5b5051604080516323b872dd60e01b81526001600160a01b038881166004830152306024830152604482018890529151929350908416916323b872dd9160648082019260009290919082900301818387803b15801561572657600080fd5b505af115801561573a573d6000803e3d6000fd5b5050505060003d60008114615756576020811461576057600080fd5b600019915061576c565b60206000803e60005191505b50806157bf576040805162461bcd60e51b815260206004820152601860248201527f544f4b454e5f5452414e534645525f494e5f4641494c45440000000000000000604482015290519081900360640190fd5b601054604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561580a57600080fd5b505afa15801561581e573d6000803e3d6000fd5b505050506040513d602081101561583457600080fd5b505190508281101561588d576040805162461bcd60e51b815260206004820152601a60248201527f544f4b454e5f5452414e534645525f494e5f4f564552464c4f57000000000000604482015290519081900360640190fd5b9190910395945050505050565b600081600160201b84106158ef5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315613f44578181015183820152602001613f2c565b509192915050565b600080600080612d728686600061590c6159ed565b600080615921670de0b6b3a764000087614876565b9092509050600082600381111561593457fe5b1461595357506040805160208101909152600081529092509050612da8565b612da1818660000151613e2c565b828054600181600116156101000203166002900490600052602060002090601f01602090048101928261599757600085556159dd565b82601f106159b057805160ff19168380011785556159dd565b828001600101855582156159dd579182015b828111156159dd5782518255916020019190600101906159c2565b506159e9929150615aad565b5090565b6040518060200160405280600081525090565b6040805161010081019091528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805160e0810190915280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b604080516080810190915280600081526020016000815260200160008152602001600081525090565b5b808211156159e95760008155600101615aae56fe505069653a3a64656c656761746542795369673a20696e76616c6964206e6f6e63656d61726b6574206d6179206f6e6c7920626520696e697469616c697a6564206f6e6365505069653a3a5f7772697465436865636b706f696e743a20626c6f636b206e756d62657220657863656564732033322062697473696e697469616c2065786368616e67652072617465206d7573742062652067726561746572207468616e207a65726f2e505069653a3a64656c656761746542795369673a207369676e6174757265206578706972656473657474696e6720696e7465726573742072617465206d6f64656c206661696c65644d494e545f4e45575f4143434f554e545f42414c414e43455f43414c43554c4154494f4e5f4641494c4544626f72726f7742616c616e636553746f7265643a20626f72726f7742616c616e636553746f726564496e7465726e616c206661696c65644c49515549444154455f434f4e54524f4c4c45525f43414c43554c4154455f414d4f554e545f5345495a455f4641494c4544505069653a3a6765745072696f72566f7465733a206e6f74207965742064657465726d696e656452455041595f424f52524f575f4e45575f4143434f554e545f424f52524f575f42414c414e43455f43414c43554c4154494f4e5f4641494c4544505069653a3a5f6d6f7665566f7465733a20766f746520616d6f756e74206f766572666c6f7773ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef52455041595f424f52524f575f4e45575f544f54414c5f42414c414e43455f43414c43554c4154494f4e5f4641494c4544505069653a3a5f6d6f7665566f7465733a20766f746520616d6f756e7420756e646572666c6f7773505069653a3a64656c656761746542795369673a20696e76616c6964207369676e617475726565786368616e67655261746553746f7265643a2065786368616e67655261746553746f726564496e7465726e616c206661696c65644d494e545f4e45575f544f54414c5f535550504c595f43414c43554c4154494f4e5f4641494c45446f6e65206f662072656465656d546f6b656e73496e206f722072656465656d416d6f756e74496e206d757374206265207a65726f72656475636520726573657276657320756e657870656374656420756e646572666c6f77a264697066735822122020f3a885f3c5cf9d8fbae18c3a1bdc5360e118c179c4b8969ee2d17dab45fd5a64736f6c63430007060033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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