Contract 0x04ebbe38c13eb510b12429188fe1f7991e08573c

Contract Overview

Balance:
0 BNB
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x80602cbf71e8f06d59dd1cf9f9518d8eed08bbe8febd72d73cce7ad46815a7a50x6080604071051042021-03-15 9:26:41188 days 17 hrs ago0x815e1cf12985574d067000e469e96cc30072cfbf IN  Contract Creation0 BNB0.03664039
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x040059700b4114bb1b4f3523e41e9a60f6fdfbf49477fb2cdd36ed8dd8b24d7e117507892021-08-24 6:32:5226 days 20 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xc41417c31aa0c052d4988df776f54bcf41e5dcea847a5684ee96178b4634a76f114099722021-08-12 8:23:3338 days 18 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xb6282c04bd203fa7b2283c5fb9d1c2cd3f01c6184c7edbd25a52393fc88a8e5d114099302021-08-12 8:21:2738 days 18 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x6aadac467076396d08ac1e9e70bbeed5e68002f44ceed69d3f53217d277bc19f114098052021-08-12 8:15:1238 days 18 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x3ee21b6ac68c372d41575a9354089051b48f47410e3dddc2a7b4726437faedd3114095562021-08-12 8:02:4538 days 18 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x96adec44a6d9902f65b1b77cf5f3a7bc6ccadc6dd994497db27371ba1a4accde114092842021-08-12 7:49:0938 days 19 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x3d7201b7ced054e13074f917419bd9eed93bd5045de9161b85a35ac1406e6094114027092021-08-12 2:20:2439 days 40 mins ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xe21ddfda527580fa23ab05b5dd59429e1222f4fbe7b88b0e84cd5879d486a36098051902021-06-17 6:55:1094 days 20 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x46c0b611f394a1450e33174f06e27b14522a57139249ab24548838bda9a5ebbc98051312021-06-17 6:52:1394 days 20 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xd5a55f503d79afdf1959b68e26118b023d8e2dfcee1554b7291df9ad60c8f96798051212021-06-17 6:51:4394 days 20 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xc8ddaf0324b1e3703511d95072b2d03e973511ad622e264f20ad40e83cfc9a0398051052021-06-17 6:50:5594 days 20 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x0d9327e77e8879c556866b6776a924b9cfcc9b0f74de27fdd4fa7f91d9faf62298048752021-06-17 6:39:2594 days 20 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x76ff4f15d4b4935297da47f949da6c3de747fdbdaa9a6794d2cc81a6c7b7eded89681152021-05-19 4:00:13123 days 23 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xc737362131fc317328aa2f3e82df94343e270e723a791c4dc55dffa371e4f06a89623922021-05-18 23:11:29124 days 3 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x46afc47969af42c4b76d3d027673a0dd0243b5967a069bfa563d71afcd1ceab589509882021-05-18 13:41:17124 days 13 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x93a0325b388208ec58bbc4be8d2fd258d1e8d86a12a437809b7424faec9f450089451992021-05-18 8:51:50124 days 18 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x1bb2fe67502ef86bd4fd11dd832a50c0fbf2e4c8be58f73f6f58c4e4854a14d989384782021-05-18 3:15:47124 days 23 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x84a74c761132325b7671daa8edb4c945af3820148592b4964e5870f401df08c289382082021-05-18 3:02:17124 days 23 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x6c470c307ae98b8ee2870a78b495420307ae7b260d80c1f9b50f1be321fbc47a89186902021-05-17 10:46:17125 days 16 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xaf57b50a61077c75ec43c88c8e8c9b309ca799fcd73804e7c193bbd81c91383c89185772021-05-17 10:40:38125 days 16 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xbb5c01cedf09cabf3daa02a02dc9f00829011975931b1f01ea61b387ec96a93189181592021-05-17 10:19:44125 days 16 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x72a4521c2714d591c1194d37bbaa8bc06a8845e5df535991d096f66529f464ab89110452021-05-17 4:24:02125 days 22 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x0be76509ae8b1467254b46f0e82946fec12fa60c04e173233c2f264a5ae2c1b589108092021-05-17 4:12:14125 days 22 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0x645ec5c8772033ad99dc2eb49a4f06d105dd0c44c9189f7b0d9006cb19797f6f89107582021-05-17 4:09:41125 days 22 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
0xb0d14121eb1a378f092d94b16f05506f8e5ab33e9345b81d30cdff66de88f1e789107222021-05-17 4:07:53125 days 22 hrs ago 0x8d1cd10a491e24659993b56f4fb6a43987233e12 0x04ebbe38c13eb510b12429188fe1f7991e08573c0 BNB
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
PiggyDistribution

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity)

/**
 *Submitted for verification at BscScan.com on 2021-04-01
*/

pragma solidity 0.6.12;


// COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/CarefulMath.sol
//Copyright 2020 Compound Labs, Inc.
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
//3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// SPDX-License-Identifier: MIT
/**
  * @title Careful Math
  * @author Compound
  * @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);
    }
}

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

/**
 * @title Exponential module for storing fixed-precision decimals
 * @author Compound
 * @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)});
    }
}

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

interface IComptroller {

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

    /**
     * PIGGY-MODIFY:
     * @notice Add assets to be included in account liquidity calculation
     * @param pTokens The list of addresses of the cToken markets to be enabled
     * @return Success indicator for whether each corresponding market was entered
     */
    function enterMarkets(address[] calldata pTokens) external returns (uint[] memory);

    /**
     * PIGGY-MODIFY:
     * @notice Removes asset from sender's account liquidity calculation
     * @dev Sender must not have an outstanding borrow balance in the asset,
     *  or be providing necessary collateral for an outstanding borrow.
     * @param pTokenAddress The address of the asset to be removed
     * @return Whether or not the account successfully exited the market
     */
    function exitMarket(address pTokenAddress) external returns (uint);

    /*** Policy Hooks ***/

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the account should be allowed to mint tokens in the given market
     * @param pToken The market to verify the mint against
     * @param minter The account which would get the minted tokens
     * @param mintAmount The amount of underlying being supplied to the market in exchange for tokens
     * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)
     */
    function mintAllowed(
        address pToken,
        address minter,
        uint mintAmount
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates mint and reverts on rejection. May emit logs.
     * @param pToken Asset being minted
     * @param minter The address minting the tokens
     * @param mintAmount The amount of the underlying asset being minted
     * @param mintTokens The number of tokens being minted
     */
    function mintVerify(
        address pToken,
        address minter,
        uint mintAmount,
        uint mintTokens
    ) external;

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the account should be allowed to redeem tokens in the given market
     * @param pToken The market to verify the redeem against
     * @param redeemer The account which would redeem the tokens
     * @param redeemTokens The number of cTokens to exchange for the underlying asset in the market
     * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)
     */
    function redeemAllowed(
        address pToken,
        address redeemer,
        uint redeemTokens
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates redeem and reverts on rejection. May emit logs.
     * @param pToken Asset being redeemed
     * @param redeemer The address redeeming the tokens
     * @param redeemAmount The amount of the underlying asset being redeemed
     * @param redeemTokens The number of tokens being redeemed
     */
    function redeemVerify(
        address pToken,
        address redeemer,
        uint redeemAmount,
        uint redeemTokens
    ) external;

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the account should be allowed to borrow the underlying asset of the given market
     * @param pToken The market to verify the borrow against
     * @param borrower The account which would borrow the asset
     * @param borrowAmount The amount of underlying the account would borrow
     * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)
     */
    function borrowAllowed(
        address pToken,
        address borrower,
        uint borrowAmount
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates borrow and reverts on rejection. May emit logs.
     * @param pToken Asset whose underlying is being borrowed
     * @param borrower The address borrowing the underlying
     * @param borrowAmount The amount of the underlying asset requested to borrow
     */
    function borrowVerify(
        address pToken,
        address borrower,
        uint borrowAmount
    ) external;

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the account should be allowed to repay a borrow in the given market
     * @param pToken The market to verify the repay against
     * @param payer The account which would repay the asset
     * @param borrower The account which would borrowed the asset
     * @param repayAmount The amount of the underlying asset the account would repay
     * @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)
     */
    function repayBorrowAllowed(
        address pToken,
        address payer,
        address borrower,
        uint repayAmount
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates repayBorrow and reverts on rejection. May emit logs.
     * @param pToken Asset being repaid
     * @param payer The address repaying the borrow
     * @param borrower The address of the borrower
     * @param repayAmount The amount of underlying being repaid
     */
    function repayBorrowVerify(
        address pToken,
        address payer,
        address borrower,
        uint repayAmount,
        uint borrowerIndex
    ) external;

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the liquidation should be allowed to occur
     * @param pTokenBorrowed Asset which was borrowed by the borrower
     * @param pTokenCollateral Asset which was used as collateral and will be seized
     * @param liquidator The address repaying the borrow and seizing the collateral
     * @param borrower The address of the borrower
     * @param repayAmount The amount of underlying being repaid
     */
    function liquidateBorrowAllowed(
        address pTokenBorrowed,
        address pTokenCollateral,
        address liquidator,
        address borrower,
        uint repayAmount
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates liquidateBorrow and reverts on rejection. May emit logs.
     * @param pTokenBorrowed Asset which was borrowed by the borrower
     * @param pTokenCollateral Asset which was used as collateral and will be seized
     * @param liquidator The address repaying the borrow and seizing the collateral
     * @param borrower The address of the borrower
     * @param repayAmount The amount of underlying being repaid
     */
    function liquidateBorrowVerify(
        address pTokenBorrowed,
        address pTokenCollateral,
        address liquidator,
        address borrower,
        uint repayAmount,
        uint seizeTokens
    ) external;

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the seizing of assets should be allowed to occur
     * @param pTokenCollateral Asset which was used as collateral and will be seized
     * @param pTokenBorrowed Asset which was borrowed by the borrower
     * @param liquidator The address repaying the borrow and seizing the collateral
     * @param borrower The address of the borrower
     * @param seizeTokens The number of collateral tokens to seize
     */
    function seizeAllowed(
        address pTokenCollateral,
        address pTokenBorrowed,
        address liquidator,
        address borrower,
        uint seizeTokens
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates seize and reverts on rejection. May emit logs.
     * @param pTokenCollateral Asset which was used as collateral and will be seized
     * @param pTokenBorrowed Asset which was borrowed by the borrower
     * @param liquidator The address repaying the borrow and seizing the collateral
     * @param borrower The address of the borrower
     * @param seizeTokens The number of collateral tokens to seize
     */
    function seizeVerify(
        address pTokenCollateral,
        address pTokenBorrowed,
        address liquidator,
        address borrower,
        uint seizeTokens
    ) external;

    /**
     * PIGGY-MODIFY:
     * @notice Checks if the account should be allowed to transfer tokens in the given market
     * @param pToken The market to verify the transfer against
     * @param src The account which sources the tokens
     * @param dst The account which receives the tokens
     * @param transferTokens The number of pTokens to transfer
     * @return 0 if the transfer is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)
     */
    function transferAllowed(
        address pToken,
        address src,
        address dst,
        uint transferTokens
    ) external returns (uint);

    /**
     * PIGGY-MODIFY:
     * @notice Validates transfer and reverts on rejection. May emit logs.
     * @param pToken Asset being transferred
     * @param src The account which sources the tokens
     * @param dst The account which receives the tokens
     * @param transferTokens The number of pTokens to transfer
     */
    function transferVerify(
        address pToken,
        address src,
        address dst,
        uint transferTokens
    ) external;

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

    /**
     * PIGGY-MODIFY:
    * @notice Calculate number of tokens of collateral asset to seize given an underlying amount
    * @dev Used in liquidation (called in cToken.liquidateBorrowFresh)
    * @param pTokenBorrowed The address of the borrowed cToken
    * @param pTokenCollateral The address of the collateral cToken
    * @param repayAmount The amount of cTokenBorrowed underlying to convert into cTokenCollateral tokens
    * @return (errorCode, number of cTokenCollateral tokens to be seized in a liquidation)
    */
    function liquidateCalculateSeizeTokens(
        address pTokenBorrowed,
        address pTokenCollateral,
        uint repayAmount
    ) external view returns (uint, uint);
}

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

/**
  * @title wepiggy's IInterestRateModel Interface
  * @author wepiggy
  */
interface IInterestRateModel {
    /**
      * @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 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 returns (uint);

}

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

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

    /**
     * @dev Guard variable for re-entrancy checks
     */
    bool internal _notEntered;

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

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

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

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

    uint256 internal constant borrowRateMaxMantissa = 0.0005e16;

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

    /**
     * @dev
     * @notice Contract which oversees inter-pToken operations
     */
    IComptroller public comptroller;

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

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

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

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

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

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

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

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

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

    /**
     * @dev
     * @notice Approved token transfer amounts on behalf of others
     */
    mapping(address => mapping(address => uint256)) 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 {
        uint256 principal;
        uint256 interestIndex;
    }

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

    address public migrator;

    uint256 public minInterestAccumulated;

}

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

abstract contract IPToken is PTokenStorage {
    /*** Market Events ***/

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

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

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

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

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

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

    /*** Admin Events ***/

    /**
     * @notice Event emitted when comptroller is changed
     */
    event NewComptroller(IComptroller oldComptroller, IComptroller newComptroller);

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

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

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

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

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

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

    /**
     * @notice Failure event
     */
    event Failure(uint256 error, uint256 info, uint256 detail);

    event NewMigrator(address oldMigrator, address newMigrator);

    event NewMinInterestAccumulated(uint256 oldMinInterestAccumulated, uint256 newMinInterestAccumulated);

    /*** User Interface ***/

    function transfer(address dst, uint256 amount) external virtual returns (bool);

    function transferFrom(address src, address dst, uint256 amount) external virtual returns (bool);

    function approve(address spender, uint256 amount) external virtual returns (bool);

    function allowance(address owner, address spender) external virtual view returns (uint256);

    function balanceOf(address owner) external virtual view returns (uint256);

    function balanceOfUnderlying(address owner) external virtual returns (uint256);

    function getAccountSnapshot(address account) external virtual view returns (uint256, uint256, uint256, uint256);

    function borrowRatePerBlock() external virtual view returns (uint256);

    function supplyRatePerBlock() external virtual view returns (uint256);

    function totalBorrowsCurrent() external virtual returns (uint256);

    function borrowBalanceCurrent(address account) external virtual returns (uint256);

    function borrowBalanceStored(address account) public virtual view returns (uint256);

    function exchangeRateCurrent() public virtual returns (uint256);

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

    function getCash() external virtual view returns (uint256);

    function accrueInterest() public virtual returns (uint256);

    function seize(address liquidator, address borrower, uint256 seizeTokens) external virtual returns (uint256);

    /*** Admin Functions ***/

    function _setComptroller(IComptroller newComptroller) public virtual returns (uint256);

    function _setReserveFactor(uint256 newReserveFactorMantissa) external virtual returns (uint256);

    function _reduceReserves(uint256 reduceAmount) external virtual returns (uint256);

    function _setInterestRateModel(IInterestRateModel newInterestRateModel) public virtual returns (uint256);

    function _setMigrator(address newMigrator) public virtual returns (uint256);

    function _setMinInterestAccumulated(uint _minInterestAccumulated) public virtual returns (uint256);
}

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

contract ComptrollerErrorReporter {
    enum Error {
        NO_ERROR,
        UNAUTHORIZED,
        COMPTROLLER_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,
        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_PENDING_ADMIN_OWNER_CHECK,
        SET_PENDING_IMPLEMENTATION_OWNER_CHECK,
        SET_PRICE_ORACLE_OWNER_CHECK,
        SUPPORT_MARKET_EXISTS,
        SUPPORT_MARKET_OWNER_CHECK,
        SET_PAUSE_GUARDIAN_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,
        COMPTROLLER_REJECTION,
        COMPTROLLER_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_INTEREST_BALANCE_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_COMPTROLLER_REJECTION,
        LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED,
        LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED,
        LIQUIDATE_COLLATERAL_FRESHNESS_CHECK,
        LIQUIDATE_COMPTROLLER_REJECTION,
        LIQUIDATE_COMPTROLLER_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_COMPTROLLER_REJECTION,
        LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER,
        LIQUIDATE_SEIZE_TOO_MUCH,
        MINT_ACCRUE_INTEREST_FAILED,
        MINT_COMPTROLLER_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_COMPTROLLER_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_INTEREST_BALANCE_CALCULATION_FAILED,
        REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
        REPAY_BORROW_COMPTROLLER_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_COMPTROLLER_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_COMPTROLLER_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
    }

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

/**
 * @title Initializable
 *
 * @dev Helper contract to support initializer functions. To use it, replace
 * the constructor with a function that has the `initializer` modifier.
 * WARNING: Unlike constructors, initializer functions must be manually
 * invoked. This applies both to deploying an Initializable contract, as well
 * as extending an Initializable contract via inheritance.
 * WARNING: When used with inheritance, manual care must be taken to not invoke
 * a parent initializer twice, or ensure that all initializers are idempotent,
 * because this is not dealt with automatically as with constructors.
 */
contract Initializable {

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

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

  /**
   * @dev Modifier to use in the initializer function of a contract.
   */
  modifier initializer() {
    require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");

    bool isTopLevelCall = !initializing;
    if (isTopLevelCall) {
      initializing = true;
      initialized = true;
    }

    _;

    if (isTopLevelCall) {
      initializing = false;
    }
  }

  /// @dev Returns true if and only if the function is running in the constructor
  function isConstructor() private view returns (bool) {
    // extcodesize checks the size of the code stored in an address, and
    // address returns the current address. Since the code is still not
    // deployed when running a constructor, any checks on its code size will
    // yield zero, making it an effective way to detect if a contract is
    // under construction or not.
    address self = address(this);
    uint256 cs;
    assembly { cs := extcodesize(self) }
    return cs == 0;
  }

  // Reserved storage space to allow for layout changes in the future.
  uint256[50] private ______gap;
}

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
contract ContextUpgradeSafe is Initializable {
    // Empty internal constructor, to prevent people from mistakenly deploying
    // an instance of this contract, which should be used via inheritance.

    function __Context_init() internal initializer {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal initializer {


    }


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

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

    uint256[50] private __gap;
}

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */

    function __Ownable_init() internal initializer {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal initializer {


        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);

    }


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

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

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

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

    uint256[49] private __gap;
}

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

/**
 * @title WePiggy's PToken Contract
 * @notice Abstract base for PTokens
 * @author Compound
 */
abstract contract PToken is IPToken, Exponential, TokenErrorReporter, OwnableUpgradeSafe {

    /**
     * @notice Initialize the money market
     * @param comptroller_ The address of the Comptroller
     * @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 init(IComptroller comptroller_,
        IInterestRateModel interestRateModel_,
        uint initialExchangeRateMantissa_,
        string memory name_,
        string memory symbol_,
        uint8 decimals_) public onlyOwner {
        require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once");

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

        // Set the comptroller
        uint err = _setComptroller(comptroller_);
        require(err == uint(Error.NO_ERROR), "setting comptroller failed");

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

        // Set the interest rate model (depends on block number / borrow index)
        err = _setInterestRateModelFresh(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 = comptroller.transferAllowed(address(this), src, dst, tokens);
        if (allowed != 0) {
            return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_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);

        comptroller.transferVerify(address(this), 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 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 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 override view 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 override view 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 comptroller 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 override view returns (uint, uint, uint, uint) {
        uint cTokenBalance = 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), cTokenBalance, borrowBalance, exchangeRateMantissa);
    }

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

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

    /**
     * @notice Returns the current per-block supply interest rate for this cToken
     * @return The supply interest rate per block, scaled by 1e18
     */
    function supplyRatePerBlock() external override view 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 override view 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 Return the borrow interest 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 borrowInterestBalancePriorInternal(address account) internal view returns (MathError, uint) {

        MathError mathErr;
        uint interestTimesIndex;
        uint principalTimesIndex;
        uint interestAmountPrior;

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

        if (borrowSnapshot.principal == 0) {
            return (MathError.NO_ERROR, 0);
        }
        (mathErr, interestTimesIndex) = mulUInt(borrowSnapshot.principal, borrowIndex);
        if (mathErr != MathError.NO_ERROR) {
            return (mathErr, 0);
        }

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

        (mathErr, interestAmountPrior) = subUInt(principalTimesIndex, borrowSnapshot.principal);
        if (mathErr != MathError.NO_ERROR) {
            return (mathErr, 0);
        }

        return (MathError.NO_ERROR, interestAmountPrior);
    }

    /**
     * @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 CToken
     * @dev This function does not accrue interest before calculating the exchange rate
     * @return Calculated exchange rate scaled by 1e18
     */
    function exchangeRateStored() public override view 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 CToken
     * @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 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 cToken in the underlying asset
     * @return The quantity of underlying asset owned by this contract
     */
    function getCash() external override view returns (uint) {
        return getCashPrior();
    }

    /**
    * @notice Applies accrued interest to total borrows and reserves
    * @dev This function is copy form accrueInterest.
    */
    function accrueInterestSnapshot() public view returns (uint[] memory) {

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

        /* 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;

        uint[] memory res = new uint[](6);

        (mathErr, simpleInterestFactor) = mulScalar(Exp({mantissa : borrowRateMantissa}), blockDelta);
        if (mathErr != MathError.NO_ERROR) {
            return res;
        }

        (mathErr, interestAccumulated) = mulScalarTruncate(simpleInterestFactor, borrowsPrior);
        if (mathErr != MathError.NO_ERROR) {
            return res;
        }

        (mathErr, totalBorrowsNew) = addUInt(interestAccumulated, borrowsPrior);
        if (mathErr != MathError.NO_ERROR) {
            return res;
        }

        (mathErr, totalReservesNew) = mulScalarTruncateAddUInt(Exp({mantissa : reserveFactorMantissa}), interestAccumulated, reservesPrior);
        if (mathErr != MathError.NO_ERROR) {
            return res;
        }

        (mathErr, borrowIndexNew) = mulScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior);
        if (mathErr != MathError.NO_ERROR) {
            return res;
        }

        res[0] = currentBlockNumber;
        res[1] = cashPrior;
        res[2] = interestAccumulated;
        res[3] = totalBorrowsNew;
        res[4] = totalReservesNew;
        res[5] = borrowIndexNew;

        return res;
    }

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

        // if interestAccumulated < minInterestAccumulated, set interestAccumulated = minInterestAccumulated
        (mathErr,) = subUInt(interestAccumulated, minInterestAccumulated);
        if (mathErr != MathError.NO_ERROR) {
            interestAccumulated = minInterestAccumulated;
        }

        (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 cTokens 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) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount.
     */
    function mintInternal(uint mintAmount) 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.MINT_ACCRUE_INTEREST_FAILED), 0);
        }
        // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to
        return mintFresh(msg.sender, mintAmount, 0);
    }

    function mintInternalForMigrate(uint mintAmount, uint mintTokens) internal nonReentrant returns (uint, uint) {
        require(msg.sender == migrator, "mintInternalForMigrate: caller is not the migrator");

        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);
        }
        // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to
        return mintFresh(msg.sender, mintAmount, mintTokens);
    }

    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 cTokens 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) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount.
     */
    function mintFresh(address minter, uint mintAmount, uint mintTokens) internal returns (uint, uint) {

        /* Fail if mint not allowed */
        if (mintTokens == 0) {
            uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount);
            if (allowed != 0) {
                return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed), 0);
            }
        }

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

        MintLocalVars memory vars;

        if (mintTokens == 0) {
            (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);
            }
        }

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

        /*
         *  We call `doTransferIn` for the minter and the mintAmount.
         *  Note: The cToken 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 cToken holds an additional `actualMintAmount`
         *  of cash.
         */
        vars.actualMintAmount = doTransferIn(minter, mintAmount);

        if (mintTokens == 0) {
            /*
             * We get the current exchange rate and calculate the number of cTokens 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");
        } else {
            vars.mintTokens = mintTokens;
        }


        /*
         * We calculate the new total supply of cTokens 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, vars.totalSupplyNew, vars.accountTokensNew);
        emit Transfer(address(this), minter, vars.mintTokens);

        /* We call the defense hook */
        comptroller.mintVerify(address(this), minter, vars.actualMintAmount, vars.mintTokens);

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

    /**
     * @notice Sender redeems cTokens in exchange for the underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param redeemTokens The number of cTokens to redeem into underlying
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeemInternal(uint redeemTokens) 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 redeem failed
            return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED);
        }
        // redeemFresh emits redeem-specific logs on errors, so we don't need to
        return redeemFresh(msg.sender, redeemTokens, 0);
    }

    /**
     * @notice Sender redeems cTokens 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 cTokens
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeemUnderlyingInternal(uint redeemAmount) 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 redeem failed
            return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED);
        }
        // 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 cTokens 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 cTokens 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 cTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero)
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal returns (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));
        }

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

            vars.redeemAmount = redeemAmountIn;
        }

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

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

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

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

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

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

        /*
         * We invoke doTransferOut for the redeemer and the redeemAmount.
         *  Note: The cToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the cToken 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, vars.totalSupplyNew, vars.accountTokensNew);

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

        return uint(Error.NO_ERROR);
    }

    /**
      * @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;
        uint interestBalancePrior; //interest balance before now.
    }

    /**
      * @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 = comptroller.borrowAllowed(address(this), borrower, borrowAmount);
        if (allowed != 0) {
            return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_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.interestBalancePrior) = borrowInterestBalancePriorInternal(borrower);
        if (vars.mathErr != MathError.NO_ERROR) {
            return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_INTEREST_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));
        }

        (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 cToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the cToken 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, vars.interestBalancePrior);

        /* We call the defense hook */
        comptroller.borrowVerify(address(this), borrower, borrowAmount);

        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;
        uint interestBalancePrior;
    }

    /**
     * @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 = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount);
        if (allowed != 0) {
            return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_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;

        (vars.mathErr, vars.interestBalancePrior) = borrowInterestBalancePriorInternal(borrower);
        if (vars.mathErr != MathError.NO_ERROR) {
            return (failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_INTEREST_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)), 0);
        }

        /* 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 repayAmount == -1, repayAmount = accountBorrows */
        if (repayAmount == uint(- 1)) {
            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 cToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the cToken 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, vars.interestBalancePrior);

        /* We call the defense hook */
        comptroller.repayBorrowVerify(address(this), payer, borrower, vars.actualRepayAmount, vars.borrowerIndex);

        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 cToken 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, IPToken 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 cToken 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, IPToken pTokenCollateral) internal returns (uint, uint) {
        /* Fail if liquidate not allowed */
        uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(pTokenCollateral), liquidator, borrower, repayAmount);
        if (allowed != 0) {
            return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_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) = comptroller.liquidateCalculateSeizeTokens(address(this), address(pTokenCollateral), actualRepayAmount);
        require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_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);

        /* We call the defense hook */
        comptroller.liquidateBorrowVerify(address(this), address(pTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens);

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

    /**
     * @notice Transfers collateral tokens (this market) to the liquidator.
     * @dev Will fail unless called by another cToken during the process of liquidation.
     *  Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter.
     * @param liquidator The account receiving seized collateral
     * @param borrower The account having collateral seized
     * @param seizeTokens The number of cTokens 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 CToken.
     *  Its absolutely critical to use msg.sender as the seizer cToken and not a parameter.
     * @param seizerToken The contract seizing the collateral (i.e. borrowed cToken)
     * @param liquidator The account receiving seized collateral
     * @param borrower The account having collateral seized
     * @param seizeTokens The number of cTokens 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 returns (uint) {
        /* Fail if seize not allowed */
        uint allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens);
        if (allowed != 0) {
            return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_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);

        /* We call the defense hook */
        comptroller.seizeVerify(address(this), seizerToken, liquidator, borrower, seizeTokens);

        return uint(Error.NO_ERROR);
    }


    /*** Admin Functions ***/

    /**
      * @notice Sets a new comptroller for the market
      * @dev Admin function to set a new comptroller
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function _setComptroller(IComptroller newComptroller) public onlyOwner override returns (uint) {
        IComptroller oldComptroller = comptroller;
        // Ensure invoke comptroller.isComptroller() returns true
        // require(newComptroller.isComptroller(), "marker method returned false");

        // Set market's comptroller to newComptroller
        comptroller = newComptroller;

        // Emit NewComptroller(oldComptroller, newComptroller)
        emit NewComptroller(oldComptroller, newComptroller);

        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 onlyOwner returns (uint) {
        // 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 cToken must handle variations between ERC-20 and ETH underlying.
         *  On success, the cToken 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 onlyOwner returns (uint) {
        // totalReserves - reduceAmount
        uint totalReservesNew;

        // 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(payable(owner()), reduceAmount);

        emit ReservesReduced(owner(), 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(IInterestRateModel 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(IInterestRateModel newInterestRateModel) internal onlyOwner returns (uint) {

        // Used to store old model for use in the event that is emitted on success
        IInterestRateModel 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 _setMigrator(address newMigrator) public onlyOwner override returns (uint) {
        address oldMigrator = migrator;

        // Set market's comptroller to newComptroller
        migrator = newMigrator;

        // Emit NewComptroller(oldComptroller, newComptroller)
        emit NewMigrator(oldMigrator, newMigrator);

        return uint(Error.NO_ERROR);
    }

    function _setMinInterestAccumulated(uint _minInterestAccumulated) public onlyOwner override returns (uint256){
        uint oldMinInterestAccumulated = minInterestAccumulated;

        minInterestAccumulated = _minInterestAccumulated;

        emit NewMinInterestAccumulated(oldMinInterestAccumulated, _minInterestAccumulated);

        return uint(Error.NO_ERROR);
    }

    /*** 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 virtual view 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
    }
}

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

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

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

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

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

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

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

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

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

interface IPriceOracle {
    /**
     * @notice Get the underlying price of a asset
     * @param _pToken The asset to get the underlying price of
     * @return The underlying asset price.
     *  Zero means the price is unavailable.
     */
    function getUnderlyingPrice(PToken _pToken) external view returns (uint);
}

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

contract ComptrollerStorage {

    //PIGGY-MODIFY:Copy and modify from ComptrollerV1Storage

    /**
     * @notice Oracle which gives the price of any given asset
     */
    IPriceOracle public oracle;

    /**
     * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow
     */
    uint256 public closeFactorMantissa;

    /**
     * @notice Multiplier representing the discount on collateral that a liquidator receives
     */
    uint256 public liquidationIncentiveMantissa;

    /**
     * @notice Max number of assets a single account can participate in (borrow or use as collateral)
     */
    uint256 public maxAssets;

    /**
     * PIGGY-MODIFY:
     * @notice Per-account mapping of "assets you are in", capped by maxAssets
     */
    mapping(address => PToken[]) public accountAssets;

    /**
     * PIGGY-MODIFY: Copy and modify from ComptrollerV2Storage
     */
    struct Market {
        // @notice Whether or not this market is listed
        bool isListed;

        // @notice Multiplier representing the most one can borrow against their collateral in this market.
        // For instance, 0.9 to allow borrowing 90% of collateral value. Must be between 0 and 1, and stored as a mantissa.
        uint256 collateralFactorMantissa;

        // @notice Per-market mapping of "accounts in this asset"
        mapping(address => bool) accountMembership;

        // @notice Whether or not this market receives WPC
        bool isMinted;
    }

    /**
     * @notice Official mapping of pTokens -> Market metadata
     * @dev Used e.g. to determine if a market is supported
     */
    mapping(address => Market) public markets;

    /**
     * @notice The Pause Guardian can pause certain actions as a safety mechanism.
     *  Actions which allow users to remove their own assets cannot be paused.
     *  Liquidation / seizing / transfer can only be paused globally, not by market.
     */
    address public pauseGuardian;
    bool public _mintGuardianPaused;
    bool public _borrowGuardianPaused;
    bool public transferGuardianPaused;
    bool public seizeGuardianPaused;
    mapping(address => bool) public pTokenMintGuardianPaused;
    mapping(address => bool) public pTokenBorrowGuardianPaused;
    bool public distributeWpcPaused;


    //PIGGY-MODIFY: Copy and modify from ComptrollerV4Storage

    // @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market.
    address public borrowCapGuardian;

    // @notice Borrow caps enforced by borrowAllowed for each cToken address. Defaults to zero which corresponds to unlimited borrowing.
    mapping(address => uint256) public borrowCaps;


    //PIGGY-MODIFY: Copy and modify from ComptrollerV3Storage
    /// @notice A list of all markets
    PToken[] public allMarkets;

}

interface IPiggyDistribution {

    function distributeMintWpc(address pToken, address minter, bool distributeAll) external;

    function distributeRedeemWpc(address pToken, address redeemer, bool distributeAll) external;

    function distributeBorrowWpc(address pToken, address borrower, bool distributeAll) external;

    function distributeRepayBorrowWpc(address pToken, address borrower, bool distributeAll) external;

    function distributeSeizeWpc(address pTokenCollateral, address borrower, address liquidator, bool distributeAll) external;

    function distributeTransferWpc(address pToken, address src, address dst, bool distributeAll) external;

}

interface IPiggyBreeder {
    function stake(uint256 _pid, uint256 _amount) external;

    function unStake(uint256 _pid, uint256 _amount) external;

    function claim(uint256 _pid) external;

    function emergencyWithdraw(uint256 _pid) external;
}

contract PiggyDistribution is IPiggyDistribution, Exponential, OwnableUpgradeSafe {

    IERC20 public piggy;

    IPiggyBreeder public piggyBreeder;

    Comptroller public comptroller;

    //PIGGY-MODIFY: Copy and modify from ComptrollerV3Storage

    struct WpcMarketState {
        /// @notice The market's last updated compBorrowIndex or compSupplyIndex
        uint224 index;

        /// @notice The block number the index was last updated at
        uint32 block;
    }

    /// @notice The portion of compRate that each market currently receives
    mapping(address => uint) public wpcSpeeds;

    /// @notice The WPC market supply state for each market
    mapping(address => WpcMarketState) public wpcSupplyState;

    /// @notice The WPC market borrow state for each market
    mapping(address => WpcMarketState) public wpcBorrowState;

    /// @notice The WPC borrow index for each market for each supplier as of the last time they accrued WPC
    mapping(address => mapping(address => uint)) public wpcSupplierIndex;

    /// @notice The WPC borrow index for each market for each borrower as of the last time they accrued WPC
    mapping(address => mapping(address => uint)) public wpcBorrowerIndex;

    /// @notice The WPC accrued but not yet transferred to each user
    mapping(address => uint) public wpcAccrued;

    /// @notice The threshold above which the flywheel transfers WPC, in wei
    uint public constant wpcClaimThreshold = 0.001e18;

    /// @notice The initial WPC index for a market
    uint224 public constant wpcInitialIndex = 1e36;

    bool public enableWpcClaim;
    bool public enableDistributeMintWpc;
    bool public enableDistributeRedeemWpc;
    bool public enableDistributeBorrowWpc;
    bool public enableDistributeRepayBorrowWpc;
    bool public enableDistributeSeizeWpc;
    bool public enableDistributeTransferWpc;


    /// @notice Emitted when a new WPC speed is calculated for a market
    event WpcSpeedUpdated(PToken indexed pToken, uint newSpeed);

    /// @notice Emitted when WPC is distributed to a supplier
    event DistributedSupplierWpc(PToken indexed pToken, address indexed supplier, uint wpcDelta, uint wpcSupplyIndex);

    /// @notice Emitted when WPC is distributed to a borrower
    event DistributedBorrowerWpc(PToken indexed pToken, address indexed borrower, uint wpcDelta, uint wpcBorrowIndex);

    event StakeTokenToPiggyBreeder(IERC20 token, uint pid, uint amount);

    event ClaimWpcFromPiggyBreeder(uint pid);

    event EnableState(string action, bool state);

    function initialize(IERC20 _piggy, IPiggyBreeder _piggyBreeder, Comptroller _comptroller) public initializer {

        piggy = _piggy;
        piggyBreeder = _piggyBreeder;
        comptroller = _comptroller;

        enableWpcClaim = false;
        enableDistributeMintWpc = false;
        enableDistributeRedeemWpc = false;
        enableDistributeBorrowWpc = false;
        enableDistributeRepayBorrowWpc = false;
        enableDistributeSeizeWpc = false;
        enableDistributeTransferWpc = false;

        super.__Ownable_init();
    }

    function distributeMintWpc(address pToken, address minter, bool distributeAll) public override(IPiggyDistribution) {
        require(msg.sender == address(comptroller) || msg.sender == owner(), "only comptroller or owner");
        if (enableDistributeMintWpc) {
            updateWpcSupplyIndex(pToken);
            distributeSupplierWpc(pToken, minter, distributeAll);
        }
    }

    function distributeRedeemWpc(address pToken, address redeemer, bool distributeAll) public override(IPiggyDistribution) {
        require(msg.sender == address(comptroller) || msg.sender == owner(), "only comptroller or owner");
        if (enableDistributeRedeemWpc) {
            updateWpcSupplyIndex(pToken);
            distributeSupplierWpc(pToken, redeemer, distributeAll);
        }
    }

    function distributeBorrowWpc(address pToken, address borrower, bool distributeAll) public override(IPiggyDistribution) {

        require(msg.sender == address(comptroller) || msg.sender == owner(), "only comptroller or owner");

        if (enableDistributeBorrowWpc) {
            Exp memory borrowIndex = Exp({mantissa : PToken(pToken).borrowIndex()});
            updateWpcBorrowIndex(pToken, borrowIndex);
            distributeBorrowerWpc(pToken, borrower, borrowIndex, distributeAll);
        }


    }

    function distributeRepayBorrowWpc(address pToken, address borrower, bool distributeAll) public override(IPiggyDistribution) {

        require(msg.sender == address(comptroller) || msg.sender == owner(), "only comptroller or owner");

        if (enableDistributeRepayBorrowWpc) {
            Exp memory borrowIndex = Exp({mantissa : PToken(pToken).borrowIndex()});
            updateWpcBorrowIndex(pToken, borrowIndex);
            distributeBorrowerWpc(pToken, borrower, borrowIndex, distributeAll);
        }

    }

    function distributeSeizeWpc(address pTokenCollateral, address borrower, address liquidator, bool distributeAll) public override(IPiggyDistribution) {

        require(msg.sender == address(comptroller) || msg.sender == owner(), "only comptroller or owner");

        if (enableDistributeSeizeWpc) {
            updateWpcSupplyIndex(pTokenCollateral);
            distributeSupplierWpc(pTokenCollateral, borrower, distributeAll);
            distributeSupplierWpc(pTokenCollateral, liquidator, distributeAll);
        }

    }

    function distributeTransferWpc(address pToken, address src, address dst, bool distributeAll) public override(IPiggyDistribution) {

        require(msg.sender == address(comptroller) || msg.sender == owner(), "only comptroller or owner");

        if (enableDistributeTransferWpc) {
            updateWpcSupplyIndex(pToken);
            distributeSupplierWpc(pToken, src, distributeAll);
            distributeSupplierWpc(pToken, dst, distributeAll);
        }

    }

    function _stakeTokenToPiggyBreeder(IERC20 token, uint pid) public onlyOwner {
        uint amount = token.balanceOf(address(this));
        token.approve(address(piggyBreeder), amount);
        piggyBreeder.stake(pid, amount);
        emit StakeTokenToPiggyBreeder(token, pid, amount);
    }

    function _claimWpcFromPiggyBreeder(uint pid) public onlyOwner {
        piggyBreeder.claim(pid);
        emit ClaimWpcFromPiggyBreeder(pid);
    }

    function setWpcSpeedInternal(PToken pToken, uint wpcSpeed) internal {
        uint currentWpcSpeed = wpcSpeeds[address(pToken)];
        if (currentWpcSpeed != 0) {
            // note that WPC speed could be set to 0 to halt liquidity rewards for a market
            Exp memory borrowIndex = Exp({mantissa : pToken.borrowIndex()});
            updateWpcSupplyIndex(address(pToken));
            updateWpcBorrowIndex(address(pToken), borrowIndex);
        } else if (wpcSpeed != 0) {

            require(comptroller.isMarketListed(address(pToken)), "wpc market is not listed");

            if (comptroller.isMarketMinted(address(pToken)) == false) {
                comptroller._setMarketMinted(address(pToken), true);
            }

            if (wpcSupplyState[address(pToken)].index == 0 && wpcSupplyState[address(pToken)].block == 0) {
                wpcSupplyState[address(pToken)] = WpcMarketState({
                index : wpcInitialIndex,
                block : safe32(block.number, "block number exceeds 32 bits")
                });
            }

            if (wpcBorrowState[address(pToken)].index == 0 && wpcBorrowState[address(pToken)].block == 0) {
                wpcBorrowState[address(pToken)] = WpcMarketState({
                index : wpcInitialIndex,
                block : safe32(block.number, "block number exceeds 32 bits")
                });
            }

        }

        if (currentWpcSpeed != wpcSpeed) {
            wpcSpeeds[address(pToken)] = wpcSpeed;
            emit WpcSpeedUpdated(pToken, wpcSpeed);
        }

    }

    /**
     * @notice Accrue WPC to the market by updating the supply index
     * @param pToken The market whose supply index to update
     */
    function updateWpcSupplyIndex(address pToken) internal {
        WpcMarketState storage supplyState = wpcSupplyState[pToken];
        uint supplySpeed = wpcSpeeds[pToken];
        uint blockNumber = block.number;
        uint deltaBlocks = sub_(blockNumber, uint(supplyState.block));
        if (deltaBlocks > 0 && supplySpeed > 0) {
            uint supplyTokens = PToken(pToken).totalSupply();
            uint wpcAccrued = mul_(deltaBlocks, supplySpeed);
            Double memory ratio = supplyTokens > 0 ? fraction(wpcAccrued, supplyTokens) : Double({mantissa : 0});
            Double memory index = add_(Double({mantissa : supplyState.index}), ratio);
            wpcSupplyState[pToken] = WpcMarketState({
            index : safe224(index.mantissa, "new index exceeds 224 bits"),
            block : safe32(blockNumber, "block number exceeds 32 bits")
            });
        } else if (deltaBlocks > 0) {
            supplyState.block = safe32(blockNumber, "block number exceeds 32 bits");
        }
    }

    /**
     * @notice Accrue WPC to the market by updating the borrow index
     * @param pToken The market whose borrow index to update
     */
    function updateWpcBorrowIndex(address pToken, Exp memory marketBorrowIndex) internal {
        WpcMarketState storage borrowState = wpcBorrowState[pToken];
        uint borrowSpeed = wpcSpeeds[pToken];
        uint blockNumber = block.number;
        uint deltaBlocks = sub_(blockNumber, uint(borrowState.block));
        if (deltaBlocks > 0 && borrowSpeed > 0) {
            uint borrowAmount = div_(PToken(pToken).totalBorrows(), marketBorrowIndex);
            uint wpcAccrued = mul_(deltaBlocks, borrowSpeed);
            Double memory ratio = borrowAmount > 0 ? fraction(wpcAccrued, borrowAmount) : Double({mantissa : 0});
            Double memory index = add_(Double({mantissa : borrowState.index}), ratio);
            wpcBorrowState[pToken] = WpcMarketState({
            index : safe224(index.mantissa, "new index exceeds 224 bits"),
            block : safe32(blockNumber, "block number exceeds 32 bits")
            });
        } else if (deltaBlocks > 0) {
            borrowState.block = safe32(blockNumber, "block number exceeds 32 bits");
        }
    }

    /**
     * @notice Calculate WPC accrued by a supplier and possibly transfer it to them
     * @param pToken The market in which the supplier is interacting
     * @param supplier The address of the supplier to distribute WPC to
     */
    function distributeSupplierWpc(address pToken, address supplier, bool distributeAll) internal {
        WpcMarketState storage supplyState = wpcSupplyState[pToken];
        Double memory supplyIndex = Double({mantissa : supplyState.index});
        Double memory supplierIndex = Double({mantissa : wpcSupplierIndex[pToken][supplier]});
        wpcSupplierIndex[pToken][supplier] = supplyIndex.mantissa;

        if (supplierIndex.mantissa == 0 && supplyIndex.mantissa > 0) {
            supplierIndex.mantissa = wpcInitialIndex;
        }

        Double memory deltaIndex = sub_(supplyIndex, supplierIndex);
        uint supplierTokens = PToken(pToken).balanceOf(supplier);
        uint supplierDelta = mul_(supplierTokens, deltaIndex);
        uint supplierAccrued = add_(wpcAccrued[supplier], supplierDelta);
        wpcAccrued[supplier] = grantWpcInternal(supplier, supplierAccrued, distributeAll ? 0 : wpcClaimThreshold);
        emit DistributedSupplierWpc(PToken(pToken), supplier, supplierDelta, supplyIndex.mantissa);
    }


    /**
     * @notice Calculate WPC accrued by a borrower and possibly transfer it to them
     * @dev Borrowers will not begin to accrue until after the first interaction with the protocol.
     * @param pToken The market in which the borrower is interacting
     * @param borrower The address of the borrower to distribute WPC to
     */
    function distributeBorrowerWpc(address pToken, address borrower, Exp memory marketBorrowIndex, bool distributeAll) internal {
        WpcMarketState storage borrowState = wpcBorrowState[pToken];
        Double memory borrowIndex = Double({mantissa : borrowState.index});
        Double memory borrowerIndex = Double({mantissa : wpcBorrowerIndex[pToken][borrower]});
        wpcBorrowerIndex[pToken][borrower] = borrowIndex.mantissa;

        if (borrowerIndex.mantissa > 0) {
            Double memory deltaIndex = sub_(borrowIndex, borrowerIndex);
            uint borrowerAmount = div_(PToken(pToken).borrowBalanceStored(borrower), marketBorrowIndex);
            uint borrowerDelta = mul_(borrowerAmount, deltaIndex);
            uint borrowerAccrued = add_(wpcAccrued[borrower], borrowerDelta);
            wpcAccrued[borrower] = grantWpcInternal(borrower, borrowerAccrued, distributeAll ? 0 : wpcClaimThreshold);
            emit DistributedBorrowerWpc(PToken(pToken), borrower, borrowerDelta, borrowIndex.mantissa);
        }
    }


    /**
     * @notice Transfer WPC to the user, if they are above the threshold
     * @dev Note: If there is not enough WPC, we do not perform the transfer all.
     * @param user The address of the user to transfer WPC to
     * @param userAccrued The amount of WPC to (possibly) transfer
     * @return The amount of WPC which was NOT transferred to the user
     */
    function grantWpcInternal(address user, uint userAccrued, uint threshold) internal returns (uint) {

        if (userAccrued >= threshold && userAccrued > 0) {
            uint wpcRemaining = piggy.balanceOf(address(this));
            if (userAccrued <= wpcRemaining) {
                piggy.transfer(user, userAccrued);
                return 0;
            }
        }
        return userAccrued;
    }

    /**
     * @notice Claim all the wpc accrued by holder in all markets
     * @param holder The address to claim WPC for
     */
    function claimWpc(address holder) public {
        claimWpc(holder, comptroller.getAllMarkets());
    }

    /**
     * @notice Claim all the comp accrued by holder in the specified markets
     * @param holder The address to claim WPC for
     * @param pTokens The list of markets to claim WPC in
     */
    function claimWpc(address holder, PToken[] memory pTokens) public {
        address[] memory holders = new address[](1);
        holders[0] = holder;
        claimWpc(holders, pTokens, true, false);
    }

    /**
     * @notice Claim all wpc accrued by the holders
     * @param holders The addresses to claim WPC for
     * @param pTokens The list of markets to claim WPC in
     * @param borrowers Whether or not to claim WPC earned by borrowing
     * @param suppliers Whether or not to claim WPC earned by supplying
     */
    function claimWpc(address[] memory holders, PToken[] memory pTokens, bool borrowers, bool suppliers) public {
        require(enableWpcClaim, "Claim is not enabled");

        for (uint i = 0; i < pTokens.length; i++) {
            PToken pToken = pTokens[i];
            require(comptroller.isMarketListed(address(pToken)), "market must be listed");
            if (borrowers == true) {
                Exp memory borrowIndex = Exp({mantissa : pToken.borrowIndex()});
                updateWpcBorrowIndex(address(pToken), borrowIndex);
                for (uint j = 0; j < holders.length; j++) {
                    distributeBorrowerWpc(address(pToken), holders[j], borrowIndex, true);
                }
            }
            if (suppliers == true) {
                updateWpcSupplyIndex(address(pToken));
                for (uint j = 0; j < holders.length; j++) {
                    distributeSupplierWpc(address(pToken), holders[j], true);
                }
            }
        }

    }

    /*** WPC Distribution Admin ***/

    function _setWpcSpeed(PToken pToken, uint wpcSpeed) public onlyOwner {
        setWpcSpeedInternal(pToken, wpcSpeed);
    }

    function _setEnableWpcClaim(bool state) public onlyOwner {
        enableWpcClaim = state;
        emit EnableState("enableWpcClaim", state);
    }

    function _setEnableDistributeMintWpc(bool state) public onlyOwner {
        enableDistributeMintWpc = state;
        emit EnableState("enableDistributeMintWpc", state);
    }

    function _setEnableDistributeRedeemWpc(bool state) public onlyOwner {
        enableDistributeRedeemWpc = state;
        emit EnableState("enableDistributeRedeemWpc", state);
    }

    function _setEnableDistributeBorrowWpc(bool state) public onlyOwner {
        enableDistributeBorrowWpc = state;
        emit EnableState("enableDistributeBorrowWpc", state);
    }

    function _setEnableDistributeRepayBorrowWpc(bool state) public onlyOwner {
        enableDistributeRepayBorrowWpc = state;
        emit EnableState("enableDistributeRepayBorrowWpc", state);
    }

    function _setEnableDistributeSeizeWpc(bool state) public onlyOwner {
        enableDistributeSeizeWpc = state;
        emit EnableState("enableDistributeSeizeWpc", state);
    }

    function _setEnableDistributeTransferWpc(bool state) public onlyOwner {
        enableDistributeTransferWpc = state;
        emit EnableState("enableDistributeTransferWpc", state);
    }

    function _setEnableAll(bool state) public onlyOwner {
        _setEnableDistributeMintWpc(state);
        _setEnableDistributeRedeemWpc(state);
        _setEnableDistributeBorrowWpc(state);
        _setEnableDistributeRepayBorrowWpc(state);
        _setEnableDistributeSeizeWpc(state);
        _setEnableDistributeTransferWpc(state);
        _setEnableWpcClaim(state);
    }

    function _transferWpc(address to, uint amount) public onlyOwner {
        _transferToken(address(piggy), to, amount);
    }

    function _transferToken(address token, address to, uint amount) public onlyOwner {
        IERC20 erc20 = IERC20(token);

        uint balance = erc20.balanceOf(address(this));
        if (balance < amount) {
            amount = balance;
        }

        erc20.transfer(to, amount);
    }

    function pendingWpcAccrued(address holder, bool borrowers, bool suppliers) public view returns (uint256){
        return pendingWpcInternal(holder, borrowers, suppliers);
    }

    function pendingWpcInternal(address holder, bool borrowers, bool suppliers) internal view returns (uint256){

        uint256 pendingWpc = wpcAccrued[holder];

        PToken[] memory pTokens = comptroller.getAllMarkets();
        for (uint i = 0; i < pTokens.length; i++) {
            address pToken = address(pTokens[i]);
            uint tmp = 0;
            if (borrowers == true) {
                tmp = pendingWpcBorrowInternal(holder, pToken);
                pendingWpc = add_(pendingWpc, tmp);
            }
            if (suppliers == true) {
                tmp = pendingWpcSupplyInternal(holder, pToken);
                pendingWpc = add_(pendingWpc, tmp);
            }
        }

        return pendingWpc;
    }

    function pendingWpcBorrowInternal(address borrower, address pToken) internal view returns (uint256){
        if (enableDistributeBorrowWpc && enableDistributeRepayBorrowWpc) {
            Exp memory marketBorrowIndex = Exp({mantissa : PToken(pToken).borrowIndex()});
            WpcMarketState memory borrowState = pendingWpcBorrowIndex(pToken, marketBorrowIndex);

            Double memory borrowIndex = Double({mantissa : borrowState.index});
            Double memory borrowerIndex = Double({mantissa : wpcBorrowerIndex[pToken][borrower]});
            if (borrowerIndex.mantissa > 0) {
                Double memory deltaIndex = sub_(borrowIndex, borrowerIndex);
                uint borrowerAmount = div_(PToken(pToken).borrowBalanceStored(borrower), marketBorrowIndex);
                uint borrowerDelta = mul_(borrowerAmount, deltaIndex);
                return borrowerDelta;
            }
        }
        return 0;
    }

    function pendingWpcBorrowIndex(address pToken, Exp memory marketBorrowIndex) internal view returns (WpcMarketState memory){
        WpcMarketState memory borrowState = wpcBorrowState[pToken];
        uint borrowSpeed = wpcSpeeds[pToken];
        uint blockNumber = block.number;
        uint deltaBlocks = sub_(blockNumber, uint(borrowState.block));
        if (deltaBlocks > 0 && borrowSpeed > 0) {
            uint borrowAmount = div_(PToken(pToken).totalBorrows(), marketBorrowIndex);
            uint wpcAccrued = mul_(deltaBlocks, borrowSpeed);
            Double memory ratio = borrowAmount > 0 ? fraction(wpcAccrued, borrowAmount) : Double({mantissa : 0});
            Double memory index = add_(Double({mantissa : borrowState.index}), ratio);
            borrowState = WpcMarketState({
            index : safe224(index.mantissa, "new index exceeds 224 bits"),
            block : safe32(blockNumber, "block number exceeds 32 bits")
            });
        } else if (deltaBlocks > 0) {
            borrowState = WpcMarketState({
            index : borrowState.index,
            block : safe32(blockNumber, "block number exceeds 32 bits")
            });
        }
        return borrowState;
    }

    function pendingWpcSupplyInternal(address supplier, address pToken) internal view returns (uint256){
        if (enableDistributeMintWpc && enableDistributeRedeemWpc) {
            WpcMarketState memory supplyState = pendingWpcSupplyIndex(pToken);
            Double memory supplyIndex = Double({mantissa : supplyState.index});
            Double memory supplierIndex = Double({mantissa : wpcSupplierIndex[pToken][supplier]});
            if (supplierIndex.mantissa == 0 && supplyIndex.mantissa > 0) {
                supplierIndex.mantissa = wpcInitialIndex;
            }
            Double memory deltaIndex = sub_(supplyIndex, supplierIndex);
            uint supplierTokens = PToken(pToken).balanceOf(supplier);
            uint supplierDelta = mul_(supplierTokens, deltaIndex);
            return supplierDelta;
        }
        return 0;
    }

    function pendingWpcSupplyIndex(address pToken) internal view returns (WpcMarketState memory){
        WpcMarketState memory supplyState = wpcSupplyState[pToken];
        uint supplySpeed = wpcSpeeds[pToken];
        uint blockNumber = block.number;
        uint deltaBlocks = sub_(blockNumber, uint(supplyState.block));

        if (deltaBlocks > 0 && supplySpeed > 0) {
            uint supplyTokens = PToken(pToken).totalSupply();
            uint wpcAccrued = mul_(deltaBlocks, supplySpeed);
            Double memory ratio = supplyTokens > 0 ? fraction(wpcAccrued, supplyTokens) : Double({mantissa : 0});
            Double memory index = add_(Double({mantissa : supplyState.index}), ratio);
            supplyState = WpcMarketState({
            index : safe224(index.mantissa, "new index exceeds 224 bits"),
            block : safe32(blockNumber, "block number exceeds 32 bits")
            });
        } else if (deltaBlocks > 0) {
            supplyState = WpcMarketState({
            index : supplyState.index,
            block : safe32(blockNumber, "block number exceeds 32 bits")
            });
        }
        return supplyState;
    }

}

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

//PIGGY-MODIFY: Modified some methods and fields according to WePiggy's business logic
contract Comptroller is ComptrollerStorage, IComptroller, ComptrollerErrorReporter, Exponential, OwnableUpgradeSafe {

    // @notice Emitted when an admin supports a market
    event MarketListed(PToken pToken);

    // @notice Emitted when an account enters a market
    event MarketEntered(PToken pToken, address account);

    // @notice Emitted when an account exits a market
    event MarketExited(PToken pToken, address account);

    // @notice Emitted when close factor is changed by admin
    event NewCloseFactor(uint oldCloseFactorMantissa, uint newCloseFactorMantissa);

    // @notice Emitted when a collateral factor is changed by admin
    event NewCollateralFactor(PToken pToken, uint oldCollateralFactorMantissa, uint newCollateralFactorMantissa);

    // @notice Emitted when liquidation incentive is changed by admin
    event NewLiquidationIncentive(uint oldLiquidationIncentiveMantissa, uint newLiquidationIncentiveMantissa);

    // @notice Emitted when maxAssets is changed by admin
    event NewMaxAssets(uint oldMaxAssets, uint newMaxAssets);

    // @notice Emitted when price oracle is changed
    event NewPriceOracle(IPriceOracle oldPriceOracle, IPriceOracle newPriceOracle);

    // @notice Emitted when pause guardian is changed
    event NewPauseGuardian(address oldPauseGuardian, address newPauseGuardian);

    // @notice Emitted when an action is paused globally
    event ActionPaused(string action, bool pauseState);

    // @notice Emitted when an action is paused on a market
    event ActionPaused(PToken pToken, string action, bool pauseState);

    /// @notice Emitted when borrow cap for a pToken is changed
    event NewBorrowCap(PToken indexed pToken, uint newBorrowCap);

    /// @notice Emitted when borrow cap guardian is changed
    event NewBorrowCapGuardian(address oldBorrowCapGuardian, address newBorrowCapGuardian);

    event NewPiggyDistribution(IPiggyDistribution oldPiggyDistribution, IPiggyDistribution newPiggyDistribution);

    /// @notice Emitted when mint cap for a pToken is changed
    event NewMintCap(PToken indexed pToken, uint newMintCap);

    // closeFactorMantissa must be strictly greater than this value
    uint internal constant closeFactorMinMantissa = 0.05e18;

    // closeFactorMantissa must not exceed this value
    uint internal constant closeFactorMaxMantissa = 0.9e18;

    // No collateralFactorMantissa may exceed this value
    uint internal constant collateralFactorMaxMantissa = 0.9e18;

    // liquidationIncentiveMantissa must be no less than this value
    uint internal constant liquidationIncentiveMinMantissa = 1.0e18;

    // liquidationIncentiveMantissa must be no greater than this value
    uint internal constant liquidationIncentiveMaxMantissa = 1.5e18;

    // for distribute wpc
    IPiggyDistribution piggyDistribution;

    mapping(address => uint256) public mintCaps;

    function initialize() public initializer {

        //setting the msg.sender as the initial owner.
        super.__Ownable_init();
    }


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

    function enterMarkets(address[] memory pTokens) public override(IComptroller) returns (uint[] memory)  {
        uint len = pTokens.length;

        uint[] memory results = new uint[](len);
        for (uint i = 0; i < len; i++) {
            PToken pToken = PToken(pTokens[i]);
            results[i] = uint(addToMarketInternal(pToken, msg.sender));
        }

        return results;
    }

    /**
     * @notice Add the market to the borrower's "assets in" for liquidity calculations
     * @param pToken The market to enter
     * @param borrower The address of the account to modify
     * @return Success indicator for whether the market was entered
     */
    function addToMarketInternal(PToken pToken, address borrower) internal returns (Error) {
        Market storage marketToJoin = markets[address(pToken)];

        // market is not listed, cannot join
        if (!marketToJoin.isListed) {
            return Error.MARKET_NOT_LISTED;
        }

        // already joined
        if (marketToJoin.accountMembership[borrower] == true) {
            return Error.NO_ERROR;
        }

        // no space, cannot join
        if (accountAssets[borrower].length >= maxAssets) {
            return Error.TOO_MANY_ASSETS;
        }

        marketToJoin.accountMembership[borrower] = true;
        accountAssets[borrower].push(pToken);

        emit MarketEntered(pToken, borrower);

        return Error.NO_ERROR;
    }

    function exitMarket(address pTokenAddress) external override(IComptroller) returns (uint) {
        PToken pToken = PToken(pTokenAddress);

        // Get sender tokensHeld and amountOwed underlying from the pToken
        (uint oErr, uint tokensHeld, uint amountOwed,) = pToken.getAccountSnapshot(msg.sender);
        require(oErr == 0, "exitMarket: getAccountSnapshot failed");

        // Fail if the sender has a borrow balance
        if (amountOwed != 0) {
            return fail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED);
        }

        // Fail if the sender is not permitted to redeem all of their tokens
        uint allowed = redeemAllowedInternal(pTokenAddress, msg.sender, tokensHeld);
        if (allowed != 0) {
            return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed);
        }

        Market storage marketToExit = markets[address(pToken)];

        // Return true if the sender is not already ‘in’ the market
        if (!marketToExit.accountMembership[msg.sender]) {
            return uint(Error.NO_ERROR);
        }

        // Set pToken account membership to false
        delete marketToExit.accountMembership[msg.sender];

        // Delete pToken from the account’s list of assets
        // load into memory for faster iteration
        PToken[] memory userAssetList = accountAssets[msg.sender];
        uint len = userAssetList.length;
        uint assetIndex = len;
        for (uint i = 0; i < len; i++) {
            if (userAssetList[i] == pToken) {
                assetIndex = i;
                break;
            }
        }

        // We *must* have found the asset in the list or our redundant data structure is broken
        assert(assetIndex < len);

        // copy last item in list to location of item to be removed, reduce length by 1
        PToken[] storage storedList = accountAssets[msg.sender];
        storedList[assetIndex] = storedList[storedList.length - 1];
        storedList.pop();

        emit MarketExited(pToken, msg.sender);

        return uint(Error.NO_ERROR);
    }


    /**
    * @notice Returns the assets an account has entered
    * @param account The address of the account to pull assets for
    * @return A dynamic list with the assets the account has entered
    */
    function getAssetsIn(address account) external view returns (PToken[] memory) {
        PToken[] memory assetsIn = accountAssets[account];
        return assetsIn;
    }

    /**
     * @notice Returns whether the given account is entered in the given asset
     * @param account The address of the account to check
     * @param pToken The pToken to check
     * @return True if the account is in the asset, otherwise false.
     */
    function checkMembership(address account, PToken pToken) external view returns (bool) {
        return markets[address(pToken)].accountMembership[account];
    }

    /*** Policy Hooks ***/

    function mintAllowed(address pToken, address minter, uint mintAmount) external override(IComptroller) returns (uint){

        // Pausing is a very serious situation - we revert to sound the alarms
        require(!pTokenMintGuardianPaused[pToken], "mint is paused");

        //Shh - currently unused. It's written here to eliminate compile-time alarms.
        minter;
        mintAmount;

        if (!markets[pToken].isListed) {
            return uint(Error.MARKET_NOT_LISTED);
        }

        uint mintCap = mintCaps[pToken];
        if (mintCap != 0) {
            uint totalSupply = PToken(pToken).totalSupply();
            uint exchangeRate = PToken(pToken).exchangeRateStored();
            (MathError mErr, uint balance) = mulScalarTruncate(Exp({mantissa : exchangeRate}), totalSupply);
            require(mErr == MathError.NO_ERROR, "balance could not be calculated");
            (MathError mathErr, uint nextTotalMints) = addUInt(balance, mintAmount);
            require(mathErr == MathError.NO_ERROR, "total mint amount overflow");
            require(nextTotalMints < mintCap, "market mint cap reached");
        }

        if (distributeWpcPaused == false) {
            piggyDistribution.distributeMintWpc(pToken, minter, false);
        }

        return uint(Error.NO_ERROR);
    }

    function mintVerify(address pToken, address minter, uint mintAmount, uint mintTokens) external override(IComptroller) {

        //Shh - currently unused. It's written here to eliminate compile-time alarms.
        pToken;
        minter;
        mintAmount;
        mintTokens;

    }

    function redeemAllowed(address pToken, address redeemer, uint redeemTokens) external override(IComptroller) returns (uint){

        uint allowed = redeemAllowedInternal(pToken, redeemer, redeemTokens);
        if (allowed != uint(Error.NO_ERROR)) {
            return allowed;
        }

        if (distributeWpcPaused == false) {
            piggyDistribution.distributeRedeemWpc(pToken, redeemer, false);
        }

        return uint(Error.NO_ERROR);
    }

    /**
    * PIGGY-MODIFY:
    * @notice Checks if the account should be allowed to redeem tokens in the given market
    * @param pToken The market to verify the redeem against
    * @param redeemer The account which would redeem the tokens
    * @param redeemTokens The number of pTokens to exchange for the underlying asset in the market
    * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)
    */
    function redeemAllowedInternal(address pToken, address redeemer, uint redeemTokens) internal view returns (uint) {
        if (!markets[pToken].isListed) {
            return uint(Error.MARKET_NOT_LISTED);
        }

        /* If the redeemer is not 'in' the market, then we can bypass the liquidity check */
        if (!markets[pToken].accountMembership[redeemer]) {
            return uint(Error.NO_ERROR);
        }

        /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */
        (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(redeemer, PToken(pToken), redeemTokens, 0);
        if (err != Error.NO_ERROR) {
            return uint(err);
        }
        if (shortfall > 0) {
            return uint(Error.INSUFFICIENT_LIQUIDITY);
        }

        return uint(Error.NO_ERROR);
    }

    function redeemVerify(address pToken, address redeemer, uint redeemAmount, uint redeemTokens) external override(IComptroller) {
        //Shh - currently unused. It's written here to eliminate compile-time alarms.
        pToken;
        redeemer;
        redeemAmount;
        redeemTokens;
    }

    function borrowAllowed(address pToken, address borrower, uint borrowAmount) external override(IComptroller) returns (uint) {

        // Pausing is a very serious situation - we revert to sound the alarms
        require(!pTokenBorrowGuardianPaused[pToken], "borrow is paused");

        if (!markets[pToken].isListed) {
            return uint(Error.MARKET_NOT_LISTED);
        }

        if (!markets[pToken].accountMembership[borrower]) {

            // only pTokens may call borrowAllowed if borrower not in market
            require(msg.sender == pToken, "sender must be pToken");

            // attempt to add borrower to the market
            Error err = addToMarketInternal(PToken(msg.sender), borrower);
            if (err != Error.NO_ERROR) {
                return uint(err);
            }

            // it should be impossible to break the important invariant
            assert(markets[pToken].accountMembership[borrower]);
        }

        if (oracle.getUnderlyingPrice(PToken(pToken)) == 0) {
            return uint(Error.PRICE_ERROR);
        }

        uint borrowCap = borrowCaps[pToken];
        // Borrow cap of 0 corresponds to unlimited borrowing
        if (borrowCap != 0) {
            uint totalBorrows = PToken(pToken).totalBorrows();
            (MathError mathErr, uint nextTotalBorrows) = addUInt(totalBorrows, borrowAmount);
            require(mathErr == MathError.NO_ERROR, "total borrows overflow");
            require(nextTotalBorrows < borrowCap, "market borrow cap reached");
        }

        (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(borrower, PToken(pToken), 0, borrowAmount);
        if (err != Error.NO_ERROR) {
            return uint(err);
        }
        if (shortfall > 0) {
            return uint(Error.INSUFFICIENT_LIQUIDITY);
        }

        //distribute wpc
        if (distributeWpcPaused == false) {
            piggyDistribution.distributeBorrowWpc(pToken, borrower, false);
        }

        return uint(Error.NO_ERROR);

    }

    function borrowVerify(address pToken, address borrower, uint borrowAmount) external override(IComptroller) {
        //Shh - currently unused. It's written here to eliminate compile-time alarms.
        pToken;
        borrower;
        borrowAmount;
    }

    function repayBorrowAllowed(address pToken, address payer, address borrower, uint repayAmount) external override(IComptroller) returns (uint) {

        if (!markets[pToken].isListed) {
            return uint(Error.MARKET_NOT_LISTED);
        }

        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        payer;
        borrower;
        repayAmount;

        //distribute wpc
        if (distributeWpcPaused == false) {
            piggyDistribution.distributeRepayBorrowWpc(pToken, borrower, false);
        }

        return uint(Error.NO_ERROR);
    }

    function repayBorrowVerify(address pToken, address payer, address borrower, uint repayAmount, uint borrowerIndex) external override(IComptroller) {

        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        pToken;
        payer;
        borrower;
        repayAmount;
        borrowerIndex;
    }

    function liquidateBorrowAllowed(
        address pTokenBorrowed,
        address pTokenCollateral,
        address liquidator,
        address borrower,
        uint repayAmount
    ) external override(IComptroller) returns (uint){

        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        liquidator;

        if (!markets[pTokenBorrowed].isListed || !markets[pTokenCollateral].isListed) {
            return uint(Error.MARKET_NOT_LISTED);
        }

        /* The borrower must have shortfall in order to be liquidatable */
        (Error err, , uint shortfall) = getAccountLiquidityInternal(borrower);
        if (err != Error.NO_ERROR) {
            return uint(err);
        }
        if (shortfall == 0) {
            return uint(Error.INSUFFICIENT_SHORTFALL);
        }

        /* The liquidator may not repay more than what is allowed by the closeFactor */
        uint borrowBalance = PToken(pTokenBorrowed).borrowBalanceStored(borrower);
        (MathError mathErr, uint maxClose) = mulScalarTruncate(Exp({mantissa : closeFactorMantissa}), borrowBalance);
        if (mathErr != MathError.NO_ERROR) {
            return uint(Error.MATH_ERROR);
        }
        if (repayAmount > maxClose) {
            return uint(Error.TOO_MUCH_REPAY);
        }

        return uint(Error.NO_ERROR);
    }

    function liquidateBorrowVerify(
        address pTokenBorrowed,
        address pTokenCollateral,
        address liquidator,
        address borrower,
        uint repayAmount,
        uint seizeTokens
    ) external override(IComptroller) {

        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        pTokenBorrowed;
        pTokenCollateral;
        liquidator;
        borrower;
        repayAmount;
        seizeTokens;

    }

    function seizeAllowed(
        address pTokenCollateral,
        address pTokenBorrowed,
        address liquidator,
        address borrower,
        uint seizeTokens
    ) external override(IComptroller) returns (uint){
        // Pausing is a very serious situation - we revert to sound the alarms
        require(!seizeGuardianPaused, "seize is paused");

        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        seizeTokens;

        if (!markets[pTokenCollateral].isListed || !markets[pTokenBorrowed].isListed) {
            return uint(Error.MARKET_NOT_LISTED);
        }

        if (PToken(pTokenCollateral).comptroller() != PToken(pTokenBorrowed).comptroller()) {
            return uint(Error.COMPTROLLER_MISMATCH);
        }

        //distribute wpc
        if (distributeWpcPaused == false) {
            piggyDistribution.distributeSeizeWpc(pTokenCollateral, borrower, liquidator, false);
        }

        return uint(Error.NO_ERROR);
    }

    function seizeVerify(
        address pTokenCollateral,
        address pTokenBorrowed,
        address liquidator,
        address borrower,
        uint seizeTokens
    ) external override(IComptroller) {

        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        pTokenCollateral;
        pTokenBorrowed;
        liquidator;
        borrower;
        seizeTokens;
    }

    function transferAllowed(
        address pToken,
        address src,
        address dst,
        uint transferTokens
    ) external override(IComptroller) returns (uint){
        // Pausing is a very serious situation - we revert to sound the alarms
        require(!transferGuardianPaused, "transfer is paused");

        // Currently the only consideration is whether or not
        //  the src is allowed to redeem this many tokens
        uint allowed = redeemAllowedInternal(pToken, src, transferTokens);
        if (allowed != uint(Error.NO_ERROR)) {
            return allowed;
        }

        //distribute wpc
        if (distributeWpcPaused == false) {
            piggyDistribution.distributeTransferWpc(pToken, src, dst, false);
        }

        return uint(Error.NO_ERROR);
    }

    function transferVerify(
        address pToken,
        address src,
        address dst,
        uint transferTokens
    ) external override(IComptroller) {
        // Shh - currently unused. It's written here to eliminate compile-time alarms.
        pToken;
        src;
        dst;
        transferTokens;
    }

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

    /**
     * @dev Local vars for avoiding stack-depth limits in calculating account liquidity.
     *  Note that `pTokenBalance` is the number of pTokens the account owns in the market,
     *  whereas `borrowBalance` is the amount of underlying that the account has borrowed.
     */
    struct AccountLiquidityLocalVars {
        uint sumCollateral;
        uint sumBorrowPlusEffects;
        uint pTokenBalance;
        uint borrowBalance;
        uint exchangeRateMantissa;
        uint oraclePriceMantissa;
        Exp collateralFactor;
        Exp exchangeRate;
        Exp oraclePrice;
        Exp tokensToDenom;
    }

    /**
     * @notice Determine the current account liquidity wrt collateral requirements
     * @return (possible error code (semi-opaque),
                account liquidity in excess of collateral requirements,
     *          account shortfall below collateral requirements)
     */
    function getAccountLiquidity(address account) public view returns (uint, uint, uint) {
        (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, PToken(0), 0, 0);
        return (uint(err), liquidity, shortfall);
    }


    /**
     * @notice Determine the current account liquidity wrt collateral requirements
     * @return (possible error code,
                account liquidity in excess of collateral requirements,
     *          account shortfall below collateral requirements)
     */
    function getAccountLiquidityInternal(address account) internal view returns (Error, uint, uint) {
        return getHypotheticalAccountLiquidityInternal(account, PToken(0), 0, 0);
    }

    /**
     * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed
     * @param pTokenModify The market to hypothetically redeem/borrow in
     * @param account The account to determine liquidity for
     * @param redeemTokens The number of tokens to hypothetically redeem
     * @param borrowAmount The amount of underlying to hypothetically borrow
     * @return (possible error code (semi-opaque),
                hypothetical account liquidity in excess of collateral requirements,
     *          hypothetical account shortfall below collateral requirements)
     */
    function getHypotheticalAccountLiquidity(
        address account,
        address pTokenModify,
        uint redeemTokens,
        uint borrowAmount) public view returns (uint, uint, uint) {
        (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, PToken(pTokenModify), redeemTokens, borrowAmount);
        return (uint(err), liquidity, shortfall);
    }


    /**
     * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed
     * @param account The account to determine liquidity for
     * @param pTokenModify The market to hypothetically redeem/borrow in
     * @param redeemTokens The number of tokens to hypothetically redeem
     * @param borrowAmount The amount of underlying to hypothetically borrow
     * @dev Note that we calculate the exchangeRateStored for each collateral pToken using stored data,
     *  without calculating accumulated interest.
     * @return (possible error code,
                hypothetical account liquidity in excess of collateral requirements,
     *          hypothetical account shortfall below collateral requirements)
     */
    function getHypotheticalAccountLiquidityInternal(
        address account,
        PToken pTokenModify,
        uint redeemTokens,
        uint borrowAmount) internal view returns (Error, uint, uint) {

        AccountLiquidityLocalVars memory vars;
        uint oErr;
        MathError mErr;

        // For each asset the account is in
        PToken[] memory assets = accountAssets[account];
        for (uint i = 0; i < assets.length; i++) {
            PToken asset = assets[i];

            // Read the balances and exchange rate from the pToken
            (oErr, vars.pTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = asset.getAccountSnapshot(account);
            if (oErr != 0) {// semi-opaque error code, we assume NO_ERROR == 0 is invariant between upgrades
                return (Error.SNAPSHOT_ERROR, 0, 0);
            }
            vars.collateralFactor = Exp({mantissa : markets[address(asset)].collateralFactorMantissa});
            vars.exchangeRate = Exp({mantissa : vars.exchangeRateMantissa});

            // Get the normalized price of the asset
            vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset);
            if (vars.oraclePriceMantissa == 0) {
                return (Error.PRICE_ERROR, 0, 0);
            }
            vars.oraclePrice = Exp({mantissa : vars.oraclePriceMantissa});

            // Pre-compute a conversion factor from tokens -> usd (normalized price value)
            // pTokenPrice = oraclePrice * exchangeRate
            (mErr, vars.tokensToDenom) = mulExp3(vars.collateralFactor, vars.exchangeRate, vars.oraclePrice);
            if (mErr != MathError.NO_ERROR) {
                return (Error.MATH_ERROR, 0, 0);
            }

            // sumCollateral += tokensToDenom * pTokenBalance
            (mErr, vars.sumCollateral) = mulScalarTruncateAddUInt(vars.tokensToDenom, vars.pTokenBalance, vars.sumCollateral);
            if (mErr != MathError.NO_ERROR) {
                return (Error.MATH_ERROR, 0, 0);
            }

            // sumBorrowPlusEffects += oraclePrice * borrowBalance
            (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects);
            if (mErr != MathError.NO_ERROR) {
                return (Error.MATH_ERROR, 0, 0);
            }

            // Calculate effects of interacting with pTokenModify
            if (asset == pTokenModify) {
                // redeem effect
                // sumBorrowPlusEffects += tokensToDenom * redeemTokens
                (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.tokensToDenom, redeemTokens, vars.sumBorrowPlusEffects);
                if (mErr != MathError.NO_ERROR) {
                    return (Error.MATH_ERROR, 0, 0);
                }

                // borrow effect
                // sumBorrowPlusEffects += oraclePrice * borrowAmount
                (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects);
                if (mErr != MathError.NO_ERROR) {
                    return (Error.MATH_ERROR, 0, 0);
                }
            }
        }

        // These are safe, as the underflow condition is checked first
        if (vars.sumCollateral > vars.sumBorrowPlusEffects) {
            return (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0);
        } else {
            return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral);
        }
    }

    function liquidateCalculateSeizeTokens(
        address pTokenBorrowed,
        address pTokenCollateral,
        uint actualRepayAmount
    ) external override(IComptroller) view returns (uint, uint) {
        /* Read oracle prices for borrowed and collateral markets */
        uint priceBorrowedMantissa = oracle.getUnderlyingPrice(PToken(pTokenBorrowed));
        uint priceCollateralMantissa = oracle.getUnderlyingPrice(PToken(pTokenCollateral));
        if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) {
            return (uint(Error.PRICE_ERROR), 0);
        }

        /*
        * Get the exchange rate and calculate the number of collateral tokens to seize:
        *  seizeAmount = actualRepayAmount * liquidationIncentive * priceBorrowed / priceCollateral
        *  seizeTokens = seizeAmount / exchangeRate
        *   = actualRepayAmount * (liquidationIncentive * priceBorrowed) / (priceCollateral * exchangeRate)
        *
        * Note: reverts on error
        */
        uint exchangeRateMantissa = PToken(pTokenCollateral).exchangeRateStored();

        uint seizeTokens;
        Exp memory numerator;
        Exp memory denominator;
        Exp memory ratio;
        MathError mathErr;

        (mathErr, numerator) = mulExp(liquidationIncentiveMantissa, priceBorrowedMantissa);
        if (mathErr != MathError.NO_ERROR) {
            return (uint(Error.MATH_ERROR), 0);
        }

        (mathErr, denominator) = mulExp(priceCollateralMantissa, exchangeRateMantissa);
        if (mathErr != MathError.NO_ERROR) {
            return (uint(Error.MATH_ERROR), 0);
        }

        (mathErr, ratio) = divExp(numerator, denominator);
        if (mathErr != MathError.NO_ERROR) {
            return (uint(Error.MATH_ERROR), 0);
        }

        (mathErr, seizeTokens) = mulScalarTruncate(ratio, actualRepayAmount);
        if (mathErr != MathError.NO_ERROR) {
            return (uint(Error.MATH_ERROR), 0);
        }

        return (uint(Error.NO_ERROR), seizeTokens);

    }

    /*** Admin Functions ***/

    /**
      * @notice Sets a new price oracle for the comptroller
      * @dev Admin function to set a new price oracle
      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function _setPriceOracle(IPriceOracle newOracle) public onlyOwner returns (uint) {

        // Track the old oracle for the comptroller
        IPriceOracle oldOracle = oracle;

        // Set comptroller's oracle to newOracle
        oracle = newOracle;

        // Emit NewPriceOracle(oldOracle, newOracle)
        emit NewPriceOracle(oldOracle, newOracle);

        return uint(Error.NO_ERROR);
    }

    /**
      * @notice Sets the closeFactor used when liquidating borrows
      * @dev Admin function to set closeFactor
      * @param newCloseFactorMantissa New close factor, scaled by 1e18
      * @return uint 0=success, otherwise a failure. (See ErrorReporter for details)
      */
    function _setCloseFactor(uint newCloseFactorMantissa) external onlyOwner returns (uint) {

        Exp memory newCloseFactorExp = Exp({mantissa : newCloseFactorMantissa});
        Exp memory lowLimit = Exp({mantissa : closeFactorMinMantissa});
        if (lessThanOrEqualExp(newCloseFactorExp, lowLimit)) {
            return fail(Error.INVALID_CLOSE_FACTOR, FailureInfo.SET_CLOSE_FACTOR_VALIDATION);
        }

        Exp memory highLimit = Exp({mantissa : closeFactorMaxMantissa});
        if (lessThanExp(highLimit, newCloseFactorExp)) {
            return fail(Error.INVALID_CLOSE_FACTOR, FailureInfo.SET_CLOSE_FACTOR_VALIDATION);
        }

        uint oldCloseFactorMantissa = closeFactorMantissa;
        closeFactorMantissa = newCloseFactorMantissa;
        emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa);

        return uint(Error.NO_ERROR);
    }

    /**
      * @notice Sets the collateralFactor for a market
      * @dev Admin function to set per-market collateralFactor
      * @param pToken The market to set the factor on
      * @param newCollateralFactorMantissa The new collateral factor, scaled by 1e18
      * @return uint 0=success, otherwise a failure. (See ErrorReporter for details)
      */
    function _setCollateralFactor(PToken pToken, uint newCollateralFactorMantissa) external onlyOwner returns (uint) {

        // Verify market is listed
        Market storage market = markets[address(pToken)];
        if (!market.isListed) {
            return fail(Error.MARKET_NOT_LISTED, FailureInfo.SET_COLLATERAL_FACTOR_NO_EXISTS);
        }

        Exp memory newCollateralFactorExp = Exp({mantissa : newCollateralFactorMantissa});

        // Check collateral factor <= 0.9
        Exp memory highLimit = Exp({mantissa : collateralFactorMaxMantissa});
        if (lessThanExp(highLimit, newCollateralFactorExp)) {
            return fail(Error.INVALID_COLLATERAL_FACTOR, FailureInfo.SET_COLLATERAL_FACTOR_VALIDATION);
        }

        // If collateral factor != 0, fail if price == 0
        if (newCollateralFactorMantissa != 0 && oracle.getUnderlyingPrice(pToken) == 0) {
            return fail(Error.PRICE_ERROR, FailureInfo.SET_COLLATERAL_FACTOR_WITHOUT_PRICE);
        }

        // Set market's collateral factor to new collateral factor, remember old value
        uint oldCollateralFactorMantissa = market.collateralFactorMantissa;
        market.collateralFactorMantissa = newCollateralFactorMantissa;

        // Emit event with asset, old collateral factor, and new collateral factor
        emit NewCollateralFactor(pToken, oldCollateralFactorMantissa, newCollateralFactorMantissa);

        return uint(Error.NO_ERROR);
    }

    /**
      * @notice Sets maxAssets which controls how many markets can be entered
      * @dev Admin function to set maxAssets
      * @param newMaxAssets New max assets
      * @return uint 0=success, otherwise a failure. (See ErrorReporter for details)
      */
    function _setMaxAssets(uint newMaxAssets) external onlyOwner returns (uint) {

        uint oldMaxAssets = maxAssets;
        maxAssets = newMaxAssets;
        emit NewMaxAssets(oldMaxAssets, newMaxAssets);

        return uint(Error.NO_ERROR);
    }

    /**
      * @notice Sets liquidationIncentive
      * @dev Admin function to set liquidationIncentive
      * @param newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18
      * @return uint 0=success, otherwise a failure. (See ErrorReporter for details)
      */
    function _setLiquidationIncentive(uint newLiquidationIncentiveMantissa) external onlyOwner returns (uint) {

        // Check de-scaled min <= newLiquidationIncentive <= max
        Exp memory newLiquidationIncentive = Exp({mantissa : newLiquidationIncentiveMantissa});
        Exp memory minLiquidationIncentive = Exp({mantissa : liquidationIncentiveMinMantissa});
        if (lessThanExp(newLiquidationIncentive, minLiquidationIncentive)) {
            return fail(Error.INVALID_LIQUIDATION_INCENTIVE, FailureInfo.SET_LIQUIDATION_INCENTIVE_VALIDATION);
        }

        Exp memory maxLiquidationIncentive = Exp({mantissa : liquidationIncentiveMaxMantissa});
        if (lessThanExp(maxLiquidationIncentive, newLiquidationIncentive)) {
            return fail(Error.INVALID_LIQUIDATION_INCENTIVE, FailureInfo.SET_LIQUIDATION_INCENTIVE_VALIDATION);
        }

        // Save current value for use in log
        uint oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa;

        // Set liquidation incentive to new incentive
        liquidationIncentiveMantissa = newLiquidationIncentiveMantissa;

        // Emit event with old incentive, new incentive
        emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa);

        return uint(Error.NO_ERROR);
    }

    /**
      * @notice Add the market to the markets mapping and set it as listed
      * @dev Admin function to set isListed and add support for the market
      * @param pToken The address of the market (token) to list
      * @return uint 0=success, otherwise a failure. (See enum Error for details)
      */
    function _supportMarket(PToken pToken) external onlyOwner returns (uint) {

        if (markets[address(pToken)].isListed) {
            return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS);
        }

        markets[address(pToken)] = Market({isListed : true, isMinted : false, collateralFactorMantissa : 0});

        _addMarketInternal(address(pToken));

        emit MarketListed(pToken);

        return uint(Error.NO_ERROR);
    }

    function _addMarketInternal(address pToken) internal onlyOwner {
        for (uint i = 0; i < allMarkets.length; i ++) {
            require(allMarkets[i] != PToken(pToken), "market already added");
        }
        allMarkets.push(PToken(pToken));
    }

    /**
      * @notice Set the given borrow caps for the given pToken markets. Borrowing that brings total borrows to or above borrow cap will revert.
      * @dev Admin or borrowCapGuardian function to set the borrow caps. A borrow cap of 0 corresponds to unlimited borrowing.
      * @param pTokens The addresses of the markets (tokens) to change the borrow caps for
      * @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing.
      */
    function _setMarketBorrowCaps(PToken[] calldata pTokens, uint[] calldata newBorrowCaps) external {
        require(msg.sender == owner() || msg.sender == borrowCapGuardian, "only owner or borrow cap guardian can set borrow caps");

        uint numMarkets = pTokens.length;
        uint numBorrowCaps = newBorrowCaps.length;

        require(numMarkets != 0 && numMarkets == numBorrowCaps, "invalid input");

        for (uint i = 0; i < numMarkets; i++) {
            borrowCaps[address(pTokens[i])] = newBorrowCaps[i];
            emit NewBorrowCap(pTokens[i], newBorrowCaps[i]);
        }
    }

    /**
     * @notice Admin function to change the Borrow Cap Guardian
     * @param newBorrowCapGuardian The address of the new Borrow Cap Guardian
     */
    function _setBorrowCapGuardian(address newBorrowCapGuardian) external onlyOwner {

        // Save current value for inclusion in log
        address oldBorrowCapGuardian = borrowCapGuardian;

        // Store borrowCapGuardian with value newBorrowCapGuardian
        borrowCapGuardian = newBorrowCapGuardian;

        // Emit NewBorrowCapGuardian(OldBorrowCapGuardian, NewBorrowCapGuardian)
        emit NewBorrowCapGuardian(oldBorrowCapGuardian, newBorrowCapGuardian);
    }

    /**
     * @notice Admin function to change the Pause Guardian
     * @param newPauseGuardian The address of the new Pause Guardian
     * @return uint 0=success, otherwise a failure. (See enum Error for details)
     */
    function _setPauseGuardian(address newPauseGuardian) public onlyOwner returns (uint) {

        // Save current value for inclusion in log
        address oldPauseGuardian = pauseGuardian;

        // Store pauseGuardian with value newPauseGuardian
        pauseGuardian = newPauseGuardian;

        // Emit NewPauseGuardian(OldPauseGuardian, NewPauseGuardian)
        emit NewPauseGuardian(oldPauseGuardian, pauseGuardian);

        return uint(Error.NO_ERROR);
    }

    function _setMintPaused(PToken pToken, bool state) public returns (bool) {
        require(markets[address(pToken)].isListed, "cannot pause a market that is not listed");
        require(msg.sender == pauseGuardian || msg.sender == owner(), "only pause guardian and owner can pause");
        require(msg.sender == owner() || state == true, "only owner can unpause");

        pTokenMintGuardianPaused[address(pToken)] = state;
        emit ActionPaused(pToken, "Mint", state);
        return state;
    }

    function _setBorrowPaused(PToken pToken, bool state) public returns (bool) {
        require(markets[address(pToken)].isListed, "cannot pause a market that is not listed");
        require(msg.sender == pauseGuardian || msg.sender == owner(), "only pause guardian and owner can pause");
        require(msg.sender == owner() || state == true, "only owner can unpause");

        pTokenBorrowGuardianPaused[address(pToken)] = state;
        emit ActionPaused(pToken, "Borrow", state);
        return state;
    }

    function _setTransferPaused(bool state) public returns (bool) {
        require(msg.sender == pauseGuardian || msg.sender == owner(), "only pause guardian and owner can pause");
        require(msg.sender == owner() || state == true, "only owner can unpause");

        transferGuardianPaused = state;
        emit ActionPaused("Transfer", state);
        return state;
    }

    function _setSeizePaused(bool state) public returns (bool) {
        require(msg.sender == pauseGuardian || msg.sender == owner(), "only pause guardian and owner can pause");
        require(msg.sender == owner() || state == true, "only owner can unpause");

        seizeGuardianPaused = state;
        emit ActionPaused("Seize", state);
        return state;
    }

    function _setDistributeWpcPaused(bool state) public returns (bool) {
        require(msg.sender == pauseGuardian || msg.sender == owner(), "only pause guardian and owner can pause");
        require(msg.sender == owner() || state == true, "only owner can unpause");

        distributeWpcPaused = state;
        emit ActionPaused("DistributeWpc", state);
        return state;
    }

    /**
     * @notice Sets a new price piggyDistribution for the comptroller
     * @dev Admin function to set a new piggy distribution
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _setPiggyDistribution(IPiggyDistribution newPiggyDistribution) public onlyOwner returns (uint) {

        IPiggyDistribution oldPiggyDistribution = piggyDistribution;

        piggyDistribution = newPiggyDistribution;

        emit NewPiggyDistribution(oldPiggyDistribution, newPiggyDistribution);

        return uint(Error.NO_ERROR);
    }

    function getAllMarkets() public view returns (PToken[] memory){
        return allMarkets;
    }

    function isMarketMinted(address pToken) public view returns (bool){
        return markets[pToken].isMinted;
    }

    function isMarketListed(address pToken) public view returns (bool){
        return markets[pToken].isListed;
    }

    function _setMarketMinted(address pToken, bool status) public {

        require(msg.sender == address(piggyDistribution) || msg.sender == owner(), "only PiggyDistribution or owner can update");

        markets[pToken].isMinted = status;
    }

    function _setMarketMintCaps(PToken[] calldata pTokens, uint[] calldata newMintCaps) external onlyOwner {

        uint numMarkets = pTokens.length;
        uint numMintCaps = newMintCaps.length;

        require(numMarkets != 0 && numMarkets == numMintCaps, "invalid input");

        for (uint i = 0; i < numMarkets; i++) {
            mintCaps[address(pTokens[i])] = newMintCaps[i];
            emit NewBorrowCap(pTokens[i], newMintCaps[i]);
        }
    }


}

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"pid","type":"uint256"}],"name":"ClaimWpcFromPiggyBreeder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract PToken","name":"pToken","type":"address"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"wpcDelta","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wpcBorrowIndex","type":"uint256"}],"name":"DistributedBorrowerWpc","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract PToken","name":"pToken","type":"address"},{"indexed":true,"internalType":"address","name":"supplier","type":"address"},{"indexed":false,"internalType":"uint256","name":"wpcDelta","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wpcSupplyIndex","type":"uint256"}],"name":"DistributedSupplierWpc","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"action","type":"string"},{"indexed":false,"internalType":"bool","name":"state","type":"bool"}],"name":"EnableState","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"StakeTokenToPiggyBreeder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract PToken","name":"pToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"newSpeed","type":"uint256"}],"name":"WpcSpeedUpdated","type":"event"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"_claimWpcFromPiggyBreeder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableDistributeBorrowWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableDistributeMintWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableDistributeRedeemWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableDistributeRepayBorrowWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableDistributeSeizeWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableDistributeTransferWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setEnableWpcClaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract PToken","name":"pToken","type":"address"},{"internalType":"uint256","name":"wpcSpeed","type":"uint256"}],"name":"_setWpcSpeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"_stakeTokenToPiggyBreeder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_transferToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_transferWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"contract PToken[]","name":"pTokens","type":"address[]"}],"name":"claimWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"holders","type":"address[]"},{"internalType":"contract PToken[]","name":"pTokens","type":"address[]"},{"internalType":"bool","name":"borrowers","type":"bool"},{"internalType":"bool","name":"suppliers","type":"bool"}],"name":"claimWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"claimWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"comptroller","outputs":[{"internalType":"contract Comptroller","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pToken","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"bool","name":"distributeAll","type":"bool"}],"name":"distributeBorrowWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pToken","type":"address"},{"internalType":"address","name":"minter","type":"address"},{"internalType":"bool","name":"distributeAll","type":"bool"}],"name":"distributeMintWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pToken","type":"address"},{"internalType":"address","name":"redeemer","type":"address"},{"internalType":"bool","name":"distributeAll","type":"bool"}],"name":"distributeRedeemWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pToken","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"bool","name":"distributeAll","type":"bool"}],"name":"distributeRepayBorrowWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pTokenCollateral","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"liquidator","type":"address"},{"internalType":"bool","name":"distributeAll","type":"bool"}],"name":"distributeSeizeWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pToken","type":"address"},{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"bool","name":"distributeAll","type":"bool"}],"name":"distributeTransferWpc","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"enableDistributeBorrowWpc","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableDistributeMintWpc","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableDistributeRedeemWpc","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableDistributeRepayBorrowWpc","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableDistributeSeizeWpc","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableDistributeTransferWpc","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableWpcClaim","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_piggy","type":"address"},{"internalType":"contract IPiggyBreeder","name":"_piggyBreeder","type":"address"},{"internalType":"contract Comptroller","name":"_comptroller","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"bool","name":"borrowers","type":"bool"},{"internalType":"bool","name":"suppliers","type":"bool"}],"name":"pendingWpcAccrued","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"piggy","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"piggyBreeder","outputs":[{"internalType":"contract IPiggyBreeder","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wpcAccrued","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wpcBorrowState","outputs":[{"internalType":"uint224","name":"index","type":"uint224"},{"internalType":"uint32","name":"block","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"wpcBorrowerIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wpcClaimThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wpcInitialIndex","outputs":[{"internalType":"uint224","name":"","type":"uint224"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wpcSpeeds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"wpcSupplierIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wpcSupplyState","outputs":[{"internalType":"uint224","name":"index","type":"uint224"},{"internalType":"uint32","name":"block","type":"uint32"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50614156806100206000396000f3fe608060405234801561001057600080fd5b506004361061027f5760003560e01c80638da5cb5b1161015c578063c48a3940116100ce578063eb4d3c3611610087578063eb4d3c361461094f578063efcd0db414610957578063f2fde38b1461097d578063f3a87196146109a3578063f774351e146109db578063f90ec13314610a135761027f565b8063c48a394014610881578063c771ea1914610889578063ce1afbe1146108a8578063d0fe0412146108de578063d3ad34cc146108fd578063e54ac468146109295761027f565b80639ce393f7116101205780639ce393f7146107a9578063a69ed161146107d5578063b5fdf28e14610803578063b712beef1461080b578063c0c53b8b14610813578063c16bb15c1461084b5761027f565b80638da5cb5b146106fd57806392068f041461070557806392e1a2951461072b57806399329c33146107635780639b52edb81461076b5761027f565b80634cd54b7a116101f55780635ff132f9116101b95780635ff132f9146106355780635ff8821914610661578063692c1d44146106695780636dd955531461068857806370d05be4146106d6578063715018a6146106f55761027f565b80634cd54b7a146104795780635169448b146104b757806352afdbfe146105e35780635e5ce05e146106095780635fe3b567146106115761027f565b80631f6c7a41116102475780631f6c7a41146103ba578063247092ce146103d957806327190769146103fd5780632f7d336a146104055780633637d9741461043d5780634485a2861461045a5761027f565b8063011875b51461028457806302c4678b1461033757806304f6e19c1461037757806304f79da81461039357806313f7cea11461039b575b600080fd5b6103356004803603604081101561029a57600080fd5b6001600160a01b038235169190810190604081016020820135600160201b8111156102c457600080fd5b8201836020820111156102d657600080fd5b803590602001918460208302840111600160201b831117156102f757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610a32945050505050565b005b6103656004803603604081101561034d57600080fd5b506001600160a01b0381358116916020013516610a95565b60408051918252519081900360200190f35b61037f610ab2565b604080519115158252519081900360200190f35b61037f610ac2565b610335600480360360208110156103b157600080fd5b50351515610ad0565b610335600480360360208110156103d057600080fd5b50351515610b99565b6103e1610c66565b604080516001600160e01b039092168252519081900360200190f35b61037f610c78565b6103356004803603606081101561041b57600080fd5b506001600160a01b038135811691602081013590911690604001351515610c81565b6103356004803603602081101561045357600080fd5b5035610d15565b6103356004803603602081101561047057600080fd5b50351515610e09565b6103356004803603608081101561048f57600080fd5b506001600160a01b038135811691602081013582169160408201351690606001351515610ed9565b610335600480360360808110156104cd57600080fd5b810190602081018135600160201b8111156104e757600080fd5b8201836020820111156104f957600080fd5b803590602001918460208302840111600160201b8311171561051a57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561056957600080fd5b82018360208201111561057b57600080fd5b803590602001918460208302840111600160201b8311171561059c57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505050803515159150602001351515610f80565b610365600480360360208110156105f957600080fd5b50356001600160a01b03166111d3565b6103656111e5565b6106196111f0565b604080516001600160a01b039092168252519081900360200190f35b6103356004803603604081101561064b57600080fd5b506001600160a01b0381351690602001356111ff565b61037f611412565b6103356004803603602081101561067f57600080fd5b50351515611424565b6106ae6004803603602081101561069e57600080fd5b50356001600160a01b03166114be565b604080516001600160e01b03909316835263ffffffff90911660208301528051918290030190f35b610335600480360360208110156106ec57600080fd5b503515156114e8565b6103356115b6565b610619611658565b6103656004803603602081101561071b57600080fd5b50356001600160a01b0316611667565b6103356004803603606081101561074157600080fd5b506001600160a01b038135811691602081013590911690604001351515611679565b61037f61178d565b6103356004803603608081101561078157600080fd5b506001600160a01b03813581169160208101358216916040820135169060600135151561179c565b610335600480360360408110156107bf57600080fd5b506001600160a01b038135169060200135611829565b610365600480360360408110156107eb57600080fd5b506001600160a01b038135811691602001351661189c565b6106196118b9565b6106196118c8565b6103356004803603606081101561082957600080fd5b506001600160a01b0381358116916020810135821691604090910135166118d7565b6103656004803603606081101561086157600080fd5b506001600160a01b038135169060208101351515906040013515156119d0565b61037f6119e7565b6103356004803603602081101561089f57600080fd5b503515156119f7565b610335600480360360608110156108be57600080fd5b506001600160a01b03813581169160208101359091169060400135611aa9565b610335600480360360208110156108f457600080fd5b50351515611c10565b6103356004803603604081101561091357600080fd5b506001600160a01b038135169060200135611ce1565b6103356004803603602081101561093f57600080fd5b50356001600160a01b0316611d43565b61037f611e61565b6106ae6004803603602081101561096d57600080fd5b50356001600160a01b0316611e71565b6103356004803603602081101561099357600080fd5b50356001600160a01b0316611e9b565b610335600480360360608110156109b957600080fd5b506001600160a01b038135811691602081013590911690604001351515611f94565b610335600480360360608110156109f157600080fd5b506001600160a01b03813581169160208101359091169060400135151561201e565b61033560048036036020811015610a2957600080fd5b503515156120a8565b604080516001808252818301909252606091602080830190803683370190505090508281600081518110610a6257fe5b60200260200101906001600160a01b031690816001600160a01b031681525050610a90818360016000610f80565b505050565b609d60209081526000928352604080842090915290825290205481565b60a054600160201b900460ff1681565b60a054610100900460ff1681565b610ad8612173565b6065546001600160a01b03908116911614610b28576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a08054821515610100810261ff0019909216919091179091556040805160208101929092528082526017828201527f656e61626c65446973747269627574654d696e745770630000000000000000006060830152516000805160206140c18339815191529181900360800190a150565b610ba1612173565b6065546001600160a01b03908116911614610bf1576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a080548215156301000000810263ff00000019909216919091179091556040805160208101929092528082526019828201527f656e61626c6544697374726962757465426f72726f77577063000000000000006060830152516000805160206140c18339815191529181900360800190a150565b6a0c097ce7bc90715b34b9f160241b81565b60a05460ff1681565b6099546001600160a01b0316331480610cb25750610c9d611658565b6001600160a01b0316336001600160a01b0316145b610cf1576040805162461bcd60e51b81526020600482015260196024820152600080516020614101833981519152604482015290519081900360640190fd5b60a054610100900460ff1615610a9057610d0a83612177565b610a908383836123e9565b610d1d612173565b6065546001600160a01b03908116911614610d6d576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b6098546040805163379607f560e01b81526004810184905290516001600160a01b039092169163379607f59160248082019260009290919082900301818387803b158015610dba57600080fd5b505af1158015610dce573d6000803e3d6000fd5b50506040805184815290517f44542e73ff1ebfa31eab4e203a32710f1b2be84fe883bc080772cf78b455b32d9350908190036020019150a150565b610e11612173565b6065546001600160a01b03908116911614610e61576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a08054821515600160301b810266ff0000000000001990921691909117909155604080516020810192909252808252601b828201527f656e61626c65446973747269627574655472616e7366657257706300000000006060830152516000805160206140c18339815191529181900360800190a150565b6099546001600160a01b0316331480610f0a5750610ef5611658565b6001600160a01b0316336001600160a01b0316145b610f49576040805162461bcd60e51b81526020600482015260196024820152600080516020614101833981519152604482015290519081900360640190fd5b60a054600160301b900460ff1615610f7a57610f6484612177565b610f6f8484836123e9565b610f7a8483836123e9565b50505050565b60a05460ff16610fce576040805162461bcd60e51b815260206004820152601460248201527310db185a5b481a5cc81b9bdd08195b98589b195960621b604482015290519081900360640190fd5b60005b83518110156111cc576000848281518110610fe857fe5b60209081029190910181015160995460408051633d98a1e560e01b81526001600160a01b0380851660048301529151939550911692633d98a1e592602480840193829003018186803b15801561103d57600080fd5b505afa158015611051573d6000803e3d6000fd5b505050506040513d602081101561106757600080fd5b50516110b2576040805162461bcd60e51b81526020600482015260156024820152741b585c9ad95d081b5d5cdd081899481b1a5cdd1959605a1b604482015290519081900360640190fd5b6001841515141561117a576110c5614022565b6040518060200160405280836001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561110957600080fd5b505afa15801561111d573d6000803e3d6000fd5b505050506040513d602081101561113357600080fd5b50519052905061114382826125df565b60005b87518110156111775761116f8389838151811061115f57fe5b602002602001015184600161285c565b600101611146565b50505b600183151514156111c35761118e81612177565b60005b86518110156111c1576111b9828883815181106111aa57fe5b602002602001015160016123e9565b600101611191565b505b50600101610fd1565b5050505050565b609f6020526000908152604090205481565b66038d7ea4c6800081565b6099546001600160a01b031681565b611207612173565b6065546001600160a01b03908116911614611257576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b6000826001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156112a657600080fd5b505afa1580156112ba573d6000803e3d6000fd5b505050506040513d60208110156112d057600080fd5b50516098546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810184905290519293509085169163095ea7b3916044808201926020929091908290030181600087803b15801561132b57600080fd5b505af115801561133f573d6000803e3d6000fd5b505050506040513d602081101561135557600080fd5b5050609854604080516307b0472f60e41b8152600481018590526024810184905290516001600160a01b0390921691637b0472f09160448082019260009290919082900301818387803b1580156113ab57600080fd5b505af11580156113bf573d6000803e3d6000fd5b5050604080516001600160a01b03871681526020810186905280820185905290517f9e607a7395a4b086a7a32e21952e8789eb525dafb3978a5f51a63d7e13b929919350908190036060019150a1505050565b60a05465010000000000900460ff1681565b61142c612173565b6065546001600160a01b0390811691161461147c576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b61148581610ad0565b61148e816120a8565b61149781610b99565b6114a0816114e8565b6114a981611c10565b6114b281610e09565b6114bb816119f7565b50565b609c602052600090815260409020546001600160e01b03811690600160e01b900463ffffffff1682565b6114f0612173565b6065546001600160a01b03908116911614611540576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a08054821515600160201b810264ff000000001990921691909117909155604080516020810192909252808252601e828201527f656e61626c65446973747269627574655265706179426f72726f7757706300006060830152516000805160206140c18339815191529181900360800190a150565b6115be612173565b6065546001600160a01b0390811691161461160e576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b6065546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3606580546001600160a01b0319169055565b6065546001600160a01b031690565b609a6020526000908152604090205481565b6099546001600160a01b03163314806116aa5750611695611658565b6001600160a01b0316336001600160a01b0316145b6116e9576040805162461bcd60e51b81526020600482015260196024820152600080516020614101833981519152604482015290519081900360640190fd5b60a054600160201b900460ff1615610a9057611703614022565b6040518060200160405280856001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561174757600080fd5b505afa15801561175b573d6000803e3d6000fd5b505050506040513d602081101561177157600080fd5b50519052905061178184826125df565b610f7a8484838561285c565b60a05462010000900460ff1681565b6099546001600160a01b03163314806117cd57506117b8611658565b6001600160a01b0316336001600160a01b0316145b61180c576040805162461bcd60e51b81526020600482015260196024820152600080516020614101833981519152604482015290519081900360640190fd5b60a05465010000000000900460ff1615610f7a57610f6484612177565b611831612173565b6065546001600160a01b03908116911614611881576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b609754611898906001600160a01b03168383611aa9565b5050565b609e60209081526000928352604080842090915290825290205481565b6097546001600160a01b031681565b6098546001600160a01b031681565b600054610100900460ff16806118f057506118f0612a35565b806118fe575060005460ff16155b6119395760405162461bcd60e51b815260040180806020018281038252602e815260200180614093602e913960400191505060405180910390fd5b600054610100900460ff16158015611964576000805460ff1961ff0019909116610100171660011790555b609780546001600160a01b038087166001600160a01b03199283161790925560988054868416908316179055609980549285169290911691909117905560a0805466ffffffffffffff191690556119b9612a3b565b8015610f7a576000805461ff001916905550505050565b60006119dd848484612aec565b90505b9392505050565b60a054600160301b900460ff1681565b6119ff612173565b6065546001600160a01b03908116911614611a4f576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a0805482151560ff199091168117909155604080516020810192909252808252600e828201526d656e61626c65577063436c61696d60901b6060830152516000805160206140c18339815191529181900360800190a150565b611ab1612173565b6065546001600160a01b03908116911614611b01576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b604080516370a0823160e01b8152306004820152905184916000916001600160a01b038416916370a08231916024808301926020929190829003018186803b158015611b4c57600080fd5b505afa158015611b60573d6000803e3d6000fd5b505050506040513d6020811015611b7657600080fd5b5051905082811015611b86578092505b816001600160a01b031663a9059cbb85856040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015611bdd57600080fd5b505af1158015611bf1573d6000803e3d6000fd5b505050506040513d6020811015611c0757600080fd5b50505050505050565b611c18612173565b6065546001600160a01b03908116911614611c68576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a0805482151565010000000000810265ff000000000019909216919091179091556040805160208101929092528082526018828201527f656e61626c65446973747269627574655365697a6557706300000000000000006060830152516000805160206140c18339815191529181900360800190a150565b611ce9612173565b6065546001600160a01b03908116911614611d39576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b6118988282612c97565b6114bb81609960009054906101000a90046001600160a01b03166001600160a01b031663b0772d0b6040518163ffffffff1660e01b815260040160006040518083038186803b158015611d9557600080fd5b505afa158015611da9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015611dd257600080fd5b8101908080516040519392919084600160201b821115611df157600080fd5b908301906020820185811115611e0657600080fd5b82518660208202830111600160201b82111715611e2257600080fd5b82525081516020918201928201910280838360005b83811015611e4f578181015183820152602001611e37565b50505050905001604052505050610a32565b60a0546301000000900460ff1681565b609b602052600090815260409020546001600160e01b03811690600160e01b900463ffffffff1682565b611ea3612173565b6065546001600160a01b03908116911614611ef3576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b6001600160a01b038116611f385760405162461bcd60e51b815260040180806020018281038252602681526020018061404d6026913960400191505060405180910390fd5b6065546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3606580546001600160a01b0319166001600160a01b0392909216919091179055565b6099546001600160a01b0316331480611fc55750611fb0611658565b6001600160a01b0316336001600160a01b0316145b612004576040805162461bcd60e51b81526020600482015260196024820152600080516020614101833981519152604482015290519081900360640190fd5b60a0546301000000900460ff1615610a9057611703614022565b6099546001600160a01b031633148061204f575061203a611658565b6001600160a01b0316336001600160a01b0316145b61208e576040805162461bcd60e51b81526020600482015260196024820152600080516020614101833981519152604482015290519081900360640190fd5b60a05462010000900460ff1615610a9057610d0a83612177565b6120b0612173565b6065546001600160a01b03908116911614612100576040805162461bcd60e51b81526020600482018190526024820152600080516020614073833981519152604482015290519081900360640190fd5b60a0805482151562010000810262ff000019909216919091179091556040805160208101929092528082526019828201527f656e61626c654469737472696275746552656465656d577063000000000000006060830152516000805160206140c18339815191529181900360800190a150565b3390565b6001600160a01b0381166000908152609b60209081526040808320609a9092528220548154919290914391906121bb908390600160e01b900463ffffffff16613170565b90506000811180156121cd5750600083115b15612390576000856001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561220d57600080fd5b505afa158015612221573d6000803e3d6000fd5b505050506040513d602081101561223757600080fd5b50519050600061224783866131b3565b9050612251614022565b6000831161226e5760405180602001604052806000815250612278565b61227882846131f5565b9050612282614022565b604080516020810190915288546001600160e01b031681526122a49083613232565b905060405180604001604052806122f183600001516040518060400160405280601a8152602001796e657720696e646578206578636565647320323234206269747360301b815250613257565b6001600160e01b0316815260200161232c886040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff9081169091526001600160a01b038b166000908152609b60209081526040909120835181549490920151909216600160e01b026001600160e01b039182166001600160e01b03199094169390931716919091179055506111cc92505050565b80156111cc576123c3826040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b845463ffffffff91909116600160e01b026001600160e01b039091161784555050505050565b6001600160a01b0383166000908152609b60205260409020612409614022565b50604080516020810190915281546001600160e01b0316815261242a614022565b5060408051602080820183526001600160a01b038089166000908152609d83528481209189168082528284529481208054855286519590915291529190915580511580156124785750815115155b1561248f576a0c097ce7bc90715b34b9f160241b81525b612497614022565b6124a18383613346565b90506000876001600160a01b03166370a08231886040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156124f257600080fd5b505afa158015612506573d6000803e3d6000fd5b505050506040513d602081101561251c57600080fd5b50519050600061252c828461336b565b6001600160a01b0389166000908152609f6020526040812054919250906125539083613399565b905061257489828a61256c5766038d7ea4c6800061256f565b60005b6133cf565b6001600160a01b03808b166000818152609f602090815260409182902094909455895181518781529485015280519193928e16927fbe0c0c96a4998bc3a0d03adf87afe52655ee22c978742a6fd827cbb2a7544a80929081900390910190a350505050505050505050565b6001600160a01b0382166000908152609c60209081526040808320609a909252822054815491929091439190612623908390600160e01b900463ffffffff16613170565b90506000811180156126355750600083115b156128015760006126aa876001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561267857600080fd5b505afa15801561268c573d6000803e3d6000fd5b505050506040513d60208110156126a257600080fd5b5051876134fd565b905060006126b883866131b3565b90506126c2614022565b600083116126df57604051806020016040528060008152506126e9565b6126e982846131f5565b90506126f3614022565b604080516020810190915288546001600160e01b031681526127159083613232565b9050604051806040016040528061276283600001516040518060400160405280601a8152602001796e657720696e646578206578636565647320323234206269747360301b815250613257565b6001600160e01b0316815260200161279d886040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff9081169091526001600160a01b038c166000908152609c60209081526040909120835181549490920151909216600160e01b026001600160e01b039182166001600160e01b031990941693909317169190911790555061285492505050565b801561285457612834826040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b845463ffffffff91909116600160e01b026001600160e01b039091161784555b505050505050565b6001600160a01b0384166000908152609c6020526040902061287c614022565b50604080516020810190915281546001600160e01b0316815261289d614022565b5060408051602080820183526001600160a01b03808a166000908152609e8352848120918a1680825282845294812080548552865195909152915291909155805115611c07576128eb614022565b6128f58383613346565b9050600061297b896001600160a01b03166395dd91938a6040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561294957600080fd5b505afa15801561295d573d6000803e3d6000fd5b505050506040513d602081101561297357600080fd5b5051886134fd565b90506000612989828461336b565b6001600160a01b038a166000908152609f6020526040812054919250906129b09083613399565b90506129c98a828a61256c5766038d7ea4c6800061256f565b6001600160a01b03808c166000818152609f602090815260409182902094909455895181518781529485015280519193928f16927f51c85dc0c0081306f30e8294ba3e28ddb525503774c20605841b8b161b39845b929081900390910190a35050505050505050505050565b303b1590565b600054610100900460ff1680612a545750612a54612a35565b80612a62575060005460ff16155b612a9d5760405162461bcd60e51b815260040180806020018281038252602e815260200180614093602e913960400191505060405180910390fd5b600054610100900460ff16158015612ac8576000805460ff1961ff0019909116610100171660011790555b612ad061351b565b612ad86135bb565b80156114bb576000805461ff001916905550565b6001600160a01b038084166000908152609f602052604080822054609954825163b0772d0b60e01b8152925193949193606093919092169163b0772d0b916004808201928892909190829003018186803b158015612b4957600080fd5b505afa158015612b5d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015612b8657600080fd5b8101908080516040519392919084600160201b821115612ba557600080fd5b908301906020820185811115612bba57600080fd5b82518660208202830111600160201b82111715612bd657600080fd5b82525081516020918201928201910280838360005b83811015612c03578181015183820152602001612beb565b50505050905001604052505050905060005b8151811015612c8c576000828281518110612c2c57fe5b602002602001015190506000871515600115151415612c5e57612c4f89836136b4565b9050612c5b8582613399565b94505b60018715151415612c8257612c73898361385f565b9050612c7f8582613399565b94505b5050600101612c15565b509095945050505050565b6001600160a01b0382166000908152609a60205260409020548015612d4b57612cbe614022565b6040518060200160405280856001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612d0257600080fd5b505afa158015612d16573d6000803e3d6000fd5b505050506040513d6020811015612d2c57600080fd5b505190529050612d3b84612177565b612d4584826125df565b50613114565b81156131145760995460408051633d98a1e560e01b81526001600160a01b03868116600483015291519190921691633d98a1e5916024808301926020929190829003018186803b158015612d9e57600080fd5b505afa158015612db2573d6000803e3d6000fd5b505050506040513d6020811015612dc857600080fd5b5051612e1b576040805162461bcd60e51b815260206004820152601860248201527f777063206d61726b6574206973206e6f74206c69737465640000000000000000604482015290519081900360640190fd5b609954604080516390ba830760e01b81526001600160a01b038681166004830152915191909216916390ba8307916024808301926020929190829003018186803b158015612e6857600080fd5b505afa158015612e7c573d6000803e3d6000fd5b505050506040513d6020811015612e9257600080fd5b5051612f0657609954604080516308f1c6ad60e31b81526001600160a01b038681166004830152600160248301529151919092169163478e356891604480830192600092919082900301818387803b158015612eed57600080fd5b505af1158015612f01573d6000803e3d6000fd5b505050505b6001600160a01b0383166000908152609b60205260409020546001600160e01b0316158015612f5857506001600160a01b0383166000908152609b6020526040902054600160e01b900463ffffffff16155b1561300d5760405180604001604052806a0c097ce7bc90715b34b9f160241b6001600160e01b03168152602001612fb2436040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff9081169091526001600160a01b0385166000908152609b60209081526040909120835181549490920151909216600160e01b026001600160e01b039182166001600160e01b031990941693909317169190911790555b6001600160a01b0383166000908152609c60205260409020546001600160e01b031615801561305f57506001600160a01b0383166000908152609c6020526040902054600160e01b900463ffffffff16155b156131145760405180604001604052806a0c097ce7bc90715b34b9f160241b6001600160e01b031681526020016130b9436040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff9081169091526001600160a01b0385166000908152609c60209081526040909120835181549490920151909216600160e01b026001600160e01b039182166001600160e01b031990941693909317169190911790555b818114610a90576001600160a01b0383166000818152609a6020908152604091829020859055815185815291517fff762c446cf74e816bf5f9eaeadb8596574ad13acd08e7bce6d246991645e3289281900390910190a2505050565b60006131aa8383604051806040016040528060158152602001747375627472616374696f6e20756e646572666c6f7760581b8152506139c3565b90505b92915050565b60006131aa83836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f77000000000000000000815250613a1d565b6131fd614022565b6040518060200160405280613229613223866a0c097ce7bc90715b34b9f160241b6131b3565b85613a9c565b90529392505050565b61323a614022565b604051806020016040528061322985600001518560000151613399565b600081600160e01b84106132e95760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156132ae578181015183820152602001613296565b50505050905090810190601f1680156132db5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b509192915050565b600081600160201b84106132e95760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156132ae578181015183820152602001613296565b61334e614022565b604051806020016040528061322985600001518560000151613170565b60006a0c097ce7bc90715b34b9f160241b61338a8484600001516131b3565b8161339157fe5b049392505050565b60006131aa8383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250613acf565b60008183101580156133e15750600083115b156134f557609754604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561343157600080fd5b505afa158015613445573d6000803e3d6000fd5b505050506040513d602081101561345b57600080fd5b505190508084116134f3576097546040805163a9059cbb60e01b81526001600160a01b038881166004830152602482018890529151919092169163a9059cbb9160448083019260209291908290030181600087803b1580156134bc57600080fd5b505af11580156134d0573d6000803e3d6000fd5b505050506040513d60208110156134e657600080fd5b50600092506119e0915050565b505b509092915050565b60006131aa61351484670de0b6b3a76400006131b3565b8351613a9c565b600054610100900460ff16806135345750613534612a35565b80613542575060005460ff16155b61357d5760405162461bcd60e51b815260040180806020018281038252602e815260200180614093602e913960400191505060405180910390fd5b600054610100900460ff16158015612ad8576000805460ff1961ff00199091166101001716600117905580156114bb576000805461ff001916905550565b600054610100900460ff16806135d457506135d4612a35565b806135e2575060005460ff16155b61361d5760405162461bcd60e51b815260040180806020018281038252602e815260200180614093602e913960400191505060405180910390fd5b600054610100900460ff16158015613648576000805460ff1961ff0019909116610100171660011790555b6000613652612173565b606580546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35080156114bb576000805461ff001916905550565b60a0546000906301000000900460ff1680156136d9575060a054600160201b900460ff165b15613856576136e6614022565b6040518060200160405280846001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561372a57600080fd5b505afa15801561373e573d6000803e3d6000fd5b505050506040513d602081101561375457600080fd5b505190529050613762614035565b61376c8483613b24565b9050613776614022565b50604080516020810190915281516001600160e01b03168152613797614022565b5060408051602080820183526001600160a01b038089166000908152609e8352848120918b1681529152919091205480825215613851576137d6614022565b6137e08383613346565b90506000613834886001600160a01b03166395dd91938b6040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561267857600080fd5b90506000613842828461336b565b97506131ad9650505050505050565b505050505b50600092915050565b60a054600090610100900460ff168015613881575060a05462010000900460ff165b156138565761388e614035565b61389783613d5e565b90506138a1614022565b50604080516020810190915281516001600160e01b031681526138c2614022565b5060408051602080820183526001600160a01b038088166000908152609d8352848120918a168152915291909120548082521580156139015750815115155b15613918576a0c097ce7bc90715b34b9f160241b81525b613920614022565b61392a8383613346565b90506000866001600160a01b03166370a08231896040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561397b57600080fd5b505afa15801561398f573d6000803e3d6000fd5b505050506040513d60208110156139a557600080fd5b5051905060006139b5828461336b565b96506131ad95505050505050565b60008184841115613a155760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156132ae578181015183820152602001613296565b505050900390565b6000831580613a2a575082155b15613a37575060006119e0565b83830283858281613a4457fe5b04148390613a935760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156132ae578181015183820152602001613296565b50949350505050565b60006131aa83836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250613fc0565b60008383018285821015613a935760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156132ae578181015183820152602001613296565b613b2c614035565b613b34614035565b506001600160a01b0383166000818152609c602090815260408083208151808301835290546001600160e01b038116825263ffffffff600160e01b9091048116828501908152958552609a90935290832054935190939243929091613b9b91849116613170565b9050600081118015613bad5750600083115b15613cf7576000613bf0886001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561294957600080fd5b90506000613bfe83866131b3565b9050613c08614022565b60008311613c255760405180602001604052806000815250613c2f565b613c2f82846131f5565b9050613c39614022565b604080516020810190915288516001600160e01b03168152613c5b9083613232565b90506040518060400160405280613ca883600001516040518060400160405280601a8152602001796e657720696e646578206578636565647320323234206269747360301b815250613257565b6001600160e01b03168152602001613ce3886040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff16815250975050505050613d53565b8015613d5357604051806040016040528085600001516001600160e01b03168152602001613d48846040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff16905293505b509195945050505050565b613d66614035565b613d6e614035565b506001600160a01b0382166000818152609b602090815260408083208151808301835290546001600160e01b038116825263ffffffff600160e01b9091048116828501908152958552609a90935290832054935190939243929091613dd591849116613170565b9050600081118015613de75750600083115b15613f5a576000866001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015613e2757600080fd5b505afa158015613e3b573d6000803e3d6000fd5b505050506040513d6020811015613e5157600080fd5b505190506000613e6183866131b3565b9050613e6b614022565b60008311613e885760405180602001604052806000815250613e92565b613e9282846131f5565b9050613e9c614022565b604080516020810190915288516001600160e01b03168152613ebe9083613232565b90506040518060400160405280613f0b83600001516040518060400160405280601a8152602001796e657720696e646578206578636565647320323234206269747360301b815250613257565b6001600160e01b03168152602001613f46886040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff16815250975050505050613fb6565b8015613fb657604051806040016040528085600001516001600160e01b03168152602001613fab846040518060400160405280601c81526020016000805160206140e18339815191528152506132f1565b63ffffffff16905293505b5091949350505050565b6000818361400f5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156132ae578181015183820152602001613296565b5082848161401957fe5b04949350505050565b6040518060200160405280600081525090565b60408051808201909152600080825260208201529056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a656412ad31419ea664a1cf3160aa34e0fddd4ef4471faffbea66015bfc8bd1f7a61d626c6f636b206e756d62657220657863656564732033322062697473000000006f6e6c7920636f6d7074726f6c6c6572206f72206f776e657200000000000000a2646970667358221220637a3b394969f1ee62d9ec4949add8e61867b24614decadd47f48688039c992664736f6c634300060c0033

Deployed ByteCode Sourcemap

141694:23630:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;156244:208;;;;;;;;;;;;;;;;-1:-1:-1;;;;;156244:208:0;;;;;;;;;;;;;;;-1:-1:-1;;;156244:208:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;156244:208:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;156244:208:0;;-1:-1:-1;156244:208:0;;-1:-1:-1;;;;;156244:208:0:i;:::-;;142684:68;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;142684:68:0;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;143474:42;;;:::i;:::-;;;;;;;;;;;;;;;;;;143344:35;;;:::i;158148:177::-;;;;;;;;;;;;;;;;-1:-1:-1;158148:177:0;;;;:::i;158524:183::-;;;;;;;;;;;;;;;;-1:-1:-1;158524:183:0;;;;:::i;143256:46::-;;;:::i;:::-;;;;-1:-1:-1;;;;;143256:46:0;;;;;;;;;;;;;;143311:26;;;:::i;144871:392::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;144871:392:0;;;;;;;;;;;;;;;;;;;:::i;148075:149::-;;;;;;;;;;;;;;;;-1:-1:-1;148075:149:0;;:::i;159109:189::-;;;;;;;;;;;;;;;;-1:-1:-1;159109:189:0;;;;:::i;147286:477::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;147286:477:0;;;;;;;;;;;;;;;;;;;;;;;;:::i;156790:1019::-;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;156790:1019:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;156790:1019:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;156790:1019:0;;;;;;;;-1:-1:-1;156790:1019:0;;-1:-1:-1;;;;;156790:1019:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;156790:1019:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;156790:1019:0;;-1:-1:-1;;;;156790:1019:0;;;;;-1:-1:-1;156790:1019:0;;;;;;:::i;143017:42::-;;;;;;;;;;;;;;;;-1:-1:-1;143017:42:0;-1:-1:-1;;;;;143017:42:0;;:::i;143146:49::-;;;:::i;141855:30::-;;;:::i;:::-;;;;-1:-1:-1;;;;;141855:30:0;;;;;;;;;;;;;;147771:296;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;147771:296:0;;;;;;;;:::i;143523:36::-;;;:::i;159306:382::-;;;;;;;;;;;;;;;;-1:-1:-1;159306:382:0;;;;:::i;142510:56::-;;;;;;;;;;;;;;;;-1:-1:-1;142510:56:0;-1:-1:-1;;;;;142510:56:0;;:::i;:::-;;;;-1:-1:-1;;;;;142510:56:0;;;;;;;;;;;;;;;;;;;;;;158715:198;;;;;;;;;;;;;;;;-1:-1:-1;158715:198:0;;;;:::i;58766:148::-;;;:::i;58124:79::-;;;:::i;142273:41::-;;;;;;;;;;;;;;;;-1:-1:-1;142273:41:0;-1:-1:-1;;;;;142273:41:0;;:::i;146207:528::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;146207:528:0;;;;;;;;;;;;;;;;;;;:::i;143386:37::-;;;:::i;146743:535::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;146743:535:0;;;;;;;;;;;;;;;;;;;;;;;;:::i;159696:125::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;159696:125:0;;;;;;;;:::i;142870:68::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;142870:68:0;;;;;;;;;;:::i;141785:19::-;;;:::i;141813:33::-;;;:::i;144305:558::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;144305:558:0;;;;;;;;;;;;;;;;;;;:::i;160137:178::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;160137:178:0;;;;;;;;;;;;;;;;;:::i;143566:39::-;;;:::i;157990:150::-;;;;;;;;;;;;;;;;-1:-1:-1;157990:150:0;;;;:::i;159829:300::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;159829:300:0;;;;;;;;;;;;;;;;;:::i;158921:180::-;;;;;;;;;;;;;;;;-1:-1:-1;158921:180:0;;;;:::i;157857:125::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;157857:125:0;;;;;;;;:::i;155925:105::-;;;;;;;;;;;;;;;;-1:-1:-1;155925:105:0;-1:-1:-1;;;;;155925:105:0;;:::i;143430:37::-;;;:::i;142384:56::-;;;;;;;;;;;;;;;;-1:-1:-1;142384:56:0;-1:-1:-1;;;;;142384:56:0;;:::i;59069:244::-;;;;;;;;;;;;;;;;-1:-1:-1;59069:244:0;-1:-1:-1;;;;;59069:244:0;;:::i;145679:520::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;145679:520:0;;;;;;;;;;;;;;;;;;;:::i;145271:400::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;145271:400:0;;;;;;;;;;;;;;;;;;;:::i;158333:183::-;;;;;;;;;;;;;;;;-1:-1:-1;158333:183:0;;;;:::i;156244:208::-;156348:16;;;156362:1;156348:16;;;;;;;;;156321:24;;156348:16;;;;;;;;;;;-1:-1:-1;156348:16:0;156321:43;;156388:6;156375:7;156383:1;156375:10;;;;;;;;;;;;;:19;-1:-1:-1;;;;;156375:19:0;;;-1:-1:-1;;;;;156375:19:0;;;;;156405:39;156414:7;156423;156432:4;156438:5;156405:8;:39::i;:::-;156244:208;;;:::o;142684:68::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;143474:42::-;;;-1:-1:-1;;;143474:42:0;;;;;:::o;143344:35::-;;;;;;;;;:::o;158148:177::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;158225:23:::1;:31:::0;;;::::1;;;::::0;::::1;-1:-1:-1::0;;158225:31:0;;::::1;::::0;;;::::1;::::0;;;158272:45:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;;;;-1:-1:-1;;;;;;;;;;;158272:45:0;;;;;;;::::1;158148:177:::0;:::o;158524:183::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;158603:25:::1;:33:::0;;;::::1;;::::0;;::::1;-1:-1:-1::0;;158603:33:0;;::::1;::::0;;;::::1;::::0;;;158652:47:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;;;;-1:-1:-1;;;;;;;;;;;158652:47:0;;;;;;;::::1;158524:183:::0;:::o;143256:46::-;-1:-1:-1;;;143256:46:0;:::o;143311:26::-;;;;;;:::o;144871:392::-;145027:11;;-1:-1:-1;;;;;145027:11:0;145005:10;:34;;:59;;;145057:7;:5;:7::i;:::-;-1:-1:-1;;;;;145043:21:0;:10;-1:-1:-1;;;;;145043:21:0;;145005:59;144997:97;;;;;-1:-1:-1;;;144997:97:0;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;144997:97:0;;;;;;;;;;;;;;;145109:23;;;;;;;145105:151;;;145149:28;145170:6;145149:20;:28::i;:::-;145192:52;145214:6;145222;145230:13;145192:21;:52::i;148075:149::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;148148:12:::1;::::0;:23:::1;::::0;;-1:-1:-1;;;148148:23:0;;::::1;::::0;::::1;::::0;;;;;-1:-1:-1;;;;;148148:12:0;;::::1;::::0;:18:::1;::::0;:23;;;;;:12:::1;::::0;:23;;;;;;;;:12;;:23;::::1;;::::0;::::1;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;148187:29:0::1;::::0;;;;;;;::::1;::::0;-1:-1:-1;148187:29:0;;;;::::1;::::0;;-1:-1:-1;148187:29:0::1;148075:149:::0;:::o;159109:189::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;159190:27:::1;:35:::0;;;::::1;;-1:-1:-1::0;;;159190:35:0;::::1;-1:-1:-1::0;;159190:35:0;;::::1;::::0;;;::::1;::::0;;;159241:49:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;;;;-1:-1:-1;;;;;;;;;;;159241:49:0;;;;;;;::::1;159109:189:::0;:::o;147286:477::-;147458:11;;-1:-1:-1;;;;;147458:11:0;147436:10;:34;;:59;;;147488:7;:5;:7::i;:::-;-1:-1:-1;;;;;147474:21:0;:10;-1:-1:-1;;;;;147474:21:0;;147436:59;147428:97;;;;;-1:-1:-1;;;147428:97:0;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;147428:97:0;;;;;;;;;;;;;;;147542:27;;-1:-1:-1;;;147542:27:0;;;;147538:216;;;147586:28;147607:6;147586:20;:28::i;:::-;147629:49;147651:6;147659:3;147664:13;147629:21;:49::i;:::-;147693;147715:6;147723:3;147728:13;147693:21;:49::i;:::-;147286:477;;;;:::o;156790:1019::-;156917:14;;;;156909:47;;;;;-1:-1:-1;;;156909:47:0;;;;;;;;;;;;-1:-1:-1;;;156909:47:0;;;;;;;;;;;;;;;156974:6;156969:831;156990:7;:14;156986:1;:18;156969:831;;;157026:13;157042:7;157050:1;157042:10;;;;;;;;;;;;;;;;;;;157075:11;;:43;;;-1:-1:-1;;;157075:43:0;;-1:-1:-1;;;;;157075:43:0;;;;;;;;;157042:10;;-1:-1:-1;157075:11:0;;;:26;;:43;;;;;;;;;;:11;:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;157075:43:0;157067:77;;;;;-1:-1:-1;;;157067:77:0;;;;;;;;;;;;-1:-1:-1;;;157067:77:0;;;;;;;;;;;;;;;157176:4;157163:17;;;;157159:362;;;157201:22;;:::i;:::-;157226:38;;;;;;;;157242:6;-1:-1:-1;;;;;157242:18:0;;:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;157242:20:0;157226:38;;157201:63;-1:-1:-1;157283:50:0;157312:6;157201:63;157283:20;:50::i;:::-;157357:6;157352:154;157373:7;:14;157369:1;:18;157352:154;;;157417:69;157447:6;157456:7;157464:1;157456:10;;;;;;;;;;;;;;157468:11;157481:4;157417:21;:69::i;:::-;157389:3;;157352:154;;;;157159:362;;157552:4;157539:17;;;;157535:254;;;157577:37;157606:6;157577:20;:37::i;:::-;157638:6;157633:141;157654:7;:14;157650:1;:18;157633:141;;;157698:56;157728:6;157737:7;157745:1;157737:10;;;;;;;;;;;;;;157749:4;157698:21;:56::i;:::-;157670:3;;157633:141;;;;157535:254;-1:-1:-1;157006:3:0;;156969:831;;;;156790:1019;;;;:::o;143017:42::-;;;;;;;;;;;;;:::o;143146:49::-;143187:8;143146:49;:::o;141855:30::-;;;-1:-1:-1;;;;;141855:30:0;;:::o;147771:296::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;147858:11:::1;147872:5;-1:-1:-1::0;;;;;147872:15:0::1;;147896:4;147872:30;;;;;;;;;;;;;-1:-1:-1::0;;;;;147872:30:0::1;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;::::0;::::1;;-1:-1:-1::0;147872:30:0;147935:12:::1;::::0;147913:44:::1;::::0;;-1:-1:-1;;;147913:44:0;;-1:-1:-1;;;;;147935:12:0;;::::1;147913:44;::::0;::::1;::::0;;;;;;;;;147872:30;;-1:-1:-1;147913:13:0;;::::1;::::0;::::1;::::0;:44;;;;;147872:30:::1;::::0;147913:44;;;;;;;;147935:12:::1;147913:13:::0;:44;::::1;;::::0;::::1;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;::::0;::::1;;-1:-1:-1::0;;147968:12:0::1;::::0;:31:::1;::::0;;-1:-1:-1;;;147968:31:0;;::::1;::::0;::::1;::::0;;;;;;;;;;;-1:-1:-1;;;;;147968:12:0;;::::1;::::0;:18:::1;::::0;:31;;;;;:12:::1;::::0;:31;;;;;;;;:12;;:31;::::1;;::::0;::::1;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;148015:44:0::1;::::0;;-1:-1:-1;;;;;148015:44:0;::::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;;;;;::::1;::::0;-1:-1:-1;148015:44:0;;;;;;;-1:-1:-1;148015:44:0::1;58406:1;147771:296:::0;;:::o;143523:36::-;;;;;;;;;:::o;159306:382::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;159369:34:::1;159397:5;159369:27;:34::i;:::-;159414:36;159444:5;159414:29;:36::i;:::-;159461;159491:5;159461:29;:36::i;:::-;159508:41;159543:5;159508:34;:41::i;:::-;159560:35;159589:5;159560:28;:35::i;:::-;159606:38;159638:5;159606:31;:38::i;:::-;159655:25;159674:5;159655:18;:25::i;:::-;159306:382:::0;:::o;142510:56::-;;;;;;;;;;;;-1:-1:-1;;;;;142510:56:0;;;-1:-1:-1;;;142510:56:0;;;;;:::o;158715:198::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;158799:30:::1;:38:::0;;;::::1;;-1:-1:-1::0;;;158799:38:0;::::1;-1:-1:-1::0;;158799:38:0;;::::1;::::0;;;::::1;::::0;;;158853:52:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;;;;-1:-1:-1;;;;;;;;;;;158853:52:0;;;;;;;::::1;158715:198:::0;:::o;58766:148::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;58857:6:::1;::::0;58836:40:::1;::::0;58873:1:::1;::::0;-1:-1:-1;;;;;58857:6:0::1;::::0;58836:40:::1;::::0;58873:1;;58836:40:::1;58887:6;:19:::0;;-1:-1:-1;;;;;;58887:19:0::1;::::0;;58766:148::o;58124:79::-;58189:6;;-1:-1:-1;;;;;58189:6:0;58124:79;:::o;142273:41::-;;;;;;;;;;;;;:::o;146207:528::-;146374:11;;-1:-1:-1;;;;;146374:11:0;146352:10;:34;;:59;;;146404:7;:5;:7::i;:::-;-1:-1:-1;;;;;146390:21:0;:10;-1:-1:-1;;;;;146390:21:0;;146352:59;146344:97;;;;;-1:-1:-1;;;146344:97:0;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;146344:97:0;;;;;;;;;;;;;;;146458:30;;-1:-1:-1;;;146458:30:0;;;;146454:272;;;146505:22;;:::i;:::-;146530:46;;;;;;;;146553:6;-1:-1:-1;;;;;146546:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;146546:28:0;146530:46;;146505:71;-1:-1:-1;146591:41:0;146612:6;146505:71;146591:20;:41::i;:::-;146647:67;146669:6;146677:8;146687:11;146700:13;146647:21;:67::i;143386:37::-;;;;;;;;;:::o;146743:535::-;146934:11;;-1:-1:-1;;;;;146934:11:0;146912:10;:34;;:59;;;146964:7;:5;:7::i;:::-;-1:-1:-1;;;;;146950:21:0;:10;-1:-1:-1;;;;;146950:21:0;;146912:59;146904:97;;;;;-1:-1:-1;;;146904:97:0;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;146904:97:0;;;;;;;;;;;;;;;147018:24;;;;;;;147014:255;;;147059:38;147080:16;147059:20;:38::i;159696:125::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;159794:5:::1;::::0;159771:42:::1;::::0;-1:-1:-1;;;;;159794:5:0::1;159802:2:::0;159806:6;159771:14:::1;:42::i;:::-;159696:125:::0;;:::o;142870:68::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;141785:19::-;;;-1:-1:-1;;;;;141785:19:0;;:::o;141813:33::-;;;-1:-1:-1;;;;;141813:33:0;;:::o;144305:558::-;54588:12;;;;;;;;:31;;;54604:15;:13;:15::i;:::-;54588:47;;;-1:-1:-1;54624:11:0;;;;54623:12;54588:47;54580:106;;;;-1:-1:-1;;;54580:106:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;54695:19;54718:12;;;;;;54717:13;54737:83;;;;54766:12;:19;;-1:-1:-1;;;;54766:19:0;;;;;54794:18;54781:4;54794:18;;;54737:83;144427:5:::1;:14:::0;;-1:-1:-1;;;;;144427:14:0;;::::1;-1:-1:-1::0;;;;;;144427:14:0;;::::1;;::::0;;;144452:12:::1;:28:::0;;;;::::1;::::0;;::::1;;::::0;;144491:11:::1;:26:::0;;;;::::1;::::0;;;::::1;::::0;;;::::1;::::0;;144530:14:::1;:22:::0;;-1:-1:-1;;144785:35:0;;;144833:22:::1;:20;:22::i;:::-;54842:14:::0;54838:57;;;54882:5;54867:20;;-1:-1:-1;;54867:20:0;;;144305:558;;;;:::o;160137:178::-;160233:7;160259:48;160278:6;160286:9;160297;160259:18;:48::i;:::-;160252:55;;160137:178;;;;;;:::o;143566:39::-;;;-1:-1:-1;;;143566:39:0;;;;;:::o;157990:150::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;158058:14:::1;:22:::0;;;::::1;;-1:-1:-1::0;;158058:22:0;;::::1;::::0;::::1;::::0;;;158096:36:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;-1:-1:-1;;;158096:36:0;;;;;-1:-1:-1;;;;;;;;;;;158096:36:0;;;;;;;::::1;157990:150:::0;:::o;159829:300::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;159977:30:::1;::::0;;-1:-1:-1;;;159977:30:0;;160001:4:::1;159977:30;::::0;::::1;::::0;;;159943:5;;159921:12:::1;::::0;-1:-1:-1;;;;;159977:15:0;::::1;::::0;::::1;::::0;:30;;;;;::::1;::::0;;;;;;;;:15;:30;::::1;;::::0;::::1;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;::::0;::::1;;-1:-1:-1::0;159977:30:0;;-1:-1:-1;160022:16:0;;::::1;160018:65;;;160064:7;160055:16;;160018:65;160095:5;-1:-1:-1::0;;;;;160095:14:0::1;;160110:2;160114:6;160095:26;;;;;;;;;;;;;-1:-1:-1::0;;;;;160095:26:0::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;::::0;::::1;;-1:-1:-1::0;;;;;;;159829:300:0:o;158921:180::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;158999:24:::1;:32:::0;;;::::1;;::::0;;::::1;-1:-1:-1::0;;158999:32:0;;::::1;::::0;;;::::1;::::0;;;159047:46:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;;;;-1:-1:-1;;;;;;;;;;;159047:46:0;;;;;;;::::1;158921:180:::0;:::o;157857:125::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;157937:37:::1;157957:6;157965:8;157937:19;:37::i;155925:105::-:0;155977:45;155986:6;155994:11;;;;;;;;;-1:-1:-1;;;;;155994:11:0;-1:-1:-1;;;;;155994:25:0;;:27;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;155994:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;155994:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;155994:27:0;;;;;;;;;;;;-1:-1:-1;155994:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;155977:8;:45::i;143430:37::-;;;;;;;;;:::o;142384:56::-;;;;;;;;;;;;-1:-1:-1;;;;;142384:56:0;;;-1:-1:-1;;;142384:56:0;;;;;:::o;59069:244::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;-1:-1:-1;;;;;59158:22:0;::::1;59150:73;;;;-1:-1:-1::0;;;59150:73:0::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;59260:6;::::0;59239:38:::1;::::0;-1:-1:-1;;;;;59239:38:0;;::::1;::::0;59260:6:::1;::::0;59239:38:::1;::::0;59260:6:::1;::::0;59239:38:::1;59288:6;:17:::0;;-1:-1:-1;;;;;;59288:17:0::1;-1:-1:-1::0;;;;;59288:17:0;;;::::1;::::0;;;::::1;::::0;;59069:244::o;145679:520::-;145841:11;;-1:-1:-1;;;;;145841:11:0;145819:10;:34;;:59;;;145871:7;:5;:7::i;:::-;-1:-1:-1;;;;;145857:21:0;:10;-1:-1:-1;;;;;145857:21:0;;145819:59;145811:97;;;;;-1:-1:-1;;;145811:97:0;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;145811:97:0;;;;;;;;;;;;;;;145925:25;;;;;;;145921:267;;;145967:22;;:::i;145271:400::-;145431:11;;-1:-1:-1;;;;;145431:11:0;145409:10;:34;;:59;;;145461:7;:5;:7::i;:::-;-1:-1:-1;;;;;145447:21:0;:10;-1:-1:-1;;;;;145447:21:0;;145409:59;145401:97;;;;;-1:-1:-1;;;145401:97:0;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;145401:97:0;;;;;;;;;;;;;;;145513:25;;;;;;;145509:155;;;145555:28;145576:6;145555:20;:28::i;158333:183::-;58346:12;:10;:12::i;:::-;58336:6;;-1:-1:-1;;;;;58336:6:0;;;:22;;;58328:67;;;;;-1:-1:-1;;;58328:67:0;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;58328:67:0;;;;;;;;;;;;;;;158412:25:::1;:33:::0;;;::::1;;::::0;;::::1;-1:-1:-1::0;;158412:33:0;;::::1;::::0;;;::::1;::::0;;;158461:47:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;;;;-1:-1:-1;;;;;;;;;;;158461:47:0;;;;;;;::::1;158333:183:::0;:::o;56511:106::-;56599:10;56511:106;:::o;149992:1031::-;-1:-1:-1;;;;;150095:22:0;;150058:34;150095:22;;;:14;:22;;;;;;;;150147:9;:17;;;;;;150259;;150095:22;;150147:17;;150194:12;;150058:34;150236:42;;150194:12;;-1:-1:-1;;;150259:17:0;;;;150236:4;:42::i;:::-;150217:61;;150307:1;150293:11;:15;:34;;;;;150326:1;150312:11;:15;150293:34;150289:727;;;150344:17;150371:6;-1:-1:-1;;;;;150364:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;150364:28:0;;-1:-1:-1;150407:15:0;150425:30;150430:11;150443;150425:4;:30::i;:::-;150407:48;;150470:19;;:::i;:::-;150507:1;150492:12;:16;:78;;150548:22;;;;;;;;150567:1;150548:22;;;150492:78;;;150511:34;150520:10;150532:12;150511:8;:34::i;:::-;150470:100;;150585:19;;:::i;:::-;150612:38;;;;;;;;;150631:17;;-1:-1:-1;;;;;150631:17:0;150612:38;;150607:51;;150652:5;150607:4;:51::i;:::-;150585:73;;150698:181;;;;;;;;150736:53;150744:5;:14;;;150736:53;;;;;;;;;;;;;-1:-1:-1;;;150736:53:0;;;:7;:53::i;:::-;-1:-1:-1;;;;;150698:181:0;;;;;150812:51;150819:11;150812:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;150812:51:0;;;:6;:51::i;:::-;150698:181;;;;;;;-1:-1:-1;;;;;150673:22:0;;;;;;:14;:22;;;;;;;;:206;;;;;;;;;;;;-1:-1:-1;;;150673:206:0;-1:-1:-1;;;;;150673:206:0;;;-1:-1:-1;;;;;;150673:206:0;;;;;;;;;;;;;;-1:-1:-1;150289:727:0;;-1:-1:-1;;;150289:727:0;;150901:15;;150897:119;;150953:51;150960:11;150953:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;150953:51:0;;;:6;:51::i;:::-;150933:71;;;;;;;-1:-1:-1;;;150933:71:0;-1:-1:-1;;;;;150933:71:0;;;;;;149992:1031;;;;;:::o;152522:1048::-;-1:-1:-1;;;;;152664:22:0;;152627:34;152664:22;;;:14;:22;;;;;152697:25;;:::i;:::-;-1:-1:-1;152725:38:0;;;;;;;;;152744:17;;-1:-1:-1;;;;;152744:17:0;152725:38;;152774:27;;:::i;:::-;-1:-1:-1;152804:55:0;;;;;;;;;-1:-1:-1;;;;;152823:24:0;;;-1:-1:-1;152823:24:0;;;:16;:24;;;;;:34;;;;;;;;;;;;;;152804:55;;152907:20;;152870:34;;;;;;:57;;;;152944:22;;:27;:55;;;;-1:-1:-1;152975:20:0;;:24;;152944:55;152940:128;;;-1:-1:-1;;;153016:40:0;;152940:128;153080:24;;:::i;:::-;153107:32;153112:11;153125:13;153107:4;:32::i;:::-;153080:59;;153150:19;153179:6;-1:-1:-1;;;;;153172:24:0;;153197:8;153172:34;;;;;;;;;;;;;-1:-1:-1;;;;;153172:34:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;153172:34:0;;-1:-1:-1;153217:18:0;153238:32;153172:34;153259:10;153238:4;:32::i;:::-;-1:-1:-1;;;;;153309:20:0;;153281;153309;;;:10;:20;;;;;;153217:53;;-1:-1:-1;153281:20:0;153304:41;;153217:53;153304:4;:41::i;:::-;153281:64;;153379:82;153396:8;153406:15;153423:13;:37;;143187:8;153423:37;;;153439:1;153423:37;153379:16;:82::i;:::-;-1:-1:-1;;;;;153356:20:0;;;;;;;:10;:20;;;;;;;;;:105;;;;153541:20;;153477:85;;;;;;;;;;;153356:20;;153477:85;;;;;;;;;;;;;;;152522:1048;;;;;;;;;;:::o;151181:1087::-;-1:-1:-1;;;;;151314:22:0;;151277:34;151314:22;;;:14;:22;;;;;;;;151366:9;:17;;;;;;151478;;151314:22;;151366:17;;151413:12;;151277:34;151455:42;;151413:12;;-1:-1:-1;;;151478:17:0;;;;151455:4;:42::i;:::-;151436:61;;151526:1;151512:11;:15;:34;;;;;151545:1;151531:11;:15;151512:34;151508:753;;;151563:17;151583:54;151595:6;-1:-1:-1;;;;;151588:27:0;;:29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;151588:29:0;151619:17;151583:4;:54::i;:::-;151563:74;;151652:15;151670:30;151675:11;151688;151670:4;:30::i;:::-;151652:48;;151715:19;;:::i;:::-;151752:1;151737:12;:16;:78;;151793:22;;;;;;;;151812:1;151793:22;;;151737:78;;;151756:34;151765:10;151777:12;151756:8;:34::i;:::-;151715:100;;151830:19;;:::i;:::-;151857:38;;;;;;;;;151876:17;;-1:-1:-1;;;;;151876:17:0;151857:38;;151852:51;;151897:5;151852:4;:51::i;:::-;151830:73;;151943:181;;;;;;;;151981:53;151989:5;:14;;;151981:53;;;;;;;;;;;;;-1:-1:-1;;;151981:53:0;;;:7;:53::i;:::-;-1:-1:-1;;;;;151943:181:0;;;;;152057:51;152064:11;152057:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;152057:51:0;;;:6;:51::i;:::-;151943:181;;;;;;;-1:-1:-1;;;;;151918:22:0;;;;;;:14;:22;;;;;;;;:206;;;;;;;;;;;;-1:-1:-1;;;151918:206:0;-1:-1:-1;;;;;151918:206:0;;;-1:-1:-1;;;;;;151918:206:0;;;;;;;;;;;;;;-1:-1:-1;151508:753:0;;-1:-1:-1;;;151508:753:0;;152146:15;;152142:119;;152198:51;152205:11;152198:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;152198:51:0;;;:6;:51::i;:::-;152178:71;;;;;;;-1:-1:-1;;;152178:71:0;-1:-1:-1;;;;;152178:71:0;;;;;;152142:119;151181:1087;;;;;;:::o;153927:1051::-;-1:-1:-1;;;;;154099:22:0;;154062:34;154099:22;;;:14;:22;;;;;154132:25;;:::i;:::-;-1:-1:-1;154160:38:0;;;;;;;;;154179:17;;-1:-1:-1;;;;;154179:17:0;154160:38;;154209:27;;:::i;:::-;-1:-1:-1;154239:55:0;;;;;;;;;-1:-1:-1;;;;;154258:24:0;;;-1:-1:-1;154258:24:0;;;:16;:24;;;;;:34;;;;;;;;;;;;;;154239:55;;154342:20;;154305:34;;;;;;:57;;;;154379:22;;:26;154375:596;;154422:24;;:::i;:::-;154449:32;154454:11;154467:13;154449:4;:32::i;:::-;154422:59;;154496:19;154518:69;154530:6;-1:-1:-1;;;;;154523:34:0;;154558:8;154523:44;;;;;;;;;;;;;-1:-1:-1;;;;;154523:44:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;154523:44:0;154569:17;154518:4;:69::i;:::-;154496:91;;154602:18;154623:32;154628:14;154644:10;154623:4;:32::i;:::-;-1:-1:-1;;;;;154698:20:0;;154670;154698;;;:10;:20;;;;;;154602:53;;-1:-1:-1;154670:20:0;154693:41;;154602:53;154693:4;:41::i;:::-;154670:64;;154772:82;154789:8;154799:15;154816:13;:37;;143187:8;154816:37;;154772:82;-1:-1:-1;;;;;154749:20:0;;;;;;;:10;:20;;;;;;;;;:105;;;;154938:20;;154874:85;;;;;;;;;;;154749:20;;154874:85;;;;;;;;;;;;;;;154375:596;;;;153927:1051;;;;;;;:::o;54989:508::-;55406:4;55452:17;55484:7;54989:508;:::o;57702:129::-;54588:12;;;;;;;;:31;;;54604:15;:13;:15::i;:::-;54588:47;;;-1:-1:-1;54624:11:0;;;;54623:12;54588:47;54580:106;;;;-1:-1:-1;;;54580:106:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;54695:19;54718:12;;;;;;54717:13;54737:83;;;;54766:12;:19;;-1:-1:-1;;;;54766:19:0;;;;;54794:18;54781:4;54794:18;;;54737:83;57760:26:::1;:24;:26::i;:::-;57797;:24;:26::i;:::-;54842:14:::0;54838:57;;;54882:5;54867:20;;-1:-1:-1;;54867:20:0;;;57702:129;:::o;160323:747::-;-1:-1:-1;;;;;160464:18:0;;;160422:7;160464:18;;;:10;:18;;;;;;;160521:11;;:27;;-1:-1:-1;;;160521:27:0;;;;160422:7;;160464:18;;160495:23;;160521:11;;;;;:25;;:27;;;;;160422:7;;160521:27;;;;;;;;:11;:27;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;160521:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;160521:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;160521:27:0;;;;;;;;;;;;-1:-1:-1;160521:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;160495:53;;160564:6;160559:474;160580:7;:14;160576:1;:18;160559:474;;;160616:14;160641:7;160649:1;160641:10;;;;;;;;;;;;;;160616:36;;160667:8;160698:9;:17;;160711:4;160698:17;;;160694:157;;;160742:40;160767:6;160775;160742:24;:40::i;:::-;160736:46;;160814:21;160819:10;160831:3;160814:4;:21::i;:::-;160801:34;;160694:157;160882:4;160869:17;;;;160865:157;;;160913:40;160938:6;160946;160913:24;:40::i;:::-;160907:46;;160985:21;160990:10;161002:3;160985:4;:21::i;:::-;160972:34;;160865:157;-1:-1:-1;;160596:3:0;;160559:474;;;-1:-1:-1;161052:10:0;;160323:747;-1:-1:-1;;;;;160323:747:0:o;148232:1602::-;-1:-1:-1;;;;;148334:26:0;;148311:20;148334:26;;;:9;:26;;;;;;148375:20;;148371:1292;;148505:22;;:::i;:::-;148530:38;;;;;;;;148546:6;-1:-1:-1;;;;;148546:18:0;;:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;148546:20:0;148530:38;;148505:63;-1:-1:-1;148583:37:0;148612:6;148583:20;:37::i;:::-;148635:50;148664:6;148673:11;148635:20;:50::i;:::-;148371:1292;;;;148707:13;;148703:960;;148747:11;;:43;;;-1:-1:-1;;;148747:43:0;;-1:-1:-1;;;;;148747:43:0;;;;;;;;;:11;;;;;:26;;:43;;;;;;;;;;;;;;:11;:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;148747:43:0;148739:80;;;;;-1:-1:-1;;;148739:80:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;148840:11;;:43;;;-1:-1:-1;;;148840:43:0;;-1:-1:-1;;;;;148840:43:0;;;;;;;;;:11;;;;;:26;;:43;;;;;;;;;;;;;;:11;:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;148840:43:0;148836:144;;148913:11;;:51;;;-1:-1:-1;;;148913:51:0;;-1:-1:-1;;;;;148913:51:0;;;;;;;:11;:51;;;;;;:11;;;;;:28;;:51;;;;;:11;;:51;;;;;;;:11;;:51;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;148836:144;-1:-1:-1;;;;;149000:31:0;;;;;;:14;:31;;;;;:37;-1:-1:-1;;;;;149000:37:0;:42;:88;;;;-1:-1:-1;;;;;;149046:31:0;;;;;;:14;:31;;;;;:37;-1:-1:-1;;;149046:37:0;;;;:42;149000:88;148996:319;;;149143:156;;;;;;;;-1:-1:-1;;;;;;;;149143:156:0;;;;;149227:52;149234:12;149227:52;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;149227:52:0;;;:6;:52::i;:::-;149143:156;;;;;;;-1:-1:-1;;;;;149109:31:0;;;;;;:14;:31;;;;;;;;:190;;;;;;;;;;;;-1:-1:-1;;;149109:190:0;-1:-1:-1;;;;;149109:190:0;;;-1:-1:-1;;;;;;149109:190:0;;;;;;;;;;;;;;148996:319;-1:-1:-1;;;;;149335:31:0;;;;;;:14;:31;;;;;:37;-1:-1:-1;;;;;149335:37:0;:42;:88;;;;-1:-1:-1;;;;;;149381:31:0;;;;;;:14;:31;;;;;:37;-1:-1:-1;;;149381:37:0;;;;:42;149335:88;149331:319;;;149478:156;;;;;;;;-1:-1:-1;;;;;;;;149478:156:0;;;;;149562:52;149569:12;149562:52;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;149562:52:0;;;:6;:52::i;:::-;149478:156;;;;;;;-1:-1:-1;;;;;149444:31:0;;;;;;:14;:31;;;;;;;;:190;;;;;;;;;;;;-1:-1:-1;;;149444:190:0;-1:-1:-1;;;;;149444:190:0;;;-1:-1:-1;;;;;;149444:190:0;;;;;;;;;;;;;;149331:319;149698:8;149679:15;:27;149675:150;;-1:-1:-1;;;;;149723:26:0;;;;;;:9;:26;;;;;;;;;:37;;;149780:33;;;;;;;;;;;;;;;;;148232:1602;;;:::o;15222:120::-;15275:4;15299:35;15304:1;15307;15299:35;;;;;;;;;;;;;-1:-1:-1;;;15299:35:0;;;:4;:35::i;:::-;15292:42;;15222:120;;;;;:::o;16420:122::-;16473:4;16497:37;16502:1;16505;16497:37;;;;;;;;;;;;;;;;;:4;:37::i;18018:147::-;18075:13;;:::i;:::-;18108:49;;;;;;;;18126:29;18131:20;18136:1;-1:-1:-1;;;18131:4:0;:20::i;:::-;18153:1;18126:4;:29::i;:::-;18108:49;;18101:56;18018:147;-1:-1:-1;;;18018:147:0:o;14419:160::-;14490:13;;:::i;:::-;14523:48;;;;;;;;14541:28;14546:1;:10;;;14558:1;:10;;;14541:4;:28::i;13921:165::-;13997:7;14037:12;-1:-1:-1;;;14025:10:0;;14017:33;;;;-1:-1:-1;;;14017:33:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;14076:1:0;;13921:165;-1:-1:-1;;13921:165:0:o;14094:161::-;14169:6;14207:12;-1:-1:-1;;;14196:9:0;;14188:32;;;;-1:-1:-1;;;14188:32:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;15054:160;15125:13;;:::i;:::-;15158:48;;;;;;;;15176:28;15181:1;:10;;;15193:1;:10;;;15176:4;:28::i;16285:127::-;16347:4;-1:-1:-1;;;16371:19:0;16376:1;16379;:10;;;16371:4;:19::i;:::-;:33;;;;;;;16285:127;-1:-1:-1;;;16285:127:0:o;14587:116::-;14640:4;14664:31;14669:1;14672;14664:31;;;;;;;;;;;;;-1:-1:-1;;;14664:31:0;;;:4;:31::i;155366:415::-;155458:4;155496:9;155481:11;:24;;:43;;;;;155523:1;155509:11;:15;155481:43;155477:268;;;155561:5;;:30;;;-1:-1:-1;;;155561:30:0;;155585:4;155561:30;;;;;;155541:17;;-1:-1:-1;;;;;155561:5:0;;:15;;:30;;;;;;;;;;;;;;:5;:30;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;155561:30:0;;-1:-1:-1;155610:27:0;;;155606:128;;155658:5;;:33;;;-1:-1:-1;;;155658:33:0;;-1:-1:-1;;;;;155658:33:0;;;;;;;;;;;;;;;:5;;;;;:14;;:33;;;;;;;;;;;;;;:5;;:33;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;155717:1:0;;-1:-1:-1;155710:8:0;;-1:-1:-1;;155710:8:0;155606:128;155477:268;;-1:-1:-1;155762:11:0;;155366:415;-1:-1:-1;;155366:415:0:o;17121:126::-;17180:4;17204:35;17209:17;17214:1;5886:4;17209;:17::i;:::-;17228:10;;17204:4;:35::i;56432:69::-;54588:12;;;;;;;;:31;;;54604:15;:13;:15::i;:::-;54588:47;;;-1:-1:-1;54624:11:0;;;;54623:12;54588:47;54580:106;;;;-1:-1:-1;;;54580:106:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;54695:19;54718:12;;;;;;54717:13;54737:83;;;;54766:12;:19;;-1:-1:-1;;;;54766:19:0;;;;;54794:18;54781:4;54794:18;;;54842:14;54838:57;;;54882:5;54867:20;;-1:-1:-1;;54867:20:0;;;56432:69;:::o;57839:202::-;54588:12;;;;;;;;:31;;;54604:15;:13;:15::i;:::-;54588:47;;;-1:-1:-1;54624:11:0;;;;54623:12;54588:47;54580:106;;;;-1:-1:-1;;;54580:106:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;54695:19;54718:12;;;;;;54717:13;54737:83;;;;54766:12;:19;;-1:-1:-1;;;;54766:19:0;;;;;54794:18;54781:4;54794:18;;;54737:83;57911:17:::1;57931:12;:10;:12::i;:::-;57954:6;:18:::0;;-1:-1:-1;;;;;;57954:18:0::1;-1:-1:-1::0;;;;;57954:18:0;::::1;::::0;;::::1;::::0;;;57988:43:::1;::::0;57954:18;;-1:-1:-1;57954:18:0;-1:-1:-1;;57988:43:0::1;::::0;-1:-1:-1;;57988:43:0::1;54828:1;54842:14:::0;54838:57;;;54882:5;54867:20;;-1:-1:-1;;54867:20:0;;;57839:202;:::o;161078:948::-;161192:25;;161169:7;;161192:25;;;;;:59;;;;-1:-1:-1;161221:30:0;;-1:-1:-1;;;161221:30:0;;;;161192:59;161188:812;;;161268:28;;:::i;:::-;161299:46;;;;;;;;161322:6;-1:-1:-1;;;;;161315:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;161315:28:0;161299:46;;161268:77;-1:-1:-1;161360:33:0;;:::i;:::-;161396:48;161418:6;161426:17;161396:21;:48::i;:::-;161360:84;;161461:25;;:::i;:::-;-1:-1:-1;161489:38:0;;;;;;;;;161508:17;;-1:-1:-1;;;;;161489:38:0;;;161542:27;;:::i;:::-;-1:-1:-1;161572:55:0;;;;;;;;;-1:-1:-1;;;;;161591:24:0;;;-1:-1:-1;161591:24:0;;;:16;:24;;;;;:34;;;;;;;;;;;;161572:55;;;161646:26;161642:347;;161693:24;;:::i;:::-;161720:32;161725:11;161738:13;161720:4;:32::i;:::-;161693:59;;161771:19;161793:69;161805:6;-1:-1:-1;;;;;161798:34:0;;161833:8;161798:44;;;;;;;;;;;;;-1:-1:-1;;;;;161798:44:0;;;;;;;;;;;;;;;;;;;;;;;;;;161793:69;161771:91;;161881:18;161902:32;161907:14;161923:10;161902:4;:32::i;:::-;161881:53;-1:-1:-1;161953:20:0;;-1:-1:-1;;;;;;;161953:20:0;161642:347;161188:812;;;;;-1:-1:-1;162017:1:0;161078:948;;;;:::o;163271:865::-;163385:23;;163362:7;;163385:23;;;;;:52;;;;-1:-1:-1;163412:25:0;;;;;;;163385:52;163381:729;;;163454:33;;:::i;:::-;163490:29;163512:6;163490:21;:29::i;:::-;163454:65;;163534:25;;:::i;:::-;-1:-1:-1;163562:38:0;;;;;;;;;163581:17;;-1:-1:-1;;;;;163562:38:0;;;163615:27;;:::i;:::-;-1:-1:-1;163645:55:0;;;;;;;;;-1:-1:-1;;;;;163664:24:0;;;-1:-1:-1;163664:24:0;;;:16;:24;;;;;:34;;;;;;;;;;;;163645:55;;;163719:27;:55;;;;-1:-1:-1;163750:20:0;;:24;;163719:55;163715:136;;;-1:-1:-1;;;163795:40:0;;163715:136;163865:24;;:::i;:::-;163892:32;163897:11;163910:13;163892:4;:32::i;:::-;163865:59;;163939:19;163968:6;-1:-1:-1;;;;;163961:24:0;;163986:8;163961:34;;;;;;;;;;;;;-1:-1:-1;;;;;163961:34:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;163961:34:0;;-1:-1:-1;164010:18:0;164031:32;163961:34;164052:10;164031:4;:32::i;:::-;164010:53;-1:-1:-1;164078:20:0;;-1:-1:-1;;;;;;164078:20:0;15350:158;15431:4;15464:12;15456:6;;;;15448:29;;;;-1:-1:-1;;;15448:29:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;15495:5:0;;;15350:158::o;16550:250::-;16631:4;16652:6;;;:16;;-1:-1:-1;16662:6:0;;16652:16;16648:57;;;-1:-1:-1;16692:1:0;16685:8;;16648:57;16724:5;;;16728:1;16724;:5;:1;16748:5;;;;;:10;16760:12;16740:33;;;;;-1:-1:-1;;;16740:33:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;16791:1:0;16550:250;-1:-1:-1;;;;16550:250:0:o;17732:113::-;17785:4;17809:28;17814:1;17817;17809:28;;;;;;;;;;;;;-1:-1:-1;;;17809:28:0;;;:4;:28::i;14711:179::-;14792:4;14818:5;;;14850:12;14842:6;;;;14834:29;;;;-1:-1:-1;;;14834:29:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;162034:1229;162134:21;;:::i;:::-;162167:33;;:::i;:::-;-1:-1:-1;;;;;;162203:22:0;;;;;;:14;:22;;;;;;;;162167:58;;;;;;;;;-1:-1:-1;;;;;162167:58:0;;;;;-1:-1:-1;;;162167:58:0;;;;;;;;;;;162255:17;;;:9;:17;;;;;;;162367;;162167:58;;162255:17;162302:12;;162203:22;;162344:42;;162302:12;;162362:23;162344:4;:42::i;:::-;162325:61;;162415:1;162401:11;:15;:34;;;;;162434:1;162420:11;:15;162401:34;162397:830;;;162452:17;162472:54;162484:6;-1:-1:-1;;;;;162477:27:0;;:29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;162472:54;162452:74;;162541:15;162559:30;162564:11;162577;162559:4;:30::i;:::-;162541:48;;162604:19;;:::i;:::-;162641:1;162626:12;:16;:78;;162682:22;;;;;;;;162701:1;162682:22;;;162626:78;;;162645:34;162654:10;162666:12;162645:8;:34::i;:::-;162604:100;;162719:19;;:::i;:::-;162746:38;;;;;;;;;162765:17;;-1:-1:-1;;;;;162746:38:0;;;162741:51;;162786:5;162741:4;:51::i;:::-;162719:73;;162821:181;;;;;;;;162859:53;162867:5;:14;;;162859:53;;;;;;;;;;;;;-1:-1:-1;;;162859:53:0;;;:7;:53::i;:::-;-1:-1:-1;;;;;162821:181:0;;;;;162935:51;162942:11;162935:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;162935:51:0;;;:6;:51::i;:::-;162821:181;;;;;162807:195;;162397:830;;;;;;;163024:15;;163020:207;;163070:145;;;;;;;;163108:11;:17;;;-1:-1:-1;;;;;163070:145:0;;;;;163148:51;163155:11;163148:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;163148:51:0;;;:6;:51::i;:::-;163070:145;;;;163056:159;-1:-1:-1;163020:207:0;-1:-1:-1;163244:11:0;;162034:1229;-1:-1:-1;;;;;162034:1229:0:o;164144:1175::-;164214:21;;:::i;:::-;164247:33;;:::i;:::-;-1:-1:-1;;;;;;164283:22:0;;;;;;:14;:22;;;;;;;;164247:58;;;;;;;;;-1:-1:-1;;;;;164247:58:0;;;;;-1:-1:-1;;;164247:58:0;;;;;;;;;;;164335:17;;;:9;:17;;;;;;;164447;;164247:58;;164335:17;164382:12;;164283:22;;164424:42;;164382:12;;164442:23;164424:4;:42::i;:::-;164405:61;;164497:1;164483:11;:15;:34;;;;;164516:1;164502:11;:15;164483:34;164479:804;;;164534:17;164561:6;-1:-1:-1;;;;;164554:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;164554:28:0;;-1:-1:-1;164597:15:0;164615:30;164620:11;164633;164615:4;:30::i;:::-;164597:48;;164660:19;;:::i;:::-;164697:1;164682:12;:16;:78;;164738:22;;;;;;;;164757:1;164738:22;;;164682:78;;;164701:34;164710:10;164722:12;164701:8;:34::i;:::-;164660:100;;164775:19;;:::i;:::-;164802:38;;;;;;;;;164821:17;;-1:-1:-1;;;;;164802:38:0;;;164797:51;;164842:5;164797:4;:51::i;:::-;164775:73;;164877:181;;;;;;;;164915:53;164923:5;:14;;;164915:53;;;;;;;;;;;;;-1:-1:-1;;;164915:53:0;;;:7;:53::i;:::-;-1:-1:-1;;;;;164877:181:0;;;;;164991:51;164998:11;164991:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;164991:51:0;;;:6;:51::i;:::-;164877:181;;;;;164863:195;;164479:804;;;;;;;165080:15;;165076:207;;165126:145;;;;;;;;165164:11;:17;;;-1:-1:-1;;;;;165126:145:0;;;;;165204:51;165211:11;165204:51;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;165204:51:0;;;:6;:51::i;:::-;165126:145;;;;165112:159;-1:-1:-1;165076:207:0;-1:-1:-1;165300:11:0;;164144:1175;-1:-1:-1;;;;164144:1175:0:o;17853:157::-;17934:4;17966:12;17959:5;17951:28;;;;-1:-1:-1;;;17951:28:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;18001:1;17997;:5;;;;;;;17853:157;-1:-1:-1;;;;17853:157:0:o;-1:-1:-1:-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;:::o

Swarm Source

ipfs://637a3b394969f1ee62d9ec4949add8e61867b24614decadd47f48688039c9926
Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading