ETH Price: $2,736.82 (+1.89%)

Contract

0x8DC1750B1fe69e940f570c021d658C14D8041834
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Refresh170074792023-04-09 1:22:23683 days ago1681003343IN
0x8DC1750B...4D8041834
0 ETH0.0129748617.11838231
Refresh170074192023-04-09 1:10:23683 days ago1681002623IN
0x8DC1750B...4D8041834
0 ETH0.0133786217.70457352

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CvxStableRTokenMetapoolCollateral

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 36 : CvxStableRTokenMetapoolCollateral.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.17;

import "./CvxStableMetapoolCollateral.sol";

/**
 * @title CvxStableRTokenMetapoolCollateral
 *  This plugin contract is intended for 2-token stable metapools that
 *  involve RTokens, such as eUSD-fraxBP.
 *
 * tok = ConvexStakingWrapper(cvxPairedUSDRToken/USDBasePool)
 * ref = PairedUSDRToken/USDBasePool pool invariant
 * tar = USD
 * UoA = USD
 */
contract CvxStableRTokenMetapoolCollateral is CvxStableMetapoolCollateral {
    using FixLib for uint192;

    IAssetRegistry internal immutable reg; // AssetRegistry of pairedToken

    /// @param config.chainlinkFeed Feed units: {UoA/pairedTok}
    /// @dev config.chainlinkFeed/oracleError/oracleTimeout are unused; set chainlinkFeed to 0x1
    /// @dev config.erc20 should be a IConvexStakingWrapper
    constructor(
        CollateralConfig memory config,
        uint192 revenueHiding,
        PTConfiguration memory ptConfig,
        ICurveMetaPool metapoolToken_,
        uint192 pairedTokenDefaultThreshold_
    )
        CvxStableMetapoolCollateral(
            config,
            revenueHiding,
            ptConfig,
            metapoolToken_,
            pairedTokenDefaultThreshold_
        )
    {
        reg = IRToken(address(pairedToken)).main().assetRegistry();
    }

    /// Can revert, used by `_anyDepeggedOutsidePool()`
    /// Should not return FIX_MAX for low
    /// @return lowPaired {UoA/pairedTok} The low price estimate of the paired token
    /// @return highPaired {UoA/pairedTok} The high price estimate of the paired token
    function tryPairedPrice()
        public
        view
        virtual
        override
        returns (uint192 lowPaired, uint192 highPaired)
    {
        return reg.toAsset(pairedToken).price();
    }
}

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

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

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

  function version() external view returns (uint256);

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

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

File 3 of 36 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

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

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

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

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

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

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

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

File 4 of 36 : draft-IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20PermitUpgradeable {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 5 of 36 : IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 6 of 36 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @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);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

File 7 of 36 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 8 of 36 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

File 9 of 36 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

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

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

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

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

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

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`.
        // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
        // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
        // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
        // good first aproximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1;
        uint256 x = a;
        if (x >> 128 > 0) {
            x >>= 128;
            result <<= 64;
        }
        if (x >> 64 > 0) {
            x >>= 64;
            result <<= 32;
        }
        if (x >> 32 > 0) {
            x >>= 32;
            result <<= 16;
        }
        if (x >> 16 > 0) {
            x >>= 16;
            result <<= 8;
        }
        if (x >> 8 > 0) {
            x >>= 8;
            result <<= 4;
        }
        if (x >> 4 > 0) {
            x >>= 4;
            result <<= 2;
        }
        if (x >> 2 > 0) {
            result <<= 1;
        }

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        uint256 result = sqrt(a);
        if (rounding == Rounding.Up && result * result < a) {
            result += 1;
        }
        return result;
    }
}

File 10 of 36 : IAsset.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../libraries/Fixed.sol";
import "./IMain.sol";
import "./IRewardable.sol";

/**
 * @title IAsset
 * @notice Supertype. Any token that interacts with our system must be wrapped in an asset,
 * whether it is used as RToken backing or not. Any token that can report a price in the UoA
 * is eligible to be an asset.
 */
interface IAsset is IRewardable {
    /// Refresh saved price
    /// The Reserve protocol calls this at least once per transaction, before relying on
    /// the Asset's other functions.
    /// @dev Called immediately after deployment, before use
    function refresh() external;

    /// Should not revert
    /// @return low {UoA/tok} The lower end of the price estimate
    /// @return high {UoA/tok} The upper end of the price estimate
    function price() external view returns (uint192 low, uint192 high);

    /// Should not revert
    /// lotLow should be nonzero when the asset might be worth selling
    /// @return lotLow {UoA/tok} The lower end of the lot price estimate
    /// @return lotHigh {UoA/tok} The upper end of the lot price estimate
    function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);

    /// @return {tok} The balance of the ERC20 in whole tokens
    function bal(address account) external view returns (uint192);

    /// @return The ERC20 contract of the token with decimals() available
    function erc20() external view returns (IERC20Metadata);

    /// @return The number of decimals in the ERC20; just for gas optimization
    function erc20Decimals() external view returns (uint8);

    /// @return If the asset is an instance of ICollateral or not
    function isCollateral() external view returns (bool);

    /// @param {UoA} The max trade volume, in UoA
    function maxTradeVolume() external view returns (uint192);
}

// Used only in Testing. Strictly speaking an Asset does not need to adhere to this interface
interface TestIAsset is IAsset {
    /// @return The address of the chainlink feed
    function chainlinkFeed() external view returns (AggregatorV3Interface);

    /// {1} The max % deviation allowed by the oracle
    function oracleError() external view returns (uint192);

    /// @return {s} Seconds that an oracle value is considered valid
    function oracleTimeout() external view returns (uint48);

    /// @return {s} Seconds that the lotPrice should decay over, after stale price
    function priceTimeout() external view returns (uint48);
}

/// CollateralStatus must obey a linear ordering. That is:
/// - being DISABLED is worse than being IFFY, or SOUND
/// - being IFFY is worse than being SOUND.
enum CollateralStatus {
    SOUND,
    IFFY, // When a peg is not holding or a chainlink feed is stale
    DISABLED // When the collateral has completely defaulted
}

/// Upgrade-safe maximum operator for CollateralStatus
library CollateralStatusComparator {
    /// @return Whether a is worse than b
    function worseThan(CollateralStatus a, CollateralStatus b) internal pure returns (bool) {
        return uint256(a) > uint256(b);
    }
}

/**
 * @title ICollateral
 * @notice A subtype of Asset that consists of the tokens eligible to back the RToken.
 */
interface ICollateral is IAsset {
    /// Emitted whenever the collateral status is changed
    /// @param newStatus The old CollateralStatus
    /// @param newStatus The updated CollateralStatus
    event CollateralStatusChanged(
        CollateralStatus indexed oldStatus,
        CollateralStatus indexed newStatus
    );

    /// @dev refresh()
    /// Refresh exchange rates and update default status.
    /// VERY IMPORTANT: In any valid implemntation, status() MUST become DISABLED in refresh() if
    /// refPerTok() has ever decreased since last call.

    /// @return The canonical name of this collateral's target unit.
    function targetName() external view returns (bytes32);

    /// @return The status of this collateral asset. (Is it defaulting? Might it soon?)
    function status() external view returns (CollateralStatus);

    // ==== Exchange Rates ====

    /// @return {ref/tok} Quantity of whole reference units per whole collateral tokens
    function refPerTok() external view returns (uint192);

    /// @return {target/ref} Quantity of whole target units per whole reference unit in the peg
    function targetPerRef() external view returns (uint192);
}

// Used only in Testing. Strictly speaking a Collateral does not need to adhere to this interface
interface TestICollateral is TestIAsset, ICollateral {
    /// @return The epoch timestamp when the collateral will default from IFFY to DISABLED
    function whenDefault() external view returns (uint256);

    /// @return The amount of time a collateral must be in IFFY status until being DISABLED
    function delayUntilDefault() external view returns (uint48);
}

File 11 of 36 : IAssetRegistry.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

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

/// A serialization of the AssetRegistry to be passed around in the P1 impl for gas optimization
struct Registry {
    IERC20[] erc20s;
    IAsset[] assets;
}

/**
 * @title IAssetRegistry
 * @notice The AssetRegistry is in charge of maintaining the ERC20 tokens eligible
 *   to be handled by the rest of the system. If an asset is in the registry, this means:
 *      1. Its ERC20 contract has been vetted
 *      2. The asset is the only asset for that ERC20
 *      3. The asset can be priced in the UoA, usually via an oracle
 */
interface IAssetRegistry is IComponent {
    /// Emitted when an asset is added to the registry
    /// @param erc20 The ERC20 contract for the asset
    /// @param asset The asset contract added to the registry
    event AssetRegistered(IERC20 indexed erc20, IAsset indexed asset);

    /// Emitted when an asset is removed from the registry
    /// @param erc20 The ERC20 contract for the asset
    /// @param asset The asset contract removed from the registry
    event AssetUnregistered(IERC20 indexed erc20, IAsset indexed asset);

    // Initialization
    function init(IMain main_, IAsset[] memory assets_) external;

    /// Fully refresh all asset state
    /// @custom:interaction
    function refresh() external;

    /// @return The corresponding asset for ERC20, or reverts if not registered
    function toAsset(IERC20 erc20) external view returns (IAsset);

    /// @return The corresponding collateral, or reverts if unregistered or not collateral
    function toColl(IERC20 erc20) external view returns (ICollateral);

    /// @return If the ERC20 is registered
    function isRegistered(IERC20 erc20) external view returns (bool);

    /// @return A list of all registered ERC20s
    function erc20s() external view returns (IERC20[] memory);

    /// @return reg The list of registered ERC20s and Assets, in the same order
    function getRegistry() external view returns (Registry memory reg);

    function register(IAsset asset) external returns (bool);

    function swapRegistered(IAsset asset) external returns (bool swapped);

    function unregister(IAsset asset) external;
}

File 12 of 36 : IBackingManager.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

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

/**
 * @title IBackingManager
 * @notice The BackingManager handles changes in the ERC20 balances that back an RToken.
 *   - It computes which trades to perform, if any, and initiates these trades with the Broker.
 *   - If already collateralized, excess assets are transferred to RevenueTraders.
 *
 * `manageTokens(erc20s)` and `manageTokensSortedOrder(erc20s)` are handles for getting at the
 *   same underlying functionality. The former allows an ERC20 list in any order, while the
 *   latter requires a sorted array, and executes in O(n) rather than O(n^2) time. In the
 *   vast majority of cases we expect the the O(n^2) function to be acceptable.
 */
interface IBackingManager is IComponent, ITrading {
    event TradingDelaySet(uint48 indexed oldVal, uint48 indexed newVal);
    event BackingBufferSet(uint192 indexed oldVal, uint192 indexed newVal);

    // Initialization
    function init(
        IMain main_,
        uint48 tradingDelay_,
        uint192 backingBuffer_,
        uint192 maxTradeSlippage_,
        uint192 minTradeVolume_
    ) external;

    // Give RToken max allowance over a registered token
    /// @custom:refresher
    /// @custom:interaction
    function grantRTokenAllowance(IERC20) external;

    /// Maintain the overall backing policy; handout assets otherwise
    /// @dev Performs a uniqueness check on the erc20s list in O(n^2)
    /// @custom:interaction
    function manageTokens(IERC20[] memory erc20s) external;

    /// Maintain the overall backing policy; handout assets otherwise
    /// @dev Tokens must be in sorted order!
    /// @dev Performs a uniqueness check on the erc20s list in O(n)
    /// @custom:interaction
    function manageTokensSortedOrder(IERC20[] memory erc20s) external;
}

interface TestIBackingManager is IBackingManager, TestITrading {
    function tradingDelay() external view returns (uint48);

    function backingBuffer() external view returns (uint192);

    function setTradingDelay(uint48 val) external;

    function setBackingBuffer(uint192 val) external;
}

File 13 of 36 : IBasketHandler.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";

struct BasketRange {
    uint192 bottom; // {BU}
    uint192 top; // {BU}
}

/**
 * @title IBasketHandler
 * @notice The BasketHandler aims to maintain a reference basket of constant target unit amounts.
 * When a collateral token defaults, a new reference basket of equal target units is set.
 * When _all_ collateral tokens default for a target unit, only then is the basket allowed to fall
 *   in terms of target unit amounts. The basket is considered defaulted in this case.
 */
interface IBasketHandler is IComponent {
    /// Emitted when the prime basket is set
    /// @param erc20s The collateral tokens for the prime basket
    /// @param targetAmts {target/BU} A list of quantities of target unit per basket unit
    /// @param targetNames Each collateral token's targetName
    event PrimeBasketSet(IERC20[] erc20s, uint192[] targetAmts, bytes32[] targetNames);

    /// Emitted when the reference basket is set
    /// @param nonce The basket nonce
    /// @param erc20s The list of collateral tokens in the reference basket
    /// @param refAmts {ref/BU} The reference amounts of the basket collateral tokens
    /// @param disabled True when the list of erc20s + refAmts may not be correct
    event BasketSet(uint256 indexed nonce, IERC20[] erc20s, uint192[] refAmts, bool disabled);

    /// Emitted when a backup config is set for a target unit
    /// @param targetName The name of the target unit as a bytes32
    /// @param max The max number to use from `erc20s`
    /// @param erc20s The set of backup collateral tokens
    event BackupConfigSet(bytes32 indexed targetName, uint256 indexed max, IERC20[] erc20s);

    // Initialization
    function init(IMain main_) external;

    /// Set the prime basket
    /// @param erc20s The collateral tokens for the new prime basket
    /// @param targetAmts The target amounts (in) {target/BU} for the new prime basket
    ///                   required range: 1e9 values; absolute range irrelevant.
    /// @custom:governance
    function setPrimeBasket(IERC20[] memory erc20s, uint192[] memory targetAmts) external;

    /// Set the backup configuration for a given target
    /// @param targetName The name of the target as a bytes32
    /// @param max The maximum number of collateral tokens to use from this target
    ///            Required range: 1-255
    /// @param erc20s A list of ordered backup collateral tokens
    /// @custom:governance
    function setBackupConfig(
        bytes32 targetName,
        uint256 max,
        IERC20[] calldata erc20s
    ) external;

    /// Default the basket in order to schedule a basket refresh
    /// @custom:protected
    function disableBasket() external;

    /// Governance-controlled setter to cause a basket switch explicitly
    /// @custom:governance
    /// @custom:interaction
    function refreshBasket() external;

    /// @return If the BackingManager has sufficient collateral to redeem the entire RToken supply
    function fullyCollateralized() external view returns (bool);

    /// @return status The worst CollateralStatus of all collateral in the basket
    function status() external view returns (CollateralStatus status);

    /// @param erc20 The ERC20 token contract for the asset
    /// @return {tok/BU} The whole token quantity of token in the reference basket
    /// Returns 0 if erc20 is not registered or not in the basket
    /// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
    /// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
    function quantity(IERC20 erc20) external view returns (uint192);

    /// Like quantity(), but unsafe because it DOES NOT CONFIRM THAT THE ASSET IS CORRECT
    /// @param erc20 The ERC20 token contract for the asset
    /// @param asset The registered asset plugin contract for the erc20
    /// @return {tok/BU} The whole token quantity of token in the reference basket
    /// Returns 0 if erc20 is not registered or not in the basket
    /// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.
    /// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())
    function quantityUnsafe(IERC20 erc20, IAsset asset) external view returns (uint192);

    /// @param amount {BU}
    /// @return erc20s The addresses of the ERC20 tokens in the reference basket
    /// @return quantities {qTok} The quantity of each ERC20 token to issue `amount` baskets
    function quote(uint192 amount, RoundingMode rounding)
        external
        view
        returns (address[] memory erc20s, uint256[] memory quantities);

    /// @return top {BU} The number of partial basket units: e.g max(coll.map((c) => c.balAsBUs())
    ///         bottom {BU} The number of whole basket units held by the account
    function basketsHeldBy(address account) external view returns (BasketRange memory);

    /// Should not revert
    /// @return low {UoA/BU} The lower end of the price estimate
    /// @return high {UoA/BU} The upper end of the price estimate
    function price() external view returns (uint192 low, uint192 high);

    /// Should not revert
    /// lotLow should be nonzero if a BU could be worth selling
    /// @return lotLow {UoA/tok} The lower end of the lot price estimate
    /// @return lotHigh {UoA/tok} The upper end of the lot price estimate
    function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);

    /// @return timestamp The timestamp at which the basket was last set
    function timestamp() external view returns (uint48);

    /// @return The current basket nonce, regardless of status
    function nonce() external view returns (uint48);
}

File 14 of 36 : IBroker.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "./IAsset.sol";
import "./IComponent.sol";
import "./IGnosis.sol";
import "./ITrade.sol";

/// The data format that describes a request for trade with the Broker
struct TradeRequest {
    IAsset sell;
    IAsset buy;
    uint256 sellAmount; // {qSellTok}
    uint256 minBuyAmount; // {qBuyTok}
}

/**
 * @title IBroker
 * @notice The Broker deploys oneshot Trade contracts for Traders and monitors
 *   the continued proper functioning of trading platforms.
 */
interface IBroker is IComponent {
    event GnosisSet(IGnosis indexed oldVal, IGnosis indexed newVal);
    event TradeImplementationSet(ITrade indexed oldVal, ITrade indexed newVal);
    event AuctionLengthSet(uint48 indexed oldVal, uint48 indexed newVal);
    event DisabledSet(bool indexed prevVal, bool indexed newVal);

    // Initialization
    function init(
        IMain main_,
        IGnosis gnosis_,
        ITrade tradeImplementation_,
        uint48 auctionLength_
    ) external;

    /// Request a trade from the broker
    /// @dev Requires setting an allowance in advance
    /// @custom:interaction
    function openTrade(TradeRequest memory req) external returns (ITrade);

    /// Only callable by one of the trading contracts the broker deploys
    function reportViolation() external;

    function disabled() external view returns (bool);
}

interface TestIBroker is IBroker {
    function gnosis() external view returns (IGnosis);

    function tradeImplementation() external view returns (ITrade);

    function auctionLength() external view returns (uint48);

    function setGnosis(IGnosis newGnosis) external;

    function setTradeImplementation(ITrade newTradeImplementation) external;

    function setAuctionLength(uint48 newAuctionLength) external;

    function setDisabled(bool disabled_) external;
}

File 15 of 36 : IComponent.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "./IMain.sol";
import "./IVersioned.sol";

/**
 * @title IComponent
 * @notice A Component is the central building block of all our system contracts. Components
 *   contain important state that must be migrated during upgrades, and they delegate
 *   their ownership to Main's owner.
 */
interface IComponent is IVersioned {
    function main() external view returns (IMain);
}

File 16 of 36 : IDistributor.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

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

struct RevenueShare {
    uint16 rTokenDist; // {revShare} A value between [0, 10,000]
    uint16 rsrDist; // {revShare} A value between [0, 10,000]
}

/// Assumes no more than 1024 independent distributions.
struct RevenueTotals {
    uint24 rTokenTotal; // {revShare}
    uint24 rsrTotal; // {revShare}
}

/**
 * @title IDistributor
 * @notice The Distributor Component maintains a revenue distribution table that dictates
 *   how to divide revenue across the Furnace, StRSR, and any other destinations.
 */
interface IDistributor is IComponent {
    /// Emitted when a distribution is set
    /// @param dest The address set to receive the distribution
    /// @param rTokenDist The distribution of RToken that should go to `dest`
    /// @param rsrDist The distribution of RSR that should go to `dest`
    event DistributionSet(address dest, uint16 rTokenDist, uint16 rsrDist);

    /// Emitted when revenue is distributed
    /// @param erc20 The token being distributed, either RSR or the RToken itself
    /// @param source The address providing the revenue
    /// @param amount The amount of the revenue
    event RevenueDistributed(IERC20 indexed erc20, address indexed source, uint256 indexed amount);

    // Initialization
    function init(IMain main_, RevenueShare memory dist) external;

    /// @custom:governance
    function setDistribution(address dest, RevenueShare memory share) external;

    /// Distribute the `erc20` token across all revenue destinations
    /// @custom:interaction
    function distribute(IERC20 erc20, uint256 amount) external;

    /// @return revTotals The total of all  destinations
    function totals() external view returns (RevenueTotals memory revTotals);
}

interface TestIDistributor is IDistributor {
    // solhint-disable-next-line func-name-mixedcase
    function FURNACE() external view returns (address);

    // solhint-disable-next-line func-name-mixedcase
    function ST_RSR() external view returns (address);

    /// @return rTokenDist The RToken distribution for the address
    /// @return rsrDist The RSR distribution for the address
    function distribution(address) external view returns (uint16 rTokenDist, uint16 rsrDist);
}

File 17 of 36 : IFurnace.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "../libraries/Fixed.sol";
import "./IComponent.sol";

/**
 * @title IFurnace
 * @notice A helper contract to burn RTokens slowly and permisionlessly.
 */
interface IFurnace is IComponent {
    // Initialization
    function init(IMain main_, uint192 ratio_) external;

    /// Emitted when the melting ratio is changed
    /// @param oldRatio The old ratio
    /// @param newRatio The new ratio
    event RatioSet(uint192 indexed oldRatio, uint192 indexed newRatio);

    function ratio() external view returns (uint192);

    ///    Needed value range: [0, 1], granularity 1e-9
    /// @custom:governance
    function setRatio(uint192) external;

    /// Performs any RToken melting that has vested since the last payout.
    /// @custom:refresher
    function melt() external;
}

interface TestIFurnace is IFurnace {
    function lastPayout() external view returns (uint256);

    function lastPayoutBal() external view returns (uint256);
}

File 18 of 36 : IGnosis.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

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

struct GnosisAuctionData {
    IERC20 auctioningToken;
    IERC20 biddingToken;
    uint256 orderCancellationEndDate;
    uint256 auctionEndDate;
    bytes32 initialAuctionOrder;
    uint256 minimumBiddingAmountPerOrder;
    uint256 interimSumBidAmount;
    bytes32 interimOrder;
    bytes32 clearingPriceOrder;
    uint96 volumeClearingPriceOrder;
    bool minFundingThresholdNotReached;
    bool isAtomicClosureAllowed;
    uint256 feeNumerator;
    uint256 minFundingThreshold;
}

/// The relevant portion of the interface of the live Gnosis EasyAuction contract
/// https://github.com/gnosis/ido-contracts/blob/main/contracts/EasyAuction.sol
interface IGnosis {
    function initiateAuction(
        IERC20 auctioningToken,
        IERC20 biddingToken,
        uint256 orderCancellationEndDate,
        uint256 auctionEndDate,
        uint96 auctionedSellAmount,
        uint96 minBuyAmount,
        uint256 minimumBiddingAmountPerOrder,
        uint256 minFundingThreshold,
        bool isAtomicClosureAllowed,
        address accessManagerContract,
        bytes memory accessManagerContractData
    ) external returns (uint256 auctionId);

    function auctionData(uint256 auctionId) external view returns (GnosisAuctionData memory);

    /// @param auctionId The external auction id
    /// @dev See here for decoding: https://git.io/JMang
    /// @return encodedOrder The order, encoded in a bytes 32
    function settleAuction(uint256 auctionId) external returns (bytes32 encodedOrder);

    /// @return The numerator over a 1000-valued denominator
    function feeNumerator() external returns (uint256);
}

File 19 of 36 : IMain.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IAssetRegistry.sol";
import "./IBasketHandler.sol";
import "./IBackingManager.sol";
import "./IBroker.sol";
import "./IGnosis.sol";
import "./IFurnace.sol";
import "./IDistributor.sol";
import "./IRToken.sol";
import "./IRevenueTrader.sol";
import "./IStRSR.sol";
import "./ITrading.sol";
import "./IVersioned.sol";

// === Auth roles ===

bytes32 constant OWNER = bytes32(bytes("OWNER"));
bytes32 constant SHORT_FREEZER = bytes32(bytes("SHORT_FREEZER"));
bytes32 constant LONG_FREEZER = bytes32(bytes("LONG_FREEZER"));
bytes32 constant PAUSER = bytes32(bytes("PAUSER"));

/**
 * Main is a central hub that maintains a list of Component contracts.
 *
 * Components:
 *   - perform a specific function
 *   - defer auth to Main
 *   - usually (but not always) contain sizeable state that require a proxy
 */
struct Components {
    // Definitely need proxy
    IRToken rToken;
    IStRSR stRSR;
    IAssetRegistry assetRegistry;
    IBasketHandler basketHandler;
    IBackingManager backingManager;
    IDistributor distributor;
    IFurnace furnace;
    IBroker broker;
    IRevenueTrader rsrTrader;
    IRevenueTrader rTokenTrader;
}

interface IAuth is IAccessControlUpgradeable {
    /// Emitted when `unfreezeAt` is changed
    /// @param oldVal The old value of `unfreezeAt`
    /// @param newVal The new value of `unfreezeAt`
    event UnfreezeAtSet(uint48 indexed oldVal, uint48 indexed newVal);

    /// Emitted when the short freeze duration governance param is changed
    /// @param oldDuration The old short freeze duration
    /// @param newDuration The new short freeze duration
    event ShortFreezeDurationSet(uint48 indexed oldDuration, uint48 indexed newDuration);

    /// Emitted when the long freeze duration governance param is changed
    /// @param oldDuration The old long freeze duration
    /// @param newDuration The new long freeze duration
    event LongFreezeDurationSet(uint48 indexed oldDuration, uint48 indexed newDuration);

    /// Emitted when the system is paused or unpaused
    /// @param oldVal The old value of `paused`
    /// @param newVal The new value of `paused`
    event PausedSet(bool indexed oldVal, bool indexed newVal);

    /**
     * Paused: Disable everything except for OWNER actions, RToken.redeem, StRSR.stake,
     * and StRSR.payoutRewards
     * Frozen: Disable everything except for OWNER actions + StRSR.stake (for governance)
     */

    function pausedOrFrozen() external view returns (bool);

    function frozen() external view returns (bool);

    function shortFreeze() external view returns (uint48);

    function longFreeze() external view returns (uint48);

    // ====

    // onlyRole(OWNER)
    function freezeForever() external;

    // onlyRole(SHORT_FREEZER)
    function freezeShort() external;

    // onlyRole(LONG_FREEZER)
    function freezeLong() external;

    // onlyRole(OWNER)
    function unfreeze() external;

    function pause() external;

    function unpause() external;
}

interface IComponentRegistry {
    // === Component setters/getters ===

    event RTokenSet(IRToken indexed oldVal, IRToken indexed newVal);

    function rToken() external view returns (IRToken);

    event StRSRSet(IStRSR indexed oldVal, IStRSR indexed newVal);

    function stRSR() external view returns (IStRSR);

    event AssetRegistrySet(IAssetRegistry indexed oldVal, IAssetRegistry indexed newVal);

    function assetRegistry() external view returns (IAssetRegistry);

    event BasketHandlerSet(IBasketHandler indexed oldVal, IBasketHandler indexed newVal);

    function basketHandler() external view returns (IBasketHandler);

    event BackingManagerSet(IBackingManager indexed oldVal, IBackingManager indexed newVal);

    function backingManager() external view returns (IBackingManager);

    event DistributorSet(IDistributor indexed oldVal, IDistributor indexed newVal);

    function distributor() external view returns (IDistributor);

    event RSRTraderSet(IRevenueTrader indexed oldVal, IRevenueTrader indexed newVal);

    function rsrTrader() external view returns (IRevenueTrader);

    event RTokenTraderSet(IRevenueTrader indexed oldVal, IRevenueTrader indexed newVal);

    function rTokenTrader() external view returns (IRevenueTrader);

    event FurnaceSet(IFurnace indexed oldVal, IFurnace indexed newVal);

    function furnace() external view returns (IFurnace);

    event BrokerSet(IBroker indexed oldVal, IBroker indexed newVal);

    function broker() external view returns (IBroker);
}

/**
 * @title IMain
 * @notice The central hub for the entire system. Maintains components and an owner singleton role
 */
interface IMain is IVersioned, IAuth, IComponentRegistry {
    function poke() external; // not used in p1

    // === Initialization ===

    event MainInitialized();

    function init(
        Components memory components,
        IERC20 rsr_,
        uint48 shortFreeze_,
        uint48 longFreeze_
    ) external;

    function rsr() external view returns (IERC20);
}

interface TestIMain is IMain {
    /// @custom:governance
    function setShortFreeze(uint48) external;

    /// @custom:governance
    function setLongFreeze(uint48) external;

    function shortFreeze() external view returns (uint48);

    function longFreeze() external view returns (uint48);

    function longFreezes(address account) external view returns (uint256);

    function paused() external view returns (bool);
}

File 20 of 36 : IRevenueTrader.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "./IComponent.sol";
import "./ITrading.sol";

/**
 * @title IRevenueTrader
 * @notice The RevenueTrader is an extension of the trading mixin that trades all
 *   assets at its address for a single target asset. There are two runtime instances
 *   of the RevenueTrader, 1 for RToken and 1 for RSR.
 */
interface IRevenueTrader is IComponent, ITrading {
    // Initialization
    function init(
        IMain main_,
        IERC20 tokenToBuy_,
        uint192 maxTradeSlippage_,
        uint192 minTradeVolume_
    ) external;

    /// Processes a single token; unpermissioned
    /// @dev Intended to be used with multicall
    /// @custom:interaction
    function manageToken(IERC20 sell) external;
}

// solhint-disable-next-line no-empty-blocks
interface TestIRevenueTrader is IRevenueTrader, TestITrading {
    function tokenToBuy() external view returns (IERC20);
}

File 21 of 36 : IRewardable.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

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

/**
 * @title IRewardable
 * @notice A simple interface mixin to support claiming of rewards.
 */
interface IRewardable {
    /// Emitted whenever a reward token balance is claimed
    event RewardsClaimed(IERC20 indexed erc20, uint256 indexed amount);

    /// Claim rewards earned by holding a balance of the ERC20 token
    /// Must emit `RewardsClaimed` for each token rewards are claimed for
    /// @dev delegatecall: there be dragons here!
    /// @custom:interaction
    function claimRewards() external;
}

/**
 * @title IRewardableComponent
 * @notice A simple interface mixin to support claiming of rewards.
 */
interface IRewardableComponent is IRewardable {
    /// Claim rewards for a single ERC20
    /// Must emit `RewardsClaimed` for each token rewards are claimed for
    /// @dev delegatecall: there be dragons here!
    /// @custom:interaction
    function claimRewardsSingle(IERC20 erc20) external;
}

File 22 of 36 : IRToken.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "../libraries/Throttle.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./IMain.sol";
import "./IRewardable.sol";

/**
 * @title IRToken
 * @notice An RToken is an ERC20 that is permissionlessly issuable/redeemable and tracks an
 *   exchange rate against a single unit: baskets, or {BU} in our type notation.
 */
interface IRToken is IComponent, IERC20MetadataUpgradeable, IERC20PermitUpgradeable {
    /// Emitted when an issuance of RToken occurs, whether it occurs via slow minting or not
    /// @param issuer The address holding collateral tokens
    /// @param recipient The address of the recipient of the RTokens
    /// @param amount The quantity of RToken being issued
    /// @param baskets The corresponding number of baskets
    event Issuance(
        address indexed issuer,
        address indexed recipient,
        uint256 indexed amount,
        uint192 baskets
    );

    /// Emitted when a redemption of RToken occurs
    /// @param redeemer The address holding RToken
    /// @param recipient The address of the account receiving the backing collateral tokens
    /// @param amount The quantity of RToken being redeemed
    /// @param baskets The corresponding number of baskets
    /// @param amount {qRTok} The amount of RTokens canceled
    event Redemption(
        address indexed redeemer,
        address indexed recipient,
        uint256 indexed amount,
        uint192 baskets
    );

    /// Emitted when the number of baskets needed changes
    /// @param oldBasketsNeeded Previous number of baskets units needed
    /// @param newBasketsNeeded New number of basket units needed
    event BasketsNeededChanged(uint192 oldBasketsNeeded, uint192 newBasketsNeeded);

    /// Emitted when RToken is melted, i.e the RToken supply is decreased but basketsNeeded is not
    /// @param amount {qRTok}
    event Melted(uint256 amount);

    /// Emitted when issuance SupplyThrottle params are set
    event IssuanceThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);

    /// Emitted when redemption SupplyThrottle params are set
    event RedemptionThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);

    // Initialization
    function init(
        IMain main_,
        string memory name_,
        string memory symbol_,
        string memory mandate_,
        ThrottleLib.Params calldata issuanceThrottleParams,
        ThrottleLib.Params calldata redemptionThrottleParams
    ) external;

    /// Issue an RToken with basket collateral
    /// @param amount {qRTok} The quantity of RToken to issue
    /// @custom:interaction
    function issue(uint256 amount) external;

    /// Issue an RToken with basket collateral, to a particular recipient
    /// @param recipient The address to receive the issued RTokens
    /// @param amount {qRTok} The quantity of RToken to issue
    /// @custom:interaction
    function issueTo(address recipient, uint256 amount) external;

    /// Redeem RToken for basket collateral
    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
    /// @param basketNonce The nonce of the basket the redemption should be from; else reverts
    /// @custom:interaction
    function redeem(uint256 amount, uint48 basketNonce) external;

    /// Redeem RToken for basket collateral to a particular recipient
    /// @param recipient The address to receive the backing collateral tokens
    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem
    /// @param basketNonce The nonce of the basket the redemption should be from; else reverts
    /// @custom:interaction
    function redeemTo(
        address recipient,
        uint256 amount,
        uint48 basketNonce
    ) external;

    /// Mints a quantity of RToken to the `recipient`, callable only by the BackingManager
    /// @param recipient The recipient of the newly minted RToken
    /// @param amount {qRTok} The amount to be minted
    /// @custom:protected
    function mint(address recipient, uint256 amount) external;

    /// Melt a quantity of RToken from the caller's account
    /// @param amount {qRTok} The amount to be melted
    function melt(uint256 amount) external;

    /// Set the number of baskets needed directly, callable only by the BackingManager
    /// @param basketsNeeded {BU} The number of baskets to target
    ///                      needed range: pretty interesting
    /// @custom:protected
    function setBasketsNeeded(uint192 basketsNeeded) external;

    /// @return {BU} How many baskets are being targeted
    function basketsNeeded() external view returns (uint192);

    /// @return {qRTok} The maximum issuance that can be performed in the current block
    function issuanceAvailable() external view returns (uint256);

    /// @return {qRTok} The maximum redemption that can be performed in the current block
    function redemptionAvailable() external view returns (uint256);
}

interface TestIRToken is IRToken {
    function setIssuanceThrottleParams(ThrottleLib.Params calldata) external;

    function setRedemptionThrottleParams(ThrottleLib.Params calldata) external;

    function issuanceThrottleParams() external view returns (ThrottleLib.Params memory);

    function redemptionThrottleParams() external view returns (ThrottleLib.Params memory);

    function increaseAllowance(address, uint256) external returns (bool);

    function decreaseAllowance(address, uint256) external returns (bool);

    function monetizeDonations(IERC20) external;
}

File 23 of 36 : IStRSR.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
// solhint-disable-next-line max-line-length
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "../libraries/Fixed.sol";
import "./IComponent.sol";
import "./IMain.sol";

/**
 * @title IStRSR
 * @notice An ERC20 token representing shares of the RSR over-collateralization pool.
 *
 * StRSR permits the BackingManager to take RSR in times of need. In return, the BackingManager
 * benefits the StRSR pool with RSR rewards purchased with a portion of its revenue.
 *
 * In the absence of collateral default or losses due to slippage, StRSR should have a
 * monotonically increasing exchange rate with respect to RSR, meaning that over time
 * StRSR is redeemable for more RSR. It is non-rebasing.
 */
interface IStRSR is IERC20MetadataUpgradeable, IERC20PermitUpgradeable, IComponent {
    /// Emitted when RSR is staked
    /// @param era The era at time of staking
    /// @param staker The address of the staker
    /// @param rsrAmount {qRSR} How much RSR was staked
    /// @param stRSRAmount {qStRSR} How much stRSR was minted by this staking
    event Staked(
        uint256 indexed era,
        address indexed staker,
        uint256 rsrAmount,
        uint256 indexed stRSRAmount
    );

    /// Emitted when an unstaking is started
    /// @param draftId The id of the draft.
    /// @param draftEra The era of the draft.
    /// @param staker The address of the unstaker
    ///   The triple (staker, draftEra, draftId) is a unique ID
    /// @param rsrAmount {qRSR} How much RSR this unstaking will be worth, absent seizures
    /// @param stRSRAmount {qStRSR} How much stRSR was burned by this unstaking
    event UnstakingStarted(
        uint256 indexed draftId,
        uint256 indexed draftEra,
        address indexed staker,
        uint256 rsrAmount,
        uint256 stRSRAmount,
        uint256 availableAt
    );

    /// Emitted when RSR is unstaked
    /// @param firstId The beginning of the range of draft IDs withdrawn in this transaction
    /// @param endId The end of range of draft IDs withdrawn in this transaction
    ///   (ID i was withdrawn if firstId <= i < endId)
    /// @param draftEra The era of the draft.
    ///   The triple (staker, draftEra, id) is a unique ID among drafts
    /// @param staker The address of the unstaker

    /// @param rsrAmount {qRSR} How much RSR this unstaking was worth
    event UnstakingCompleted(
        uint256 indexed firstId,
        uint256 indexed endId,
        uint256 draftEra,
        address indexed staker,
        uint256 rsrAmount
    );

    /// Emitted whenever the exchange rate changes
    event ExchangeRateSet(uint192 indexed oldVal, uint192 indexed newVal);

    /// Emitted whenever RSR are paids out
    event RewardsPaid(uint256 indexed rsrAmt);

    /// Emitted if all the RSR in the staking pool is seized and all balances are reset to zero.
    event AllBalancesReset(uint256 indexed newEra);
    /// Emitted if all the RSR in the unstakin pool is seized, and all ongoing unstaking is voided.
    event AllUnstakingReset(uint256 indexed newEra);

    event UnstakingDelaySet(uint48 indexed oldVal, uint48 indexed newVal);
    event RewardRatioSet(uint192 indexed oldVal, uint192 indexed newVal);

    // Initialization
    function init(
        IMain main_,
        string memory name_,
        string memory symbol_,
        uint48 unstakingDelay_,
        uint192 rewardRatio_
    ) external;

    /// Gather and payout rewards from rsrTrader
    /// @custom:interaction
    function payoutRewards() external;

    /// Stakes an RSR `amount` on the corresponding RToken to earn yield and over-collateralized
    /// the system
    /// @param amount {qRSR}
    /// @custom:interaction
    function stake(uint256 amount) external;

    /// Begins a delayed unstaking for `amount` stRSR
    /// @param amount {qStRSR}
    /// @custom:interaction
    function unstake(uint256 amount) external;

    /// Complete delayed unstaking for the account, up to (but not including!) `endId`
    /// @custom:interaction
    function withdraw(address account, uint256 endId) external;

    /// Seize RSR, only callable by main.backingManager()
    /// @custom:protected
    function seizeRSR(uint256 amount) external;

    /// Return the maximum valid value of endId such that withdraw(endId) should immediately work
    function endIdForWithdraw(address account) external view returns (uint256 endId);

    /// @return {qRSR/qStRSR} The exchange rate between RSR and StRSR
    function exchangeRate() external view returns (uint192);
}

interface TestIStRSR is IStRSR {
    function rewardRatio() external view returns (uint192);

    function setRewardRatio(uint192) external;

    function unstakingDelay() external view returns (uint48);

    function setUnstakingDelay(uint48) external;

    function increaseAllowance(address, uint256) external returns (bool);

    function decreaseAllowance(address, uint256) external returns (bool);

    /// @return {qStRSR/qRSR} The exchange rate between StRSR and RSR
    function exchangeRate() external view returns (uint192);
}

File 24 of 36 : ITrade.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

/**
 * Simple generalized trading interface for all Trade contracts to obey
 *
 * Usage: if (canSettle()) settle()
 */
interface ITrade {
    function sell() external view returns (IERC20Metadata);

    function buy() external view returns (IERC20Metadata);

    /// @return The timestamp at which the trade is projected to become settle-able
    function endTime() external view returns (uint48);

    /// @return True if the trade can be settled
    /// @dev Should be guaranteed to be true eventually as an invariant
    function canSettle() external view returns (bool);

    /// Complete the trade and transfer tokens back to the origin trader
    /// @return soldAmt {qSellTok} The quantity of tokens sold
    /// @return boughtAmt {qBuyTok} The quantity of tokens bought
    function settle() external returns (uint256 soldAmt, uint256 boughtAmt);
}

File 25 of 36 : ITrading.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../libraries/Fixed.sol";
import "./IAsset.sol";
import "./IComponent.sol";
import "./ITrade.sol";
import "./IRewardable.sol";

/**
 * @title ITrading
 * @notice Common events and refresher function for all Trading contracts
 */
interface ITrading is IComponent, IRewardableComponent {
    event MaxTradeSlippageSet(uint192 indexed oldVal, uint192 indexed newVal);
    event MinTradeVolumeSet(uint192 indexed oldVal, uint192 indexed newVal);

    /// Emitted when a trade is started
    /// @param trade The one-time-use trade contract that was just deployed
    /// @param sell The token to sell
    /// @param buy The token to buy
    /// @param sellAmount {qSellTok} The quantity of the selling token
    /// @param minBuyAmount {qBuyTok} The minimum quantity of the buying token to accept
    event TradeStarted(
        ITrade indexed trade,
        IERC20 indexed sell,
        IERC20 indexed buy,
        uint256 sellAmount,
        uint256 minBuyAmount
    );

    /// Emitted after a trade ends
    /// @param trade The one-time-use trade contract
    /// @param sell The token to sell
    /// @param buy The token to buy
    /// @param sellAmount {qSellTok} The quantity of the token sold
    /// @param buyAmount {qBuyTok} The quantity of the token bought
    event TradeSettled(
        ITrade indexed trade,
        IERC20 indexed sell,
        IERC20 indexed buy,
        uint256 sellAmount,
        uint256 buyAmount
    );

    /// Settle a single trade, expected to be used with multicall for efficient mass settlement
    /// @custom:refresher
    function settleTrade(IERC20 sell) external;

    /// @return {%} The maximum trade slippage acceptable
    function maxTradeSlippage() external view returns (uint192);

    /// @return {UoA} The minimum trade volume in UoA, applies to all assets
    function minTradeVolume() external view returns (uint192);

    /// @return The ongoing trade for a sell token, or the zero address
    function trades(IERC20 sell) external view returns (ITrade);

    /// @return The number of ongoing trades open
    function tradesOpen() external view returns (uint48);

    /// Light wrapper around FixLib.mulDiv to support try-catch
    function mulDivCeil(
        uint192 x,
        uint192 y,
        uint192 z
    ) external pure returns (uint192);
}

interface TestITrading is ITrading {
    /// @custom:governance
    function setMaxTradeSlippage(uint192 val) external;

    /// @custom:governance
    function setMinTradeVolume(uint192 val) external;
}

File 26 of 36 : IVersioned.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

interface IVersioned {
    function version() external view returns (string memory);
}

File 27 of 36 : Fixed.sol
// SPDX-License-Identifier: BlueOak-1.0.0
// solhint-disable func-name-mixedcase func-visibility
pragma solidity ^0.8.17;

/// @title FixedPoint, a fixed-point arithmetic library defining the custom type uint192
/// @author Matt Elder <[email protected]> and the Reserve Team <https://reserve.org>

/** The logical type `uint192 ` is a 192 bit value, representing an 18-decimal Fixed-point
    fractional value.  This is what's described in the Solidity documentation as
    "fixed192x18" -- a value represented by 192 bits, that makes 18 digits available to
    the right of the decimal point.

    The range of values that uint192 can represent is about [-1.7e20, 1.7e20].
    Unless a function explicitly says otherwise, it will fail on overflow.
    To be clear, the following should hold:
    toFix(0) == 0
    toFix(1) == 1e18
*/

// Analysis notes:
//   Every function should revert iff its result is out of bounds.
//   Unless otherwise noted, when a rounding mode is given, that mode is applied to
//     a single division that may happen as the last step in the computation.
//   Unless otherwise noted, when a rounding mode is *not* given but is needed, it's FLOOR.
//   For each, we comment:
//   - @return is the value expressed  in "value space", where uint192(1e18) "is" 1.0
//   - as-ints: is the value expressed in "implementation space", where uint192(1e18) "is" 1e18
//   The "@return" expression is suitable for actually using the library
//   The "as-ints" expression is suitable for testing

// A uint value passed to this library was out of bounds for uint192 operations
error UIntOutOfBounds();
bytes32 constant UIntOutofBoundsHash = keccak256(abi.encodeWithSignature("UIntOutOfBounds()"));

// Used by P1 implementation for easier casting
uint256 constant FIX_ONE_256 = 1e18;
uint8 constant FIX_DECIMALS = 18;

// If a particular uint192 is represented by the uint192 n, then the uint192 represents the
// value n/FIX_SCALE.
uint64 constant FIX_SCALE = 1e18;

// FIX_SCALE Squared:
uint128 constant FIX_SCALE_SQ = 1e36;

// The largest integer that can be converted to uint192 .
// This is a bit bigger than 3.1e39
uint192 constant FIX_MAX_INT = type(uint192).max / FIX_SCALE;

uint192 constant FIX_ZERO = 0; // The uint192 representation of zero.
uint192 constant FIX_ONE = FIX_SCALE; // The uint192 representation of one.
uint192 constant FIX_MAX = type(uint192).max; // The largest uint192. (Not an integer!)
uint192 constant FIX_MIN = 0; // The smallest uint192.

/// An enum that describes a rounding approach for converting to ints
enum RoundingMode {
    FLOOR, // Round towards zero
    ROUND, // Round to the nearest int
    CEIL // Round away from zero
}

RoundingMode constant FLOOR = RoundingMode.FLOOR;
RoundingMode constant ROUND = RoundingMode.ROUND;
RoundingMode constant CEIL = RoundingMode.CEIL;

/* @dev Solidity 0.8.x only allows you to change one of type or size per type conversion.
   Thus, all the tedious-looking double conversions like uint256(uint256 (foo))
   See: https://docs.soliditylang.org/en/v0.8.17/080-breaking-changes.html#new-restrictions
 */

/// Explicitly convert a uint256 to a uint192. Revert if the input is out of bounds.
function _safeWrap(uint256 x) pure returns (uint192) {
    if (FIX_MAX < x) revert UIntOutOfBounds();
    return uint192(x);
}

/// Convert a uint to its Fix representation.
/// @return x
// as-ints: x * 1e18
function toFix(uint256 x) pure returns (uint192) {
    return _safeWrap(x * FIX_SCALE);
}

/// Convert a uint to its fixed-point representation, and left-shift its value `shiftLeft`
/// decimal digits.
/// @return x * 10**shiftLeft
// as-ints: x * 10**(shiftLeft + 18)
function shiftl_toFix(uint256 x, int8 shiftLeft) pure returns (uint192) {
    return shiftl_toFix(x, shiftLeft, FLOOR);
}

/// @return x * 10**shiftLeft
// as-ints: x * 10**(shiftLeft + 18)
function shiftl_toFix(
    uint256 x,
    int8 shiftLeft,
    RoundingMode rounding
) pure returns (uint192) {
    // conditions for avoiding overflow
    if (x == 0) return 0;
    if (shiftLeft <= -96) return (rounding == CEIL ? 1 : 0); // 0 < uint.max / 10**77 < 0.5
    if (40 <= shiftLeft) revert UIntOutOfBounds(); // 10**56 < FIX_MAX < 10**57

    shiftLeft += 18;

    uint256 coeff = 10**abs(shiftLeft);
    uint256 shifted = (shiftLeft >= 0) ? x * coeff : _divrnd(x, coeff, rounding);

    return _safeWrap(shifted);
}

/// Divide a uint by a uint192, yielding a uint192
/// This may also fail if the result is MIN_uint192! not fixing this for optimization's sake.
/// @return x / y
// as-ints: x * 1e36 / y
function divFix(uint256 x, uint192 y) pure returns (uint192) {
    // If we didn't have to worry about overflow, we'd just do `return x * 1e36 / _y`
    // If it's safe to do this operation the easy way, do it:
    if (x < uint256(type(uint256).max / FIX_SCALE_SQ)) {
        return _safeWrap(uint256(x * FIX_SCALE_SQ) / y);
    } else {
        return _safeWrap(mulDiv256(x, FIX_SCALE_SQ, y));
    }
}

/// Divide a uint by a uint, yielding a  uint192
/// @return x / y
// as-ints: x * 1e18 / y
function divuu(uint256 x, uint256 y) pure returns (uint192) {
    return _safeWrap(mulDiv256(FIX_SCALE, x, y));
}

/// @return min(x,y)
// as-ints: min(x,y)
function fixMin(uint192 x, uint192 y) pure returns (uint192) {
    return x < y ? x : y;
}

/// @return max(x,y)
// as-ints: max(x,y)
function fixMax(uint192 x, uint192 y) pure returns (uint192) {
    return x > y ? x : y;
}

/// @return absoluteValue(x,y)
// as-ints: absoluteValue(x,y)
function abs(int256 x) pure returns (uint256) {
    return x < 0 ? uint256(-x) : uint256(x);
}

/// Divide two uints, returning a uint, using rounding mode `rounding`.
/// @return numerator / divisor
// as-ints: numerator / divisor
function _divrnd(
    uint256 numerator,
    uint256 divisor,
    RoundingMode rounding
) pure returns (uint256) {
    uint256 result = numerator / divisor;

    if (rounding == FLOOR) return result;

    if (rounding == ROUND) {
        if (numerator % divisor > (divisor - 1) / 2) {
            result++;
        }
    } else {
        if (numerator % divisor > 0) {
            result++;
        }
    }

    return result;
}

library FixLib {
    /// Again, all arithmetic functions fail if and only if the result is out of bounds.

    /// Convert this fixed-point value to a uint. Round towards zero if needed.
    /// @return x
    // as-ints: x / 1e18
    function toUint(uint192 x) internal pure returns (uint136) {
        return toUint(x, FLOOR);
    }

    /// Convert this uint192 to a uint
    /// @return x
    // as-ints: x / 1e18 with rounding
    function toUint(uint192 x, RoundingMode rounding) internal pure returns (uint136) {
        return uint136(_divrnd(uint256(x), FIX_SCALE, rounding));
    }

    /// Return the uint192 shifted to the left by `decimal` digits
    /// (Similar to a bitshift but in base 10)
    /// @return x * 10**decimals
    // as-ints: x * 10**decimals
    function shiftl(uint192 x, int8 decimals) internal pure returns (uint192) {
        return shiftl(x, decimals, FLOOR);
    }

    /// Return the uint192 shifted to the left by `decimal` digits
    /// (Similar to a bitshift but in base 10)
    /// @return x * 10**decimals
    // as-ints: x * 10**decimals
    function shiftl(
        uint192 x,
        int8 decimals,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        // Handle overflow cases
        if (x == 0) return 0;
        if (decimals <= -59) return (rounding == CEIL ? 1 : 0); // 59, because 1e58 > 2**192
        if (58 <= decimals) revert UIntOutOfBounds(); // 58, because x * 1e58 > 2 ** 192 if x != 0

        uint256 coeff = uint256(10**abs(decimals));
        return _safeWrap(decimals >= 0 ? x * coeff : _divrnd(x, coeff, rounding));
    }

    /// Add a uint192 to this uint192
    /// @return x + y
    // as-ints: x + y
    function plus(uint192 x, uint192 y) internal pure returns (uint192) {
        return x + y;
    }

    /// Add a uint to this uint192
    /// @return x + y
    // as-ints: x + y*1e18
    function plusu(uint192 x, uint256 y) internal pure returns (uint192) {
        return _safeWrap(x + y * FIX_SCALE);
    }

    /// Subtract a uint192 from this uint192
    /// @return x - y
    // as-ints: x - y
    function minus(uint192 x, uint192 y) internal pure returns (uint192) {
        return x - y;
    }

    /// Subtract a uint from this uint192
    /// @return x - y
    // as-ints: x - y*1e18
    function minusu(uint192 x, uint256 y) internal pure returns (uint192) {
        return _safeWrap(uint256(x) - uint256(y * FIX_SCALE));
    }

    /// Multiply this uint192 by a uint192
    /// Round truncated values to the nearest available value. 5e-19 rounds away from zero.
    /// @return x * y
    // as-ints: x * y/1e18  [division using ROUND, not FLOOR]
    function mul(uint192 x, uint192 y) internal pure returns (uint192) {
        return mul(x, y, ROUND);
    }

    /// Multiply this uint192 by a uint192
    /// @return x * y
    // as-ints: x * y/1e18
    function mul(
        uint192 x,
        uint192 y,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        return _safeWrap(_divrnd(uint256(x) * uint256(y), FIX_SCALE, rounding));
    }

    /// Multiply this uint192 by a uint
    /// @return x * y
    // as-ints: x * y
    function mulu(uint192 x, uint256 y) internal pure returns (uint192) {
        return _safeWrap(x * y);
    }

    /// Divide this uint192 by a uint192
    /// @return x / y
    // as-ints: x * 1e18 / y
    function div(uint192 x, uint192 y) internal pure returns (uint192) {
        return div(x, y, FLOOR);
    }

    /// Divide this uint192 by a uint192
    /// @return x / y
    // as-ints: x * 1e18 / y
    function div(
        uint192 x,
        uint192 y,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        // Multiply-in FIX_SCALE before dividing by y to preserve precision.
        return _safeWrap(_divrnd(uint256(x) * FIX_SCALE, y, rounding));
    }

    /// Divide this uint192 by a uint
    /// @return x / y
    // as-ints: x / y
    function divu(uint192 x, uint256 y) internal pure returns (uint192) {
        return divu(x, y, FLOOR);
    }

    /// Divide this uint192 by a uint
    /// @return x / y
    // as-ints: x / y
    function divu(
        uint192 x,
        uint256 y,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        return _safeWrap(_divrnd(x, y, rounding));
    }

    uint64 constant FIX_HALF = uint64(FIX_SCALE) / 2;

    /// Raise this uint192 to a nonnegative integer power. Requires that x_ <= FIX_ONE
    /// Gas cost is O(lg(y)), precision is +- 1e-18.
    /// @return x_ ** y
    // as-ints: x_ ** y / 1e18**(y-1)    <- technically correct for y = 0. :D
    function powu(uint192 x_, uint48 y) internal pure returns (uint192) {
        require(x_ <= FIX_ONE);
        if (y == 1) return x_;
        if (x_ == FIX_ONE || y == 0) return FIX_ONE;
        uint256 x = uint256(x_) * FIX_SCALE; // x is D36
        uint256 result = FIX_SCALE_SQ; // result is D36
        while (true) {
            if (y & 1 == 1) result = (result * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ;
            if (y <= 1) break;
            y = (y >> 1);
            x = (x * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ;
        }
        return _safeWrap(result / FIX_SCALE);
    }

    /// Comparison operators...
    function lt(uint192 x, uint192 y) internal pure returns (bool) {
        return x < y;
    }

    function lte(uint192 x, uint192 y) internal pure returns (bool) {
        return x <= y;
    }

    function gt(uint192 x, uint192 y) internal pure returns (bool) {
        return x > y;
    }

    function gte(uint192 x, uint192 y) internal pure returns (bool) {
        return x >= y;
    }

    function eq(uint192 x, uint192 y) internal pure returns (bool) {
        return x == y;
    }

    function neq(uint192 x, uint192 y) internal pure returns (bool) {
        return x != y;
    }

    /// Return whether or not this uint192 is less than epsilon away from y.
    /// @return |x - y| < epsilon
    // as-ints: |x - y| < epsilon
    function near(
        uint192 x,
        uint192 y,
        uint192 epsilon
    ) internal pure returns (bool) {
        uint192 diff = x <= y ? y - x : x - y;
        return diff < epsilon;
    }

    // ================ Chained Operations ================
    // The operation foo_bar() always means:
    //   Do foo() followed by bar(), and overflow only if the _end_ result doesn't fit in an uint192

    /// Shift this uint192 left by `decimals` digits, and convert to a uint
    /// @return x * 10**decimals
    // as-ints: x * 10**(decimals - 18)
    function shiftl_toUint(uint192 x, int8 decimals) internal pure returns (uint256) {
        return shiftl_toUint(x, decimals, FLOOR);
    }

    /// Shift this uint192 left by `decimals` digits, and convert to a uint.
    /// @return x * 10**decimals
    // as-ints: x * 10**(decimals - 18)
    function shiftl_toUint(
        uint192 x,
        int8 decimals,
        RoundingMode rounding
    ) internal pure returns (uint256) {
        // Handle overflow cases
        if (x == 0) return 0; // always computable, no matter what decimals is
        if (decimals <= -42) return (rounding == CEIL ? 1 : 0);
        if (96 <= decimals) revert UIntOutOfBounds();

        decimals -= 18; // shift so that toUint happens at the same time.

        uint256 coeff = uint256(10**abs(decimals));
        return decimals >= 0 ? uint256(x * coeff) : uint256(_divrnd(x, coeff, rounding));
    }

    /// Multiply this uint192 by a uint, and output the result as a uint
    /// @return x * y
    // as-ints: x * y / 1e18
    function mulu_toUint(uint192 x, uint256 y) internal pure returns (uint256) {
        return mulDiv256(uint256(x), y, FIX_SCALE);
    }

    /// Multiply this uint192 by a uint, and output the result as a uint
    /// @return x * y
    // as-ints: x * y / 1e18
    function mulu_toUint(
        uint192 x,
        uint256 y,
        RoundingMode rounding
    ) internal pure returns (uint256) {
        return mulDiv256(uint256(x), y, FIX_SCALE, rounding);
    }

    /// Multiply this uint192 by a uint192 and output the result as a uint
    /// @return x * y
    // as-ints: x * y / 1e36
    function mul_toUint(uint192 x, uint192 y) internal pure returns (uint256) {
        return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ);
    }

    /// Multiply this uint192 by a uint192 and output the result as a uint
    /// @return x * y
    // as-ints: x * y / 1e36
    function mul_toUint(
        uint192 x,
        uint192 y,
        RoundingMode rounding
    ) internal pure returns (uint256) {
        return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ, rounding);
    }

    /// Compute x * y / z avoiding intermediate overflow
    /// @dev Only use if you need to avoid overflow; costlier than x * y / z
    /// @return x * y / z
    // as-ints: x * y / z
    function muluDivu(
        uint192 x,
        uint256 y,
        uint256 z
    ) internal pure returns (uint192) {
        return muluDivu(x, y, z, FLOOR);
    }

    /// Compute x * y / z, avoiding intermediate overflow
    /// @dev Only use if you need to avoid overflow; costlier than x * y / z
    /// @return x * y / z
    // as-ints: x * y / z
    function muluDivu(
        uint192 x,
        uint256 y,
        uint256 z,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        return _safeWrap(mulDiv256(x, y, z, rounding));
    }

    /// Compute x * y / z on Fixes, avoiding intermediate overflow
    /// @dev Only use if you need to avoid overflow; costlier than x * y / z
    /// @return x * y / z
    // as-ints: x * y / z
    function mulDiv(
        uint192 x,
        uint192 y,
        uint192 z
    ) internal pure returns (uint192) {
        return mulDiv(x, y, z, FLOOR);
    }

    /// Compute x * y / z on Fixes, avoiding intermediate overflow
    /// @dev Only use if you need to avoid overflow; costlier than x * y / z
    /// @return x * y / z
    // as-ints: x * y / z
    function mulDiv(
        uint192 x,
        uint192 y,
        uint192 z,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        return _safeWrap(mulDiv256(x, y, z, rounding));
    }
}

// ================ a couple pure-uint helpers================
// as-ints comments are omitted here, because they're the same as @return statements, because
// these are all pure uint functions

/// Return (x*y/z), avoiding intermediate overflow.
//  Adapted from sources:
//    https://medium.com/coinmonks/4db014e080b1, https://medium.com/wicketh/afa55870a65
//    and quite a few of the other excellent "Mathemagic" posts from https://medium.com/wicketh
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return result x * y / z
function mulDiv256(
    uint256 x,
    uint256 y,
    uint256 z
) pure returns (uint256 result) {
    unchecked {
        (uint256 hi, uint256 lo) = fullMul(x, y);
        if (hi >= z) revert UIntOutOfBounds();
        uint256 mm = mulmod(x, y, z);
        if (mm > lo) hi -= 1;
        lo -= mm;
        uint256 pow2 = z & (0 - z);
        z /= pow2;
        lo /= pow2;
        lo += hi * ((0 - pow2) / pow2 + 1);
        uint256 r = 1;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        result = lo * r;
    }
}

/// Return (x*y/z), avoiding intermediate overflow.
/// @dev Only use if you need to avoid overflow; costlier than x * y / z
/// @return x * y / z
function mulDiv256(
    uint256 x,
    uint256 y,
    uint256 z,
    RoundingMode rounding
) pure returns (uint256) {
    uint256 result = mulDiv256(x, y, z);
    if (rounding == FLOOR) return result;

    uint256 mm = mulmod(x, y, z);
    if (rounding == CEIL) {
        if (mm > 0) result += 1;
    } else {
        if (mm > ((z - 1) / 2)) result += 1; // z should be z-1
    }
    return result;
}

/// Return (x*y) as a "virtual uint512" (lo, hi), representing (hi*2**256 + lo)
///   Adapted from sources:
///   https://medium.com/wicketh/27650fec525d, https://medium.com/coinmonks/4db014e080b1
/// @dev Intended to be internal to this library
/// @return hi (hi, lo) satisfies  hi*(2**256) + lo == x * y
/// @return lo (paired with `hi`)
function fullMul(uint256 x, uint256 y) pure returns (uint256 hi, uint256 lo) {
    unchecked {
        uint256 mm = mulmod(x, y, uint256(0) - uint256(1));
        lo = x * y;
        hi = mm - lo;
        if (mm < lo) hi -= 1;
    }
}

File 28 of 36 : Throttle.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "./Fixed.sol";

uint48 constant ONE_HOUR = 3600; // {seconds/hour}

/**
 * @title ThrottleLib
 * A library that implements a usage throttle that can be used to ensure net issuance
 * or net redemption for an RToken never exceeds some bounds per unit time (hour).
 *
 * It is expected for the RToken to use this library with two instances, one for issuance
 * and one for redemption. Issuance causes the available redemption amount to increase, and
 * visa versa.
 */
library ThrottleLib {
    using FixLib for uint192;

    struct Params {
        uint256 amtRate; // {qRTok/hour} a quantity of RToken hourly; cannot be 0
        uint192 pctRate; // {1/hour} a fraction of RToken hourly; can be 0
    }

    struct Throttle {
        // === Gov params ===
        Params params;
        // === Cache ===
        uint48 lastTimestamp; // {seconds}
        uint256 lastAvailable; // {qRTok}
    }

    /// Reverts if usage amount exceeds available amount
    /// @param supply {qRTok} Total RToken supply beforehand
    /// @param amount {qRTok} Amount of RToken to use. Should be negative for the issuance
    ///   throttle during redemption and for the redemption throttle during issuance.
    function useAvailable(
        Throttle storage throttle,
        uint256 supply,
        int256 amount
    ) internal {
        // untestable: amtRate will always be greater > 0 due to previous validations
        if (throttle.params.amtRate == 0 && throttle.params.pctRate == 0) return;

        // Calculate hourly limit
        uint256 limit = hourlyLimit(throttle, supply); // {qRTok}

        // Calculate available amount before supply change
        uint256 available = currentlyAvailable(throttle, limit);

        // Calculate available amount after supply change
        if (amount > 0) {
            require(uint256(amount) <= available, "supply change throttled");
            available -= uint256(amount);
            // untestable: the final else statement, amount will never be 0
        } else if (amount < 0) {
            available += uint256(-amount);
        }

        // Update cached values
        throttle.lastAvailable = available;
        throttle.lastTimestamp = uint48(block.timestamp);
    }

    /// @param limit {qRTok/hour} The hourly limit
    /// @return available {qRTok} Amount currently available for consumption
    function currentlyAvailable(Throttle storage throttle, uint256 limit)
        internal
        view
        returns (uint256 available)
    {
        uint48 delta = uint48(block.timestamp) - throttle.lastTimestamp; // {seconds}
        available = throttle.lastAvailable + (limit * delta) / ONE_HOUR;
        if (available > limit) available = limit;
    }

    /// @return limit {qRTok} The hourly limit
    function hourlyLimit(Throttle storage throttle, uint256 supply)
        internal
        view
        returns (uint256 limit)
    {
        Params storage params = throttle.params;

        // Calculate hourly limit as: max(params.amtRate, supply.mul(params.pctRate))
        limit = (supply * params.pctRate) / FIX_ONE_256; // {qRTok}
        if (params.amtRate > limit) limit = params.amtRate;
    }
}

File 29 of 36 : AppreciatingFiatCollateral.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../interfaces/IAsset.sol";
import "../../libraries/Fixed.sol";
import "./FiatCollateral.sol";
import "./Asset.sol";
import "./OracleLib.sol";

/**
 * @title AppreciatingFiatCollateral
 * Collateral that may need revenue hiding to become truly "up only"
 *
 * For: {tok} != {ref}, {ref} != {target}, {target} == {UoA}
 * Inheritors _must_ implement _underlyingRefPerTok()
 * Can be easily extended by (optionally) re-implementing:
 *   - tryPrice()
 *   - refPerTok()
 *   - targetPerRef()
 *   - claimRewards()
 * Should not have to re-implement any other methods.
 *
 * Can intentionally disable default checks by setting config.defaultThreshold to 0
 * Can intentionally do no revenue hiding by setting revenueHiding to 0
 */
abstract contract AppreciatingFiatCollateral is FiatCollateral {
    using FixLib for uint192;
    using OracleLib for AggregatorV3Interface;

    // revenueShowing = FIX_ONE.minus(revenueHiding)
    uint192 public immutable revenueShowing; // {1} The maximum fraction of refPerTok to show

    // does not become nonzero until after first refresh()
    uint192 public exposedReferencePrice; // {ref/tok} max ref price observed, sub revenue hiding

    /// @param config.chainlinkFeed Feed units: {UoA/ref}
    /// @param revenueHiding {1} A value like 1e-6 that represents the maximum refPerTok to hide
    constructor(CollateralConfig memory config, uint192 revenueHiding) FiatCollateral(config) {
        require(revenueHiding < FIX_ONE, "revenueHiding out of range");
        revenueShowing = FIX_ONE.minus(revenueHiding);
    }

    /// Can revert, used by other contract functions in order to catch errors
    /// Should not return FIX_MAX for low
    /// Should only return FIX_MAX for high if low is 0
    /// @dev Override this when pricing is more complicated than just a single oracle
    /// @return low {UoA/tok} The low price estimate
    /// @return high {UoA/tok} The high price estimate
    /// @return pegPrice {target/ref} The actual price observed in the peg
    function tryPrice()
        external
        view
        virtual
        override
        returns (
            uint192 low,
            uint192 high,
            uint192 pegPrice
        )
    {
        // {target/ref} = {UoA/ref} / {UoA/target} (1)
        pegPrice = chainlinkFeed.price(oracleTimeout);

        // {UoA/tok} = {target/ref} * {ref/tok} * {UoA/target} (1)
        uint192 p = pegPrice.mul(_underlyingRefPerTok());
        uint192 err = p.mul(oracleError, CEIL);

        low = p - err;
        high = p + err;
        // assert(low <= high); obviously true just by inspection
    }

    /// Should not revert
    /// Refresh exchange rates and update default status.
    /// @dev Should not need to override: can handle collateral with variable refPerTok()
    function refresh() public virtual override {
        if (alreadyDefaulted()) {
            // continue to update rates
            exposedReferencePrice = _underlyingRefPerTok().mul(revenueShowing);
            return;
        }

        CollateralStatus oldStatus = status();

        // Check for hard default
        // must happen before tryPrice() call since `refPerTok()` returns a stored value

        // revenue hiding: do not DISABLE if drawdown is small
        uint192 underlyingRefPerTok = _underlyingRefPerTok();

        // {ref/tok} = {ref/tok} * {1}
        uint192 hiddenReferencePrice = underlyingRefPerTok.mul(revenueShowing);

        // uint192(<) is equivalent to Fix.lt
        if (underlyingRefPerTok < exposedReferencePrice) {
            exposedReferencePrice = hiddenReferencePrice;
            markStatus(CollateralStatus.DISABLED);
        } else if (hiddenReferencePrice > exposedReferencePrice) {
            exposedReferencePrice = hiddenReferencePrice;
        }

        // Check for soft default + save prices
        try this.tryPrice() returns (uint192 low, uint192 high, uint192 pegPrice) {
            // {UoA/tok}, {UoA/tok}, {target/ref}
            // (0, 0) is a valid price; (0, FIX_MAX) is unpriced

            // Save prices if priced
            if (high < FIX_MAX) {
                savedLowPrice = low;
                savedHighPrice = high;
                lastSave = uint48(block.timestamp);
            } else {
                // must be unpriced
                assert(low == 0);
            }

            // If the price is below the default-threshold price, default eventually
            // uint192(+/-) is the same as Fix.plus/minus
            if (pegPrice < pegBottom || pegPrice > pegTop || low == 0) {
                markStatus(CollateralStatus.IFFY);
            } else {
                markStatus(CollateralStatus.SOUND);
            }
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string
            markStatus(CollateralStatus.IFFY);
        }

        CollateralStatus newStatus = status();
        if (oldStatus != newStatus) {
            emit CollateralStatusChanged(oldStatus, newStatus);
        }
    }

    /// @return {ref/tok} Exposed quantity of whole reference units per whole collateral tokens
    function refPerTok() public view virtual override returns (uint192) {
        return exposedReferencePrice;
    }

    /// Should update in inheritors
    /// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens
    function _underlyingRefPerTok() internal view virtual returns (uint192);
}

File 30 of 36 : Asset.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../interfaces/IAsset.sol";
import "./OracleLib.sol";

contract Asset is IAsset {
    using FixLib for uint192;
    using OracleLib for AggregatorV3Interface;

    AggregatorV3Interface public immutable chainlinkFeed; // {UoA/tok}

    IERC20Metadata public immutable erc20;

    uint8 public immutable erc20Decimals;

    uint192 public immutable override maxTradeVolume; // {UoA}

    uint48 public immutable oracleTimeout; // {s}

    uint192 public immutable oracleError; // {1}

    // === Lot price ===

    uint48 public immutable priceTimeout; // {s} The period over which `savedHighPrice` decays to 0

    uint192 public savedLowPrice; // {UoA/tok} The low price of the token during the last update

    uint192 public savedHighPrice; // {UoA/tok} The high price of the token during the last update

    uint48 public lastSave; // {s} The timestamp when prices were last saved

    /// @param priceTimeout_ {s} The number of seconds over which savedHighPrice decays to 0
    /// @param chainlinkFeed_ Feed units: {UoA/tok}
    /// @param oracleError_ {1} The % the oracle feed can be off by
    /// @param maxTradeVolume_ {UoA} The max trade volume, in UoA
    /// @param oracleTimeout_ {s} The number of seconds until a oracle value becomes invalid
    constructor(
        uint48 priceTimeout_,
        AggregatorV3Interface chainlinkFeed_,
        uint192 oracleError_,
        IERC20Metadata erc20_,
        uint192 maxTradeVolume_,
        uint48 oracleTimeout_
    ) {
        require(priceTimeout_ > 0, "price timeout zero");
        require(address(chainlinkFeed_) != address(0), "missing chainlink feed");
        require(oracleError_ > 0 && oracleError_ < FIX_ONE, "oracle error out of range");
        require(address(erc20_) != address(0), "missing erc20");
        require(maxTradeVolume_ > 0, "invalid max trade volume");
        require(oracleTimeout_ > 0, "oracleTimeout zero");
        priceTimeout = priceTimeout_;
        chainlinkFeed = chainlinkFeed_;
        oracleError = oracleError_;
        erc20 = erc20_;
        erc20Decimals = erc20.decimals();
        maxTradeVolume = maxTradeVolume_;
        oracleTimeout = oracleTimeout_;
    }

    /// Can revert, used by other contract functions in order to catch errors
    /// Should not return FIX_MAX for low
    /// Should only return FIX_MAX for high if low is 0
    /// @dev The third (unused) variable is only here for compatibility with Collateral
    /// @return low {UoA/tok} The low price estimate
    /// @return high {UoA/tok} The high price estimate
    function tryPrice()
        external
        view
        virtual
        returns (
            uint192 low,
            uint192 high,
            uint192
        )
    {
        uint192 p = chainlinkFeed.price(oracleTimeout); // {UoA/tok}
        uint192 err = p.mul(oracleError, CEIL);
        // assert(low <= high); obviously true just by inspection
        return (p - err, p + err, 0);
    }

    /// Should not revert
    /// Refresh saved prices
    function refresh() public virtual override {
        try this.tryPrice() returns (uint192 low, uint192 high, uint192) {
            // {UoA/tok}, {UoA/tok}
            // (0, 0) is a valid price; (0, FIX_MAX) is unpriced

            // Save prices if priced
            if (high < FIX_MAX) {
                savedLowPrice = low;
                savedHighPrice = high;
                lastSave = uint48(block.timestamp);
            } else {
                // must be unpriced
                assert(low == 0);
            }
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string
        }
    }

    /// Should not revert
    /// @dev Should be general enough to not need to be overridden
    /// @return {UoA/tok} The lower end of the price estimate
    /// @return {UoA/tok} The upper end of the price estimate
    function price() public view virtual returns (uint192, uint192) {
        try this.tryPrice() returns (uint192 low, uint192 high, uint192) {
            assert(low <= high);
            return (low, high);
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string
            return (0, FIX_MAX);
        }
    }

    /// Should not revert
    /// lotLow should be nonzero when the asset might be worth selling
    /// @dev Should be general enough to not need to be overridden
    /// @return lotLow {UoA/tok} The lower end of the lot price estimate
    /// @return lotHigh {UoA/tok} The upper end of the lot price estimate
    function lotPrice() external view virtual returns (uint192 lotLow, uint192 lotHigh) {
        try this.tryPrice() returns (uint192 low, uint192 high, uint192) {
            // if the price feed is still functioning, use that
            lotLow = low;
            lotHigh = high;
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string

            // if the price feed is broken, use a decayed historical value

            uint48 delta = uint48(block.timestamp) - lastSave; // {s}
            if (delta >= priceTimeout) return (0, 0); // no price after timeout elapses

            // {1} = {s} / {s}
            uint192 lotMultiplier = divuu(priceTimeout - delta, priceTimeout);

            // {UoA/tok} = {UoA/tok} * {1}
            lotLow = savedLowPrice.mul(lotMultiplier);
            lotHigh = savedHighPrice.mul(lotMultiplier);
        }
        assert(lotLow <= lotHigh);
    }

    /// @return {tok} The balance of the ERC20 in whole tokens
    function bal(address account) external view virtual returns (uint192) {
        return shiftl_toFix(erc20.balanceOf(account), -int8(erc20Decimals));
    }

    /// @return If the asset is an instance of ICollateral or not
    function isCollateral() external pure virtual returns (bool) {
        return false;
    }

    // solhint-disable no-empty-blocks

    /// Claim rewards earned by holding a balance of the ERC20 token
    /// @dev Use delegatecall
    function claimRewards() external virtual {}

    // solhint-enable no-empty-blocks
}

File 31 of 36 : CvxStableCollateral.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "contracts/interfaces/IAsset.sol";
import "contracts/libraries/Fixed.sol";
import "contracts/plugins/assets/AppreciatingFiatCollateral.sol";
import "./vendor/IConvexStakingWrapper.sol";
import "./PoolTokens.sol";

/**
 * @title CvxStableCollateral
 *  This plugin contract is fully general to any number of tokens in a plain stable pool,
 *  with between 1 and 2 oracles per each token. Stable means only like-kind pools.
 *
 * tok = ConvexStakingWrapper(cvxStablePlainPool)
 * ref = cvxStablePlainPool pool invariant
 * tar = USD
 * UoA = USD
 */
contract CvxStableCollateral is AppreciatingFiatCollateral, PoolTokens {
    using OracleLib for AggregatorV3Interface;
    using FixLib for uint192;

    /// @dev config Unused members: chainlinkFeed, oracleError, oracleTimeout
    /// @dev config.erc20 should be a IConvexStakingWrapper
    constructor(
        CollateralConfig memory config,
        uint192 revenueHiding,
        PTConfiguration memory ptConfig
    ) AppreciatingFiatCollateral(config, revenueHiding) PoolTokens(ptConfig) {
        require(config.defaultThreshold > 0, "defaultThreshold zero");
    }

    /// Can revert, used by other contract functions in order to catch errors
    /// Should not return FIX_MAX for low
    /// Should only return FIX_MAX for high if low is 0
    /// @dev Override this when pricing is more complicated than just a single oracle
    /// @return low {UoA/tok} The low price estimate
    /// @return high {UoA/tok} The high price estimate
    /// @return {target/ref} Unused. Always 0
    function tryPrice()
        external
        view
        virtual
        override
        returns (
            uint192 low,
            uint192 high,
            uint192
        )
    {
        // {UoA}
        (uint192 aumLow, uint192 aumHigh) = totalBalancesValue();

        // {tok}
        uint192 supply = shiftl_toFix(lpToken.totalSupply(), -int8(lpToken.decimals()));
        // We can always assume that the total supply is non-zero

        // {UoA/tok} = {UoA} / {tok}
        low = aumLow.div(supply, FLOOR);
        high = aumHigh.div(supply, CEIL);
        assert(low <= high); // not obviously true just by inspection

        return (low, high, 0);
    }

    /// Should not revert
    /// Refresh exchange rates and update default status.
    /// Have to override to add custom default checks
    function refresh() public virtual override {
        if (alreadyDefaulted()) {
            // continue to update rates
            exposedReferencePrice = _underlyingRefPerTok().mul(revenueShowing);
            return;
        }

        CollateralStatus oldStatus = status();

        // Check for hard default
        // must happen before tryPrice() call since `refPerTok()` returns a stored value

        // revenue hiding: do not DISABLE if drawdown is small
        uint192 underlyingRefPerTok = _underlyingRefPerTok();

        // {ref/tok} = {ref/tok} * {1}
        uint192 hiddenReferencePrice = underlyingRefPerTok.mul(revenueShowing);

        // uint192(<) is equivalent to Fix.lt
        if (underlyingRefPerTok < exposedReferencePrice) {
            exposedReferencePrice = hiddenReferencePrice;
            markStatus(CollateralStatus.DISABLED);
        } else if (hiddenReferencePrice > exposedReferencePrice) {
            exposedReferencePrice = hiddenReferencePrice;
        }

        // Check for soft default + save prices
        try this.tryPrice() returns (uint192 low, uint192 high, uint192) {
            // {UoA/tok}, {UoA/tok}, {UoA/tok}
            // (0, 0) is a valid price; (0, FIX_MAX) is unpriced

            // Save prices if priced
            if (high < FIX_MAX) {
                savedLowPrice = low;
                savedHighPrice = high;
                lastSave = uint48(block.timestamp);
            } else {
                // must be unpriced
                assert(low == 0);
            }

            // If the price is below the default-threshold price, default eventually
            // uint192(+/-) is the same as Fix.plus/minus
            if (low == 0 || _anyDepeggedInPool() || _anyDepeggedOutsidePool()) {
                markStatus(CollateralStatus.IFFY);
            } else {
                markStatus(CollateralStatus.SOUND);
            }
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string
            markStatus(CollateralStatus.IFFY);
        }

        CollateralStatus newStatus = status();
        if (oldStatus != newStatus) {
            emit CollateralStatusChanged(oldStatus, newStatus);
        }
    }

    /// Claim rewards earned by holding a balance of the ERC20 token
    /// @dev Use delegatecall
    function claimRewards() external override(Asset, IRewardable) {
        IConvexStakingWrapper wrapper = IConvexStakingWrapper(address(erc20));
        IERC20 cvx = IERC20(wrapper.cvx());
        IERC20 crv = IERC20(wrapper.crv());
        uint256 cvxOldBal = cvx.balanceOf(address(this));
        uint256 crvOldBal = crv.balanceOf(address(this));
        wrapper.getReward(address(this));
        emit RewardsClaimed(cvx, cvx.balanceOf(address(this)) - cvxOldBal);
        emit RewardsClaimed(crv, crv.balanceOf(address(this)) - crvOldBal);
    }

    // === Internal ===

    /// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens
    function _underlyingRefPerTok() internal view virtual override returns (uint192) {
        return _safeWrap(curvePool.get_virtual_price());
    }

    // Override this later to implement non-stable pools
    function _anyDepeggedInPool() internal view virtual returns (bool) {
        // Check reference token oracles
        for (uint8 i = 0; i < nTokens; i++) {
            try this.tokenPrice(i) returns (uint192 low, uint192 high) {
                // {UoA/tok} = {UoA/tok} + {UoA/tok}
                uint192 mid = (low + high) / 2;

                // If the price is below the default-threshold price, default eventually
                // uint192(+/-) is the same as Fix.plus/minus
                if (mid < pegBottom || mid > pegTop) return true;
            } catch (bytes memory errData) {
                // see: docs/solidity-style.md#Catching-Empty-Data
                if (errData.length == 0) revert(); // solhint-disable-line reason-string
                return true;
            }
        }

        return false;
    }

    // Override this in child classes to implement metapools
    function _anyDepeggedOutsidePool() internal view virtual returns (bool) {
        return false;
    }
}

File 32 of 36 : CvxStableMetapoolCollateral.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.17;

import "./CvxStableCollateral.sol";

// solhint-disable no-empty-blocks
interface ICurveMetaPool is ICurvePool, IERC20Metadata {

}

/**
 * @title CvxStableMetapoolCollateral
 *  This plugin contract is intended for 2-token stable metapools that
 *  DO NOT involve RTokens, such as LUSD-fraxBP or MIM-3CRV.
 *
 * tok = ConvexStakingWrapper(PairedUSDToken/USDBasePool)
 * ref = PairedUSDToken/USDBasePool pool invariant
 * tar = USD
 * UoA = USD
 */
contract CvxStableMetapoolCollateral is CvxStableCollateral {
    using OracleLib for AggregatorV3Interface;
    using FixLib for uint192;

    ICurveMetaPool public immutable metapoolToken; // top-level LP token + CurvePool

    IERC20Metadata public immutable pairedToken; // the token paired with ptConfig.lpToken

    uint192 public immutable pairedTokenPegBottom; // {target/ref} pegBottom but for paired token

    uint192 public immutable pairedTokenPegTop; // {target/ref} pegTop but for paired token

    /// @param config.chainlinkFeed Feed units: {UoA/pairedTok}
    /// @dev config.chainlinkFeed/oracleError/oracleTimeout should be set for paired token
    /// @dev config.erc20 should be a IConvexStakingWrapper
    constructor(
        CollateralConfig memory config,
        uint192 revenueHiding,
        PTConfiguration memory ptConfig,
        ICurveMetaPool metapoolToken_,
        uint192 pairedTokenDefaultThreshold_
    ) CvxStableCollateral(config, revenueHiding, ptConfig) {
        require(address(metapoolToken_) != address(0), "metapoolToken address is zero");
        require(
            pairedTokenDefaultThreshold_ > 0 && pairedTokenDefaultThreshold_ < FIX_ONE,
            "pairedTokenDefaultThreshold out of bounds"
        );
        metapoolToken = metapoolToken_;
        pairedToken = IERC20Metadata(metapoolToken.coins(0)); // like LUSD or MIM

        // {target/ref} = {target/ref} * {1}
        uint192 peg = targetPerRef(); // {target/ref}
        uint192 delta = peg.mul(pairedTokenDefaultThreshold_);
        pairedTokenPegBottom = peg - delta;
        pairedTokenPegTop = peg + delta;

        // Sanity checks we have the correct pool
        assert(address(pairedToken) != address(0));
        assert(metapoolToken.coins(1) == address(lpToken));
    }

    /// Can revert, used by other contract functions in order to catch errors
    /// Should not return FIX_MAX for low
    /// Should only return FIX_MAX for high if low is 0
    /// @dev Override this when pricing is more complicated than just a single oracle
    /// @return low {UoA/tok} The low price estimate
    /// @return high {UoA/tok} The high price estimate
    /// @return pegPrice {target/ref} The actual price observed in the peg
    function tryPrice()
        external
        view
        virtual
        override
        returns (
            uint192 low,
            uint192 high,
            uint192 pegPrice
        )
    {
        // {UoA/pairedTok}
        uint192 lowPaired;
        uint192 highPaired = FIX_MAX;
        try this.tryPairedPrice() returns (uint192 lowPaired_, uint192 highPaired_) {
            lowPaired = lowPaired_;
            highPaired = highPaired_;
        } catch {}

        // {UoA}
        (uint192 aumLow, uint192 aumHigh) = _metapoolBalancesValue(lowPaired, highPaired);

        // {tok}
        uint192 supply = shiftl_toFix(metapoolToken.totalSupply(), -int8(metapoolToken.decimals()));
        // We can always assume that the total supply is non-zero

        // {UoA/tok} = {UoA} / {tok}
        low = aumLow.div(supply, FLOOR);
        high = aumHigh.div(supply, CEIL);
        assert(low <= high); // not obviously true just by inspection

        return (low, high, 0);
    }

    /// Can revert, used by `_anyDepeggedOutsidePool()`
    /// Should not return FIX_MAX for low
    /// Should only return FIX_MAX for high if low is 0
    /// @return lowPaired {UoA/pairedTok} The low price estimate of the paired token
    /// @return highPaired {UoA/pairedTok} The high price estimate of the paired token
    function tryPairedPrice() public view virtual returns (uint192 lowPaired, uint192 highPaired) {
        uint192 p = chainlinkFeed.price(oracleTimeout); // {UoA/pairedTok}
        uint192 delta = p.mul(oracleError, CEIL);
        return (p - delta, p + delta);
    }

    // === Internal ===

    /// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens
    function _underlyingRefPerTok() internal view override returns (uint192) {
        return _safeWrap(metapoolToken.get_virtual_price());
    }

    // Check for defaults outside the pool
    function _anyDepeggedOutsidePool() internal view virtual override returns (bool) {
        try this.tryPairedPrice() returns (uint192 low, uint192 high) {
            // {UoA/tok} = {UoA/tok} + {UoA/tok}
            uint192 mid = (low + high) / 2;

            // If the price is below the default-threshold price, default eventually
            // uint192(+/-) is the same as Fix.plus/minus
            if (mid < pairedTokenPegBottom || mid > pairedTokenPegTop) return true;
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string
            return true;
        }
        return false;
    }

    /// @param lowPaired {UoA/pairedTok}
    /// @param highPaired {UoA/pairedTok}
    /// @return aumLow {UoA}
    /// @return aumHigh {UoA}
    function _metapoolBalancesValue(uint192 lowPaired, uint192 highPaired)
        internal
        view
        returns (uint192 aumLow, uint192 aumHigh)
    {
        // {UoA}
        (uint192 underlyingAumLow, uint192 underlyingAumHigh) = totalBalancesValue();

        // {tokUnderlying}
        uint192 underlyingSupply = shiftl_toFix(lpToken.totalSupply(), -int8(lpToken.decimals()));

        // {UoA/tokUnderlying} = {UoA} / {tokUnderlying}
        uint192 underlyingLow = underlyingAumLow.div(underlyingSupply, FLOOR);
        uint192 underlyingHigh = underlyingAumHigh.div(underlyingSupply, CEIL);

        // {tokUnderlying}
        uint192 balUnderlying = shiftl_toFix(metapoolToken.balances(1), -int8(lpToken.decimals()));

        // {UoA} = {UoA/tokUnderlying} * {tokUnderlying}
        aumLow = underlyingLow.mul(balUnderlying, FLOOR);
        aumHigh = underlyingHigh.mul(balUnderlying, CEIL);

        // {pairedTok}
        uint192 pairedBal = shiftl_toFix(metapoolToken.balances(0), -int8(pairedToken.decimals()));

        // Add-in contribution from pairedTok
        // {UoA} = {UoA} + {UoA/pairedTok} * {pairedTok}
        aumLow += lowPaired.mul(pairedBal, FLOOR);

        // Add-in high part carefully
        uint192 toAdd = safeMul(highPaired, pairedBal, CEIL);
        if (aumHigh + uint256(toAdd) >= FIX_MAX) aumHigh = FIX_MAX;
        else aumHigh += toAdd;
    }

    /// Multiply two fixes, rounding up to FIX_MAX and down to 0
    /// @param a First param to multiply
    /// @param b Second param to multiply
    function safeMul(
        uint192 a,
        uint192 b,
        RoundingMode rounding
    ) internal pure returns (uint192) {
        // untestable:
        //      a will never = 0 here because of the check in _price()
        if (a == 0 || b == 0) return 0;
        // untestable:
        //      a = FIX_MAX iff b = 0
        if (a == FIX_MAX || b == FIX_MAX) return FIX_MAX;

        // return FIX_MAX instead of throwing overflow errors.
        unchecked {
            // p and mul *are* Fix values, so have 18 decimals (D18)
            uint256 rawDelta = uint256(b) * a; // {D36} = {D18} * {D18}
            // if we overflowed, then return FIX_MAX
            if (rawDelta / b != a) return FIX_MAX;
            uint256 shiftDelta = rawDelta;

            // add in rounding
            if (rounding == RoundingMode.ROUND) shiftDelta += (FIX_ONE / 2);
            else if (rounding == RoundingMode.CEIL) shiftDelta += FIX_ONE - 1;

            // untestable (here there be dragons):
            // (below explanation is for the ROUND case, but it extends to the FLOOR/CEIL too)
            //          A)  shiftDelta = rawDelta + (FIX_ONE / 2)
            //      shiftDelta overflows if:
            //          B)  shiftDelta = MAX_UINT256 - FIX_ONE/2 + 1
            //              rawDelta + (FIX_ONE/2) = MAX_UINT256 - FIX_ONE/2 + 1
            //              b * a = MAX_UINT256 - FIX_ONE + 1
            //      therefore shiftDelta overflows if:
            //          C)  b = (MAX_UINT256 - FIX_ONE + 1) / a
            //      MAX_UINT256 ~= 1e77 , FIX_MAX ~= 6e57 (6e20 difference in magnitude)
            //      a <= 1e21 (MAX_TARGET_AMT)
            //      a must be between 1e19 & 1e20 in order for b in (C) to be uint192,
            //      but a would have to be < 1e18 in order for (A) to overflow
            if (shiftDelta < rawDelta) return FIX_MAX;

            // return FIX_MAX if return result would truncate
            if (shiftDelta / FIX_ONE > FIX_MAX) return FIX_MAX;

            // return _div(rawDelta, FIX_ONE, rounding)
            return uint192(shiftDelta / FIX_ONE); // {D18} = {D36} / {D18}
        }
    }
}

File 33 of 36 : PoolTokens.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.17;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "contracts/plugins/assets/OracleLib.sol";
import "contracts/libraries/Fixed.sol";

// solhint-disable func-name-mixedcase
interface ICurvePool {
    // For Curve Plain Pools and V2 Metapools
    function coins(uint256) external view returns (address);

    // Only exists in Curve Lending Pools
    function underlying_coins(uint256) external view returns (address);

    // Only exists in V1 Curve Metapools; not used currently
    function base_coins(uint256) external view returns (address);

    function balances(uint256) external view returns (uint256);

    function get_virtual_price() external view returns (uint256);

    function token() external view returns (address);

    function exchange(
        int128,
        int128,
        uint256,
        uint256
    ) external;
}

// solhint-enable func-name-mixedcase

/// Supports CvxCurve non-meta pools for up to 4 tokens
contract PoolTokens {
    using OracleLib for AggregatorV3Interface;
    using FixLib for uint192;

    error WrongIndex(uint8 maxLength);
    error NoToken(uint8 tokenNumber);

    enum CurvePoolType {
        Plain,
        Lending,
        Metapool // not supported via this class. parent class handles metapool math
    }

    // === State (Immutable) ===

    ICurvePool public immutable curvePool;
    IERC20Metadata public immutable lpToken;
    uint8 internal immutable nTokens;

    IERC20Metadata internal immutable token0;
    IERC20Metadata internal immutable token1;
    IERC20Metadata internal immutable token2;
    IERC20Metadata internal immutable token3;

    // For each token, we maintain up to two feeds/timeouts/errors
    // The data below would normally be a struct, but we want bytecode substitution

    AggregatorV3Interface internal immutable _t0feed0;
    AggregatorV3Interface internal immutable _t0feed1;
    uint48 internal immutable _t0timeout0; // {s}
    uint48 internal immutable _t0timeout1; // {s}
    uint192 internal immutable _t0error0; // {1}
    uint192 internal immutable _t0error1; // {1}

    AggregatorV3Interface internal immutable _t1feed0;
    AggregatorV3Interface internal immutable _t1feed1;
    uint48 internal immutable _t1timeout0; // {s}
    uint48 internal immutable _t1timeout1; // {s}
    uint192 internal immutable _t1error0; // {1}
    uint192 internal immutable _t1error1; // {1}

    AggregatorV3Interface internal immutable _t2feed0;
    AggregatorV3Interface internal immutable _t2feed1;
    uint48 internal immutable _t2timeout0; // {s}
    uint48 internal immutable _t2timeout1; // {s}
    uint192 internal immutable _t2error0; // {1}
    uint192 internal immutable _t2error1; // {1}

    AggregatorV3Interface internal immutable _t3feed0;
    AggregatorV3Interface internal immutable _t3feed1;
    uint48 internal immutable _t3timeout0; // {s}
    uint48 internal immutable _t3timeout1; // {s}
    uint192 internal immutable _t3error0; // {1}
    uint192 internal immutable _t3error1; // {1}

    // === Config ===

    struct PTConfiguration {
        uint8 nTokens;
        ICurvePool curvePool;
        IERC20Metadata lpToken;
        CurvePoolType poolType;
        AggregatorV3Interface[][] feeds; // row should multiply to give {UoA/ref}; max columns is 2
        uint48[][] oracleTimeouts; // {s} same order as feeds
        uint192[][] oracleErrors; // {1} same order as feeds
    }

    constructor(PTConfiguration memory config) {
        require(config.nTokens <= 4, "up to 4 tokens max");
        require(maxFeedsLength(config.feeds) <= 2, "price feeds limited to 2");
        require(
            config.feeds.length == config.nTokens && minFeedsLength(config.feeds) > 0,
            "each token needs at least 1 price feed"
        );
        require(address(config.curvePool) != address(0), "curvePool address is zero");

        curvePool = config.curvePool;
        nTokens = config.nTokens;
        lpToken = config.lpToken;

        // Solidity does not support immutable arrays. This is a hack to get the equivalent of
        // an immutable array so we do not have store the token feeds in the blockchain. This is
        // a gas optimization since it is significantly more expensive to read and write on the
        // blockchain than it is to use embedded values in the bytecode.

        // === Tokens ===

        IERC20Metadata[] memory tokens = new IERC20Metadata[](nTokens);
        for (uint8 i = 0; i < nTokens; ++i) {
            if (config.poolType == CurvePoolType.Plain) {
                tokens[i] = IERC20Metadata(curvePool.coins(i));
            } else if (config.poolType == CurvePoolType.Lending) {
                tokens[i] = IERC20Metadata(curvePool.underlying_coins(i));
            } else {
                revert("Use MetaPoolTokens class");
            }
        }

        token0 = tokens[0];
        token1 = tokens[1];
        token2 = (nTokens > 2) ? tokens[2] : IERC20Metadata(address(0));
        token3 = (nTokens > 3) ? tokens[3] : IERC20Metadata(address(0));

        // === Feeds + timeouts ===
        // I know this lots extremely verbose and quite silly, but it actually makes sense:
        //   - immutable variables cannot be conditionally written to
        //   - a struct or an array would not be able to be immutable
        //   - immutable variables means values get in-lined in the bytecode

        // token0
        bool more = config.feeds[0].length > 0;
        _t0feed0 = more ? config.feeds[0][0] : AggregatorV3Interface(address(0));
        _t0timeout0 = more && config.oracleTimeouts[0].length > 0 ? config.oracleTimeouts[0][0] : 0;
        _t0error0 = more && config.oracleErrors[0].length > 0 ? config.oracleErrors[0][0] : 0;
        if (more) {
            require(address(_t0feed0) != address(0), "t0feed0 empty");
            require(_t0timeout0 > 0, "t0timeout0 zero");
            require(_t0error0 < FIX_ONE, "t0error0 too large");
        }

        more = config.feeds[0].length > 1;
        _t0feed1 = more ? config.feeds[0][1] : AggregatorV3Interface(address(0));
        _t0timeout1 = more && config.oracleTimeouts[0].length > 1 ? config.oracleTimeouts[0][1] : 0;
        _t0error1 = more && config.oracleErrors[0].length > 1 ? config.oracleErrors[0][1] : 0;
        if (more) {
            require(address(_t0feed1) != address(0), "t0feed1 empty");
            require(_t0timeout1 > 0, "t0timeout1 zero");
            require(_t0error1 < FIX_ONE, "t0error1 too large");
        }

        // token1
        more = config.feeds[1].length > 0;
        _t1feed0 = more ? config.feeds[1][0] : AggregatorV3Interface(address(0));
        _t1timeout0 = more && config.oracleTimeouts[1].length > 0 ? config.oracleTimeouts[1][0] : 0;
        _t1error0 = more && config.oracleErrors[1].length > 0 ? config.oracleErrors[1][0] : 0;
        if (more) {
            require(address(_t1feed0) != address(0), "t1feed0 empty");
            require(_t1timeout0 > 0, "t1timeout0 zero");
            require(_t1error0 < FIX_ONE, "t1error0 too large");
        }

        more = config.feeds[1].length > 1;
        _t1feed1 = more ? config.feeds[1][1] : AggregatorV3Interface(address(0));
        _t1timeout1 = more && config.oracleTimeouts[1].length > 1 ? config.oracleTimeouts[1][1] : 0;
        _t1error1 = more && config.oracleErrors[1].length > 1 ? config.oracleErrors[1][1] : 0;
        if (more) {
            require(address(_t1feed1) != address(0), "t1feed1 empty");
            require(_t1timeout1 > 0, "t1timeout1 zero");
            require(_t1error1 < FIX_ONE, "t1error1 too large");
        }

        // token2
        more = config.feeds.length > 2 && config.feeds[2].length > 0;
        _t2feed0 = more ? config.feeds[2][0] : AggregatorV3Interface(address(0));
        _t2timeout0 = more && config.oracleTimeouts[2].length > 0 ? config.oracleTimeouts[2][0] : 0;
        _t2error0 = more && config.oracleErrors[2].length > 0 ? config.oracleErrors[2][0] : 0;
        if (more) {
            require(address(_t2feed0) != address(0), "t2feed0 empty");
            require(_t2timeout0 > 0, "t2timeout0 zero");
            require(_t2error0 < FIX_ONE, "t2error0 too large");
        }

        more = config.feeds.length > 2 && config.feeds[2].length > 1;
        _t2feed1 = more ? config.feeds[2][1] : AggregatorV3Interface(address(0));
        _t2timeout1 = more && config.oracleTimeouts[2].length > 1 ? config.oracleTimeouts[2][1] : 0;
        _t2error1 = more && config.oracleErrors[2].length > 1 ? config.oracleErrors[2][1] : 0;
        if (more) {
            require(address(_t2feed1) != address(0), "t2feed1 empty");
            require(_t2timeout1 > 0, "t2timeout1 zero");
            require(_t2error1 < FIX_ONE, "t2error1 too large");
        }

        // token3
        more = config.feeds.length > 3 && config.feeds[3].length > 0;
        _t3feed0 = more ? config.feeds[3][0] : AggregatorV3Interface(address(0));
        _t3timeout0 = more && config.oracleTimeouts[3].length > 0 ? config.oracleTimeouts[3][0] : 0;
        _t3error0 = more && config.oracleErrors[3].length > 0 ? config.oracleErrors[3][0] : 0;
        if (more) {
            require(address(_t3feed0) != address(0), "t3feed0 empty");
            require(_t3timeout0 > 0, "t3timeout0 zero");
            require(_t3error0 < FIX_ONE, "t3error0 too large");
        }

        more = config.feeds.length > 3 && config.feeds[3].length > 1;
        _t3feed1 = more ? config.feeds[3][1] : AggregatorV3Interface(address(0));
        _t3timeout1 = more && config.oracleTimeouts[3].length > 1 ? config.oracleTimeouts[3][1] : 0;
        _t3error1 = more && config.oracleErrors[3].length > 1 ? config.oracleErrors[3][1] : 0;
        if (more) {
            require(address(_t3feed1) != address(0), "t3feed1 empty");
            require(_t3timeout1 > 0, "t3timeout1 zero");
            require(_t3error1 < FIX_ONE, "t3error1 too large");
        }
    }

    /// @param index The index of the token: 0, 1, 2, or 3
    /// @return low {UoA/ref_index}
    /// @return high {UoA/ref_index}
    function tokenPrice(uint8 index) public view returns (uint192 low, uint192 high) {
        if (index >= nTokens) revert WrongIndex(nTokens - 1);

        // Use only 1 feed if 2nd feed not defined
        // otherwise: multiply feeds together, e.g; {UoA/ref} = {UoA/target} * {target/ref}
        uint192 x;
        uint192 y = FIX_ONE;
        uint192 xErr; // {1}
        uint192 yErr; // {1}
        // if only 1 feed: `y` is FIX_ONE and `yErr` is 0

        if (index == 0) {
            x = _t0feed0.price(_t0timeout0);
            xErr = _t0error0;
            if (address(_t0feed1) != address(0)) {
                y = _t0feed1.price(_t0timeout1);
                yErr = _t0error1;
            }
        } else if (index == 1) {
            x = _t1feed0.price(_t1timeout0);
            xErr = _t1error0;
            if (address(_t1feed1) != address(0)) {
                y = _t1feed1.price(_t1timeout1);
                yErr = _t1error1;
            }
        } else if (index == 2) {
            x = _t2feed0.price(_t2timeout0);
            xErr = _t2error0;
            if (address(_t2feed1) != address(0)) {
                y = _t2feed1.price(_t2timeout1);
                yErr = _t2error1;
            }
        } else {
            x = _t3feed0.price(_t3timeout0);
            xErr = _t3error0;
            if (address(_t3feed1) != address(0)) {
                y = _t3feed1.price(_t3timeout1);
                yErr = _t3error1;
            }
        }

        return toRange(x, y, xErr, yErr);
    }

    // === Internal ===

    /// @return low {UoA}
    /// @return high {UoA}
    function totalBalancesValue() internal view returns (uint192 low, uint192 high) {
        for (uint8 i = 0; i < nTokens; ++i) {
            IERC20Metadata token = getToken(i);
            uint192 balance = shiftl_toFix(curvePool.balances(i), -int8(token.decimals()));
            (uint192 lowP, uint192 highP) = tokenPrice(i);

            low += balance.mul(lowP, FLOOR);
            high += balance.mul(highP, CEIL);
        }
    }

    /// @return [{tok}]
    function getBalances() internal view virtual returns (uint192[] memory) {
        uint192[] memory balances = new uint192[](nTokens);

        for (uint8 i = 0; i < nTokens; ++i) {
            IERC20Metadata token = getToken(i);
            uint192 balance = shiftl_toFix(curvePool.balances(i), -int8(token.decimals()));
            balances[i] = (balance);
        }

        return balances;
    }

    // === Private ===

    function getToken(uint8 index) private view returns (IERC20Metadata) {
        if (index >= nTokens) revert WrongIndex(nTokens - 1);
        if (index == 0) return token0;
        if (index == 1) return token1;
        if (index == 2) return token2;
        return token3;
    }

    function minFeedsLength(AggregatorV3Interface[][] memory feeds) private pure returns (uint8) {
        uint8 minLength = type(uint8).max;
        for (uint8 i = 0; i < feeds.length; ++i) {
            minLength = uint8(Math.min(minLength, feeds[i].length));
        }
        return minLength;
    }

    function maxFeedsLength(AggregatorV3Interface[][] memory feeds) private pure returns (uint8) {
        uint8 maxLength;
        for (uint8 i = 0; i < feeds.length; ++i) {
            maxLength = uint8(Math.max(maxLength, feeds[i].length));
        }
        return maxLength;
    }

    /// x and y can be any two fixes that can be multiplied
    /// @param xErr {1} error associated with x
    /// @param yErr {1} error associated with y
    /// returns low and high extremes of x * y, given errors
    function toRange(
        uint192 x,
        uint192 y,
        uint192 xErr,
        uint192 yErr
    ) private pure returns (uint192 low, uint192 high) {
        low = x.mul(FIX_ONE - xErr).mul(y.mul(FIX_ONE - yErr), FLOOR);
        high = x.mul(FIX_ONE + xErr).mul(y.mul(FIX_ONE + yErr), CEIL);
    }
}

File 34 of 36 : IConvexStakingWrapper.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.17;

interface IConvexStakingWrapper {
    function crv() external returns (address);

    function cvx() external returns (address);

    function getReward(address _account) external;
}

File 35 of 36 : FiatCollateral.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../interfaces/IAsset.sol";
import "../../libraries/Fixed.sol";
import "./Asset.sol";
import "./OracleLib.sol";

uint48 constant MAX_DELAY_UNTIL_DEFAULT = 1209600; // {s} 2 weeks

struct CollateralConfig {
    uint48 priceTimeout; // {s} The number of seconds over which saved prices decay
    AggregatorV3Interface chainlinkFeed; // Feed units: {target/ref}
    uint192 oracleError; // {1} The % the oracle feed can be off by
    IERC20Metadata erc20; // The ERC20 of the collateral token
    uint192 maxTradeVolume; // {UoA} The max trade volume, in UoA
    uint48 oracleTimeout; // {s} The number of seconds until a oracle value becomes invalid
    bytes32 targetName; // The bytes32 representation of the target name
    uint192 defaultThreshold; // {1} A value like 0.05 that represents a deviation tolerance
    // set defaultThreshold to zero to create SelfReferentialCollateral
    uint48 delayUntilDefault; // {s} The number of seconds an oracle can mulfunction
}

/**
 * @title FiatCollateral
 * Parent class for all collateral. Can be extended to support appreciating collateral
 *
 * For: {tok} == {ref}, {ref} != {target}, {target} == {UoA}
 * Can be easily extended by (optionally) re-implementing:
 *   - tryPrice()
 *   - refPerTok()
 *   - targetPerRef()
 *   - claimRewards()
 * If you have appreciating collateral, then you should use AppreciatingFiatCollateral or
 * override refresh() yourself.
 *
 * Can intentionally disable default checks by setting config.defaultThreshold to 0
 */
contract FiatCollateral is ICollateral, Asset {
    using FixLib for uint192;
    using OracleLib for AggregatorV3Interface;

    // Default Status:
    // _whenDefault == NEVER: no risk of default (initial value)
    // _whenDefault > block.timestamp: delayed default may occur as soon as block.timestamp.
    //                In this case, the asset may recover, reachiving _whenDefault == NEVER.
    // _whenDefault <= block.timestamp: default has already happened (permanently)
    uint48 private constant NEVER = type(uint48).max;
    uint48 private _whenDefault = NEVER;

    uint48 public immutable delayUntilDefault; // {s} e.g 86400

    // targetName: The canonical name of this collateral's target unit.
    bytes32 public immutable targetName;

    uint192 public immutable pegBottom; // {target/ref} The bottom of the peg

    uint192 public immutable pegTop; // {target/ref} The top of the peg

    /// @param config.chainlinkFeed Feed units: {UoA/ref}
    constructor(CollateralConfig memory config)
        Asset(
            config.priceTimeout,
            config.chainlinkFeed,
            config.oracleError,
            config.erc20,
            config.maxTradeVolume,
            config.oracleTimeout
        )
    {
        require(config.targetName != bytes32(0), "targetName missing");
        if (config.defaultThreshold > 0) {
            require(config.delayUntilDefault > 0, "delayUntilDefault zero");
        }
        require(config.delayUntilDefault <= 1209600, "delayUntilDefault too long");

        targetName = config.targetName;
        delayUntilDefault = config.delayUntilDefault;

        // Cache constants
        uint192 peg = targetPerRef(); // {target/ref}

        // {target/ref} = {target/ref} * {1}
        uint192 delta = peg.mul(config.defaultThreshold);
        pegBottom = peg - delta;
        pegTop = peg + delta;
    }

    /// Can revert, used by other contract functions in order to catch errors
    /// Should not return FIX_MAX for low
    /// Should only return FIX_MAX for high if low is 0
    /// @dev Override this when pricing is more complicated than just a single oracle
    /// @return low {UoA/tok} The low price estimate
    /// @return high {UoA/tok} The high price estimate
    /// @return pegPrice {target/ref} The actual price observed in the peg
    function tryPrice()
        external
        view
        virtual
        override
        returns (
            uint192 low,
            uint192 high,
            uint192 pegPrice
        )
    {
        // {target/ref} = {UoA/ref} / {UoA/target} (1)
        pegPrice = chainlinkFeed.price(oracleTimeout);

        // {target/ref} = {target/ref} * {1}
        uint192 err = pegPrice.mul(oracleError, CEIL);

        low = pegPrice - err;
        high = pegPrice + err;
        // assert(low <= high); obviously true just by inspection
    }

    /// Should not revert
    /// Refresh exchange rates and update default status.
    /// @dev May need to override: limited to handling collateral with refPerTok() = 1
    function refresh() public virtual override(Asset, IAsset) {
        if (alreadyDefaulted()) return;
        CollateralStatus oldStatus = status();

        // Check for soft default + save lotPrice
        try this.tryPrice() returns (uint192 low, uint192 high, uint192 pegPrice) {
            // {UoA/tok}, {UoA/tok}, {target/ref}
            // (0, 0) is a valid price; (0, FIX_MAX) is unpriced

            // Save prices if priced
            if (high < FIX_MAX) {
                savedLowPrice = low;
                savedHighPrice = high;
                lastSave = uint48(block.timestamp);
            } else {
                // must be unpriced
                assert(low == 0);
            }

            // If the price is below the default-threshold price, default eventually
            // uint192(+/-) is the same as Fix.plus/minus
            if (pegPrice < pegBottom || pegPrice > pegTop || low == 0) {
                markStatus(CollateralStatus.IFFY);
            } else {
                markStatus(CollateralStatus.SOUND);
            }
        } catch (bytes memory errData) {
            // see: docs/solidity-style.md#Catching-Empty-Data
            if (errData.length == 0) revert(); // solhint-disable-line reason-string
            markStatus(CollateralStatus.IFFY);
        }

        CollateralStatus newStatus = status();
        if (oldStatus != newStatus) {
            emit CollateralStatusChanged(oldStatus, newStatus);
        }
    }

    /// @return The collateral's status
    function status() public view returns (CollateralStatus) {
        if (_whenDefault == NEVER) {
            return CollateralStatus.SOUND;
        } else if (_whenDefault > block.timestamp) {
            return CollateralStatus.IFFY;
        } else {
            return CollateralStatus.DISABLED;
        }
    }

    // === Helpers for child classes ===

    function markStatus(CollateralStatus status_) internal {
        // untestable:
        //      All calls to markStatus happen exclusively if the collateral is not defaulted
        if (_whenDefault <= block.timestamp) return; // prevent DISABLED -> SOUND/IFFY

        if (status_ == CollateralStatus.SOUND) {
            _whenDefault = NEVER;
        } else if (status_ == CollateralStatus.IFFY) {
            uint256 sum = block.timestamp + uint256(delayUntilDefault);
            // untestable:
            //      constructor enforces max length on delayUntilDefault
            if (sum >= NEVER) _whenDefault = NEVER;
            else if (sum < _whenDefault) _whenDefault = uint48(sum);
            // else: no change to _whenDefault
            // untested:
            //      explicit `if` to check DISABLED. else branch will never be hit
        } else if (status_ == CollateralStatus.DISABLED) {
            _whenDefault = uint48(block.timestamp);
        }
    }

    function alreadyDefaulted() internal view returns (bool) {
        return _whenDefault <= block.timestamp;
    }

    function whenDefault() external view returns (uint256) {
        return _whenDefault;
    }

    // === End child helpers ===

    /// @return {ref/tok} Quantity of whole reference units per whole collateral tokens
    function refPerTok() public view virtual returns (uint192) {
        return FIX_ONE;
    }

    /// @return {target/ref} Quantity of whole target units per whole reference unit in the peg
    function targetPerRef() public view virtual returns (uint192) {
        return FIX_ONE;
    }

    /// @return If the asset is an instance of ICollateral or not
    function isCollateral() external pure virtual override(Asset, IAsset) returns (bool) {
        return true;
    }
}

File 36 of 36 : OracleLib.sol
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "../../libraries/Fixed.sol";

error StalePrice();

/// Used by asset plugins to price their collateral
library OracleLib {
    /// @dev Use for on-the-fly calculations that should revert
    /// @param timeout The number of seconds after which oracle values should be considered stale
    /// @return {UoA/tok}
    function price(AggregatorV3Interface chainlinkFeed, uint48 timeout)
        internal
        view
        returns (uint192)
    {
        (uint80 roundId, int256 p, , uint256 updateTime, uint80 answeredInRound) = chainlinkFeed
            .latestRoundData();

        if (updateTime == 0 || answeredInRound < roundId) {
            revert StalePrice();
        }
        // Downcast is safe: uint256(-) reverts on underflow; block.timestamp assumed < 2^48
        uint48 secondsSince = uint48(block.timestamp - updateTime);
        if (secondsSince > timeout) revert StalePrice();

        // {UoA/tok}
        return shiftl_toFix(uint256(p), -int8(chainlinkFeed.decimals()));
    }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"components":[{"internalType":"uint48","name":"priceTimeout","type":"uint48"},{"internalType":"contract AggregatorV3Interface","name":"chainlinkFeed","type":"address"},{"internalType":"uint192","name":"oracleError","type":"uint192"},{"internalType":"contract IERC20Metadata","name":"erc20","type":"address"},{"internalType":"uint192","name":"maxTradeVolume","type":"uint192"},{"internalType":"uint48","name":"oracleTimeout","type":"uint48"},{"internalType":"bytes32","name":"targetName","type":"bytes32"},{"internalType":"uint192","name":"defaultThreshold","type":"uint192"},{"internalType":"uint48","name":"delayUntilDefault","type":"uint48"}],"internalType":"struct CollateralConfig","name":"config","type":"tuple"},{"internalType":"uint192","name":"revenueHiding","type":"uint192"},{"components":[{"internalType":"uint8","name":"nTokens","type":"uint8"},{"internalType":"contract ICurvePool","name":"curvePool","type":"address"},{"internalType":"contract IERC20Metadata","name":"lpToken","type":"address"},{"internalType":"enum PoolTokens.CurvePoolType","name":"poolType","type":"uint8"},{"internalType":"contract AggregatorV3Interface[][]","name":"feeds","type":"address[][]"},{"internalType":"uint48[][]","name":"oracleTimeouts","type":"uint48[][]"},{"internalType":"uint192[][]","name":"oracleErrors","type":"uint192[][]"}],"internalType":"struct PoolTokens.PTConfiguration","name":"ptConfig","type":"tuple"},{"internalType":"contract ICurveMetaPool","name":"metapoolToken_","type":"address"},{"internalType":"uint192","name":"pairedTokenDefaultThreshold_","type":"uint192"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint8","name":"tokenNumber","type":"uint8"}],"name":"NoToken","type":"error"},{"inputs":[],"name":"StalePrice","type":"error"},{"inputs":[],"name":"UIntOutOfBounds","type":"error"},{"inputs":[{"internalType":"uint8","name":"maxLength","type":"uint8"}],"name":"WrongIndex","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"enum CollateralStatus","name":"oldStatus","type":"uint8"},{"indexed":true,"internalType":"enum CollateralStatus","name":"newStatus","type":"uint8"}],"name":"CollateralStatusChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"erc20","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"bal","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chainlinkFeed","outputs":[{"internalType":"contract AggregatorV3Interface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"curvePool","outputs":[{"internalType":"contract ICurvePool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delayUntilDefault","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"erc20","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"erc20Decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exposedReferencePrice","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isCollateral","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"lastSave","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lotPrice","outputs":[{"internalType":"uint192","name":"lotLow","type":"uint192"},{"internalType":"uint192","name":"lotHigh","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpToken","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTradeVolume","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"metapoolToken","outputs":[{"internalType":"contract ICurveMetaPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleError","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleTimeout","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pairedToken","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pairedTokenPegBottom","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pairedTokenPegTop","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pegBottom","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pegTop","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price","outputs":[{"internalType":"uint192","name":"","type":"uint192"},{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceTimeout","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refPerTok","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refresh","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revenueShowing","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"savedHighPrice","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"savedLowPrice","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"status","outputs":[{"internalType":"enum CollateralStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"targetName","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"targetPerRef","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"index","type":"uint8"}],"name":"tokenPrice","outputs":[{"internalType":"uint192","name":"low","type":"uint192"},{"internalType":"uint192","name":"high","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tryPairedPrice","outputs":[{"internalType":"uint192","name":"lowPaired","type":"uint192"},{"internalType":"uint192","name":"highPaired","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tryPrice","outputs":[{"internalType":"uint192","name":"low","type":"uint192"},{"internalType":"uint192","name":"high","type":"uint192"},{"internalType":"uint192","name":"pegPrice","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"whenDefault","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

6106806040526002805465ffffffffffff191665ffffffffffff1790553480156200002957600080fd5b5060405162005f5538038062005f558339810160408190526200004c9162002a13565b848484848484848480838381806000015181602001518260400151836060015184608001518560a0015160008665ffffffffffff1611620000c95760405162461bcd60e51b815260206004820152601260248201527170726963652074696d656f7574207a65726f60701b60448201526064015b60405180910390fd5b6001600160a01b038516620001215760405162461bcd60e51b815260206004820152601660248201527f6d697373696e6720636861696e6c696e6b2066656564000000000000000000006044820152606401620000c0565b6000846001600160c01b03161180156200014b5750670de0b6b3a76400006001600160c01b038516105b620001995760405162461bcd60e51b815260206004820152601960248201527f6f7261636c65206572726f72206f7574206f662072616e6765000000000000006044820152606401620000c0565b6001600160a01b038316620001e15760405162461bcd60e51b815260206004820152600d60248201526c06d697373696e6720657263323609c1b6044820152606401620000c0565b6000826001600160c01b0316116200023c5760405162461bcd60e51b815260206004820152601860248201527f696e76616c6964206d617820747261646520766f6c756d6500000000000000006044820152606401620000c0565b60008165ffffffffffff16116200028b5760405162461bcd60e51b81526020600482015260126024820152716f7261636c6554696d656f7574207a65726f60701b6044820152606401620000c0565b65ffffffffffff8616610140526001600160a01b038086166080526001600160c01b03851661012052831660a08190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa158015620002f7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200031d919062002b57565b60ff1660c09081526001600160c01b0390921660e05265ffffffffffff166101005285015193506200038b925050505760405162461bcd60e51b81526020600482015260126024820152717461726765744e616d65206d697373696e6760701b6044820152606401620000c0565b60e08101516001600160c01b031615620003fe57600081610100015165ffffffffffff1611620003fe5760405162461bcd60e51b815260206004820152601660248201527f64656c6179556e74696c44656661756c74207a65726f000000000000000000006044820152606401620000c0565b6212750081610100015165ffffffffffff161115620004605760405162461bcd60e51b815260206004820152601a60248201527f64656c6179556e74696c44656661756c7420746f6f206c6f6e670000000000006044820152606401620000c0565b60c08101516101805261010081015165ffffffffffff16610160526000670de0b6b3a764000090506000620004b18360e00151836001600160c01b0316620022c460201b620019811790919060201c565b9050620004bf818362002b8b565b6001600160c01b03166101a052620004d8818362002bae565b6001600160c01b039081166101c052670de0b6b3a7640000908516109250620005479150505760405162461bcd60e51b815260206004820152601a60248201527f726576656e7565486964696e67206f7574206f662072616e67650000000000006044820152606401620000c0565b62000567670de0b6b3a764000082620022dd602090811b6200199617901c565b6001600160c01b03166101e05250508051600460ff9091161115620005c45760405162461bcd60e51b81526020600482015260126024820152710eae040e8de406840e8ded6cadce640dac2f60731b6044820152606401620000c0565b6002620005db8260800151620022eb60201b60201c565b60ff1611156200062e5760405162461bcd60e51b815260206004820152601860248201527f7072696365206665656473206c696d6974656420746f203200000000000000006044820152606401620000c0565b806000015160ff1681608001515114801562000661575060006200065c82608001516200235460201b60201c565b60ff16115b620006be5760405162461bcd60e51b815260206004820152602660248201527f6561636820746f6b656e206e65656473206174206c656173742031207072696360448201526519481999595960d21b6064820152608401620000c0565b60208101516001600160a01b03166200071a5760405162461bcd60e51b815260206004820152601960248201527f6375727665506f6f6c2061646472657373206973207a65726f000000000000006044820152606401620000c0565b60208101516001600160a01b0390811661020052815160ff166102408190526040830151909116610220526000906001600160401b0381111562000762576200076262002513565b6040519080825280602002602001820160405280156200078c578160200160208202803683370190505b50905060005b6102405160ff168160ff1610156200092957600083606001516002811115620007bf57620007bf62002bd1565b0362000877576102005160405163c661065760e01b815260ff831660048201526001600160a01b039091169063c6610657906024015b602060405180830381865afa15801562000813573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000839919062002be7565b828260ff168151811062000851576200085162002c07565b60200260200101906001600160a01b031690816001600160a01b03168152505062000916565b60018360600151600281111562000892576200089262002bd1565b03620008cd5761020051604051630b9947eb60e41b815260ff831660048201526001600160a01b039091169063b9947eb090602401620007f5565b60405162461bcd60e51b815260206004820152601860248201527f557365204d657461506f6f6c546f6b656e7320636c61737300000000000000006044820152606401620000c0565b620009218162002c1d565b905062000792565b508060008151811062000940576200094062002c07565b60200260200101516001600160a01b0316610260816001600160a01b0316815250508060018151811062000978576200097862002c07565b60200260200101516001600160a01b0316610280816001600160a01b03168152505060026102405160ff1611620009b1576000620009d0565b80600281518110620009c757620009c762002c07565b60200260200101515b6001600160a01b03166102a05261024051600360ff90911611620009f657600062000a15565b8060038151811062000a0c5762000a0c62002c07565b60200260200101515b6001600160a01b03166102c052608082015180516000918291829062000a3f5762000a3f62002c07565b6020026020010151511190508062000a5957600062000a99565b826080015160008151811062000a735762000a7362002c07565b602002602001015160008151811062000a905762000a9062002c07565b60200260200101515b6001600160a01b03166102e05280801562000ad6575060008360a0015160008151811062000acb5762000acb62002c07565b602002602001015151115b62000ae357600062000b23565b8260a0015160008151811062000afd5762000afd62002c07565b602002602001015160008151811062000b1a5762000b1a62002c07565b60200260200101515b65ffffffffffff166103205280801562000b5f575060008360c0015160008151811062000b545762000b5462002c07565b602002602001015151115b62000b6c57600062000bac565b8260c0015160008151811062000b865762000b8662002c07565b602002602001015160008151811062000ba35762000ba362002c07565b60200260200101515b6001600160c01b031661036052801562000cb6576102e0516001600160a01b031662000c0b5760405162461bcd60e51b815260206004820152600d60248201526c7430666565643020656d70747960981b6044820152606401620000c0565b60006103205165ffffffffffff161162000c5a5760405162461bcd60e51b815260206004820152600f60248201526e743074696d656f757430207a65726f60881b6044820152606401620000c0565b61036051670de0b6b3a76400006001600160c01b039091161062000cb65760405162461bcd60e51b815260206004820152601260248201527174306572726f723020746f6f206c6172676560701b6044820152606401620000c0565b6001836080015160008151811062000cd25762000cd262002c07565b6020026020010151511190508062000cec57600062000d2c565b826080015160008151811062000d065762000d0662002c07565b602002602001015160018151811062000d235762000d2362002c07565b60200260200101515b6001600160a01b03166103005280801562000d69575060018360a0015160008151811062000d5e5762000d5e62002c07565b602002602001015151115b62000d7657600062000db6565b8260a0015160008151811062000d905762000d9062002c07565b602002602001015160018151811062000dad5762000dad62002c07565b60200260200101515b65ffffffffffff166103405280801562000df2575060018360c0015160008151811062000de75762000de762002c07565b602002602001015151115b62000dff57600062000e3f565b8260c0015160008151811062000e195762000e1962002c07565b602002602001015160018151811062000e365762000e3662002c07565b60200260200101515b6001600160c01b031661038052801562000f4957610300516001600160a01b031662000e9e5760405162461bcd60e51b815260206004820152600d60248201526c7430666565643120656d70747960981b6044820152606401620000c0565b60006103405165ffffffffffff161162000eed5760405162461bcd60e51b815260206004820152600f60248201526e743074696d656f757431207a65726f60881b6044820152606401620000c0565b61038051670de0b6b3a76400006001600160c01b039091161062000f495760405162461bcd60e51b815260206004820152601260248201527174306572726f723120746f6f206c6172676560701b6044820152606401620000c0565b6000836080015160018151811062000f655762000f6562002c07565b6020026020010151511190508062000f7f57600062000fbf565b826080015160018151811062000f995762000f9962002c07565b602002602001015160008151811062000fb65762000fb662002c07565b60200260200101515b6001600160a01b03166103a05280801562000ffc575060008360a0015160018151811062000ff15762000ff162002c07565b602002602001015151115b6200100957600062001049565b8260a0015160018151811062001023576200102362002c07565b602002602001015160008151811062001040576200104062002c07565b60200260200101515b65ffffffffffff166103e05280801562001085575060008360c001516001815181106200107a576200107a62002c07565b602002602001015151115b62001092576000620010d2565b8260c00151600181518110620010ac57620010ac62002c07565b6020026020010151600081518110620010c957620010c962002c07565b60200260200101515b6001600160c01b0316610420528015620011dc576103a0516001600160a01b0316620011315760405162461bcd60e51b815260206004820152600d60248201526c7431666565643020656d70747960981b6044820152606401620000c0565b60006103e05165ffffffffffff1611620011805760405162461bcd60e51b815260206004820152600f60248201526e743174696d656f757430207a65726f60881b6044820152606401620000c0565b61042051670de0b6b3a76400006001600160c01b0390911610620011dc5760405162461bcd60e51b815260206004820152601260248201527174316572726f723020746f6f206c6172676560701b6044820152606401620000c0565b60018360800151600181518110620011f857620011f862002c07565b602002602001015151119050806200121257600062001252565b82608001516001815181106200122c576200122c62002c07565b602002602001015160018151811062001249576200124962002c07565b60200260200101515b6001600160a01b03166103c0528080156200128f575060018360a0015160018151811062001284576200128462002c07565b602002602001015151115b6200129c576000620012dc565b8260a00151600181518110620012b657620012b662002c07565b6020026020010151600181518110620012d357620012d362002c07565b60200260200101515b65ffffffffffff166104005280801562001318575060018360c001516001815181106200130d576200130d62002c07565b602002602001015151115b6200132557600062001365565b8260c001516001815181106200133f576200133f62002c07565b60200260200101516001815181106200135c576200135c62002c07565b60200260200101515b6001600160c01b03166104405280156200146f576103c0516001600160a01b0316620013c45760405162461bcd60e51b815260206004820152600d60248201526c7431666565643120656d70747960981b6044820152606401620000c0565b60006104005165ffffffffffff1611620014135760405162461bcd60e51b815260206004820152600f60248201526e743174696d656f757431207a65726f60881b6044820152606401620000c0565b61044051670de0b6b3a76400006001600160c01b03909116106200146f5760405162461bcd60e51b815260206004820152601260248201527174316572726f723120746f6f206c6172676560701b6044820152606401620000c0565b6002836080015151118015620014a75750600083608001516002815181106200149c576200149c62002c07565b602002602001015151115b905080620014b7576000620014f7565b8260800151600281518110620014d157620014d162002c07565b6020026020010151600081518110620014ee57620014ee62002c07565b60200260200101515b6001600160a01b03166104605280801562001534575060008360a0015160028151811062001529576200152962002c07565b602002602001015151115b6200154157600062001581565b8260a001516002815181106200155b576200155b62002c07565b602002602001015160008151811062001578576200157862002c07565b60200260200101515b65ffffffffffff166104a052808015620015bd575060008360c00151600281518110620015b257620015b262002c07565b602002602001015151115b620015ca5760006200160a565b8260c00151600281518110620015e457620015e462002c07565b602002602001015160008151811062001601576200160162002c07565b60200260200101515b6001600160c01b03166104e05280156200171457610460516001600160a01b0316620016695760405162461bcd60e51b815260206004820152600d60248201526c7432666565643020656d70747960981b6044820152606401620000c0565b60006104a05165ffffffffffff1611620016b85760405162461bcd60e51b815260206004820152600f60248201526e743274696d656f757430207a65726f60881b6044820152606401620000c0565b6104e051670de0b6b3a76400006001600160c01b0390911610620017145760405162461bcd60e51b815260206004820152601260248201527174326572726f723020746f6f206c6172676560701b6044820152606401620000c0565b60028360800151511180156200174c57506001836080015160028151811062001741576200174162002c07565b602002602001015151115b9050806200175c5760006200179c565b826080015160028151811062001776576200177662002c07565b602002602001015160018151811062001793576200179362002c07565b60200260200101515b6001600160a01b031661048052808015620017d9575060018360a00151600281518110620017ce57620017ce62002c07565b602002602001015151115b620017e657600062001826565b8260a0015160028151811062001800576200180062002c07565b60200260200101516001815181106200181d576200181d62002c07565b60200260200101515b65ffffffffffff166104c05280801562001862575060018360c0015160028151811062001857576200185762002c07565b602002602001015151115b6200186f576000620018af565b8260c0015160028151811062001889576200188962002c07565b6020026020010151600181518110620018a657620018a662002c07565b60200260200101515b6001600160c01b0316610500528015620019b957610480516001600160a01b03166200190e5760405162461bcd60e51b815260206004820152600d60248201526c7432666565643120656d70747960981b6044820152606401620000c0565b60006104c05165ffffffffffff16116200195d5760405162461bcd60e51b815260206004820152600f60248201526e743274696d656f757431207a65726f60881b6044820152606401620000c0565b61050051670de0b6b3a76400006001600160c01b0390911610620019b95760405162461bcd60e51b815260206004820152601260248201527174326572726f723120746f6f206c6172676560701b6044820152606401620000c0565b6003836080015151118015620019f1575060008360800151600381518110620019e657620019e662002c07565b602002602001015151115b90508062001a0157600062001a41565b826080015160038151811062001a1b5762001a1b62002c07565b602002602001015160008151811062001a385762001a3862002c07565b60200260200101515b6001600160a01b03166105205280801562001a7e575060008360a0015160038151811062001a735762001a7362002c07565b602002602001015151115b62001a8b57600062001acb565b8260a0015160038151811062001aa55762001aa562002c07565b602002602001015160008151811062001ac25762001ac262002c07565b60200260200101515b65ffffffffffff166105605280801562001b07575060008360c0015160038151811062001afc5762001afc62002c07565b602002602001015151115b62001b1457600062001b54565b8260c0015160038151811062001b2e5762001b2e62002c07565b602002602001015160008151811062001b4b5762001b4b62002c07565b60200260200101515b6001600160c01b03166105a052801562001c5e57610520516001600160a01b031662001bb35760405162461bcd60e51b815260206004820152600d60248201526c7433666565643020656d70747960981b6044820152606401620000c0565b60006105605165ffffffffffff161162001c025760405162461bcd60e51b815260206004820152600f60248201526e743374696d656f757430207a65726f60881b6044820152606401620000c0565b6105a051670de0b6b3a76400006001600160c01b039091161062001c5e5760405162461bcd60e51b815260206004820152601260248201527174336572726f723020746f6f206c6172676560701b6044820152606401620000c0565b600383608001515111801562001c9657506001836080015160038151811062001c8b5762001c8b62002c07565b602002602001015151115b90508062001ca657600062001ce6565b826080015160038151811062001cc05762001cc062002c07565b602002602001015160018151811062001cdd5762001cdd62002c07565b60200260200101515b6001600160a01b03166105405280801562001d23575060018360a0015160038151811062001d185762001d1862002c07565b602002602001015151115b62001d3057600062001d70565b8260a0015160038151811062001d4a5762001d4a62002c07565b602002602001015160018151811062001d675762001d6762002c07565b60200260200101515b65ffffffffffff166105805280801562001dac575060018360c0015160038151811062001da15762001da162002c07565b602002602001015151115b62001db957600062001df9565b8260c0015160038151811062001dd35762001dd362002c07565b602002602001015160018151811062001df05762001df062002c07565b60200260200101515b6001600160c01b03166105c052801562001f0357610540516001600160a01b031662001e585760405162461bcd60e51b815260206004820152600d60248201526c7433666565643120656d70747960981b6044820152606401620000c0565b60006105805165ffffffffffff161162001ea75760405162461bcd60e51b815260206004820152600f60248201526e743374696d656f757431207a65726f60881b6044820152606401620000c0565b6105c051670de0b6b3a76400006001600160c01b039091161062001f035760405162461bcd60e51b815260206004820152601260248201527174336572726f723120746f6f206c6172676560701b6044820152606401620000c0565b50505060008360e001516001600160c01b03161162001f655760405162461bcd60e51b815260206004820152601560248201527f64656661756c745468726573686f6c64207a65726f00000000000000000000006044820152606401620000c0565b5050506001600160a01b03821662001fc05760405162461bcd60e51b815260206004820152601d60248201527f6d657461706f6f6c546f6b656e2061646472657373206973207a65726f0000006044820152606401620000c0565b6000816001600160c01b031611801562001fea5750670de0b6b3a76400006001600160c01b038216105b6200204a5760405162461bcd60e51b815260206004820152602960248201527f706169726564546f6b656e44656661756c745468726573686f6c64206f7574206044820152686f6620626f756e647360b81b6064820152608401620000c0565b6001600160a01b0382166105e081905260405163c661065760e01b81526000600482015263c661065790602401602060405180830381865afa15801562002095573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620020bb919062002be7565b6001600160a01b031661060052670de0b6b3a76400006000620020eb8284620022c4602090811b6200198117901c565b9050620020f9818362002b8b565b6001600160c01b03166106205262002112818362002bae565b6001600160c01b031661064052610600516001600160a01b03166200213b576200213b62002c3f565b610220516001600160a01b03166105e0516001600160a01b031663c661065760016040518263ffffffff1660e01b81526004016200217b91815260200190565b602060405180830381865afa15801562002199573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620021bf919062002be7565b6001600160a01b031614620021d857620021d862002c3f565b50505050505050610600516001600160a01b031663dffeadd06040518163ffffffff1660e01b8152600401602060405180830381865afa15801562002221573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002247919062002be7565b6001600160a01b031663979d7e866040518163ffffffff1660e01b8152600401602060405180830381865afa15801562002285573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620022ab919062002be7565b6001600160a01b0316610660525062002ce59350505050565b6000620022d483836001620023b6565b90505b92915050565b6000620022d4828462002b8b565b60008060005b83518160ff1610156200234d57620023388260ff16858360ff16815181106200231e576200231e62002c07565b602002602001015151620023f860201b620019a21760201c565b9150620023458162002c1d565b9050620022f1565b5092915050565b600060ff815b83518160ff1610156200234d57620023a18260ff16858360ff168151811062002387576200238762002c07565b6020026020010151516200241160201b620019b91760201c565b9150620023ae8162002c1d565b90506200235a565b6000620023ee620023e8620023d86001600160c01b0380871690881662002c55565b670de0b6b3a76400008562002422565b620024e4565b90505b9392505050565b6000818310156200240a5781620022d4565b5090919050565b60008183106200240a5781620022d4565b60008062002431848662002c85565b905060008360028111156200244a576200244a62002bd1565b0362002458579050620023f1565b60018360028111156200246f576200246f62002bd1565b03620024b95760026200248460018662002c9c565b62002490919062002c85565b6200249c858762002cb2565b1115620024b35780620024af8162002cc9565b9150505b620023ee565b6000620024c7858762002cb2565b1115620023ee5780620024da8162002cc9565b9695505050505050565b60006001600160c01b038211156200250f5760405163f44398f560e01b815260040160405180910390fd5b5090565b634e487b7160e01b600052604160045260246000fd5b60405160e081016001600160401b03811182821017156200254e576200254e62002513565b60405290565b60405161012081016001600160401b03811182821017156200254e576200254e62002513565b604051601f8201601f191681016001600160401b0381118282101715620025a557620025a562002513565b604052919050565b805165ffffffffffff81168114620025c457600080fd5b919050565b6001600160a01b0381168114620025df57600080fd5b50565b8051620025c481620025c9565b80516001600160c01b0381168114620025c457600080fd5b805160ff81168114620025c457600080fd5b805160038110620025c457600080fd5b60006001600160401b0382111562002645576200264562002513565b5060051b60200190565b600082601f8301126200266157600080fd5b815160206200267a620026748362002629565b6200257a565b828152600592831b85018201928282019190878511156200269a57600080fd5b8387015b85811015620027455780516001600160401b03811115620026bf5760008081fd5b8801603f81018a13620026d25760008081fd5b858101516040620026e7620026748362002629565b82815291851b8301810191888101908d841115620027055760008081fd5b938201935b838510156200273357845192506200272283620025c9565b82825293890193908901906200270a565b8852505050938501935084016200269e565b5090979650505050505050565b600082601f8301126200276457600080fd5b8151602062002777620026748362002629565b828152600592831b85018201928282019190878511156200279757600080fd5b8387015b85811015620027455780516001600160401b03811115620027bc5760008081fd5b8801603f81018a13620027cf5760008081fd5b858101516040620027e4620026748362002629565b82815291851b8301810191888101908d841115620028025760008081fd5b938201935b838510156200282b576200281b85620025ad565b8252938901939089019062002807565b8852505050938501935084016200279b565b600082601f8301126200284f57600080fd5b8151602062002862620026748362002629565b828152600592831b85018201928282019190878511156200288257600080fd5b8387015b85811015620027455780516001600160401b03811115620028a75760008081fd5b8801603f81018a13620028ba5760008081fd5b858101516040620028cf620026748362002629565b82815291851b8301810191888101908d841115620028ed5760008081fd5b938201935b8385101562002916576200290685620025ef565b82529389019390890190620028f2565b88525050509385019350840162002886565b600060e082840312156200293b57600080fd5b6200294562002529565b9050620029528262002607565b81526200296260208301620025e2565b60208201526200297560408301620025e2565b6040820152620029886060830162002619565b606082015260808201516001600160401b0380821115620029a857600080fd5b620029b6858386016200264f565b608084015260a0840151915080821115620029d057600080fd5b620029de8583860162002752565b60a084015260c0840151915080821115620029f857600080fd5b5062002a07848285016200283d565b60c08301525092915050565b60008060008060008587036101a081121562002a2e57600080fd5b6101208082121562002a3f57600080fd5b62002a4962002554565b915062002a5688620025ad565b825262002a6660208901620025e2565b602083015262002a7960408901620025ef565b604083015262002a8c60608901620025e2565b606083015262002a9f60808901620025ef565b608083015262002ab260a08901620025ad565b60a083015260c088015160c083015262002acf60e08901620025ef565b60e083015261010062002ae4818a01620025ad565b818401525081965062002af9818901620025ef565b6101408901519096509150506001600160401b0381111562002b1a57600080fd5b62002b288882890162002928565b93505062002b3a6101608701620025e2565b915062002b4b6101808701620025ef565b90509295509295909350565b60006020828403121562002b6a57600080fd5b620022d48262002607565b634e487b7160e01b600052601160045260246000fd5b6001600160c01b038281168282160390808211156200234d576200234d62002b75565b6001600160c01b038181168382160190808211156200234d576200234d62002b75565b634e487b7160e01b600052602160045260246000fd5b60006020828403121562002bfa57600080fd5b8151620023f181620025c9565b634e487b7160e01b600052603260045260246000fd5b600060ff821660ff810362002c365762002c3662002b75565b60010192915050565b634e487b7160e01b600052600160045260246000fd5b8082028115828204841417620022d757620022d762002b75565b634e487b7160e01b600052601260045260246000fd5b60008262002c975762002c9762002c6f565b500490565b81810381811115620022d757620022d762002b75565b60008262002cc45762002cc462002c6f565b500690565b60006001820162002cde5762002cde62002b75565b5060010190565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c0516104e05161050051610520516105405161056051610580516105a0516105c0516105e05161060051610620516106405161066051612f7262002fe36000396000610c6d01526000818161048a015261237a0152600081816103bc015261233f01526000818161067301528181610c400152611c4c01526000818161034301528181610e9301528181610f1501528181611b4301528181611bdf0152611f45015260006115f30152600061154c015260006115cb0152600061152401526000818161156f01526115a901526000611502015260006114cf01526000611428015260006114a70152600061140001526000818161144b0152611485015260006113de015260006113a0015260006112f901526000611378015260006112d101526000818161131c0152611356015260006112af01526000611270015260006111c901526000611248015260006111a10152600081816111ec01526112260152600061117f01526000612a6601526000612a3f01526000612a0d015260006129db0152600081816110e201528181611114015281816120f6015281816125df0152818161297701526129a901526000818161039501528181611a0c0152611a8e01526000818161023901526126400152600081816103e30152818161164601526116cd01526000818161054b015261221d01526000818161058501526121e20152600061064c01526000818161061d015261203a0152600081816102a001528181610798015281816107e40152610812015260006105ac01526000610524015260006104b10152600081816103020152610dd601526000818161040a015281816108ab0152610d66015260006104630152612f726000f3fe608060405234801561001057600080fd5b50600436106102115760003560e01c806395acc4ae11610125578063c55f29d1116100ad578063ddc0c7c81161007c578063ddc0c7c814610605578063e6a1505314610618578063f8ac93e81461063f578063fdfd591714610647578063ffc94f901461066e57600080fd5b8063c55f29d1146105a7578063c59b3d63146105ce578063cde5b5ee146105dd578063d9e8e670146105f757600080fd5b8063a7fa0faf116100f4578063a7fa0faf14610507578063abfeece51461051f578063ae4e187514610546578063b419001e1461056d578063b94d87391461058057600080fd5b806395acc4ae146104ac57806396f80ae9146104d35780639ec07272146104ec578063a035b1fe146104ff57600080fd5b80635056ffa6116101a857806374b629541161017757806374b62954146103de578063785e9e86146104055780637d1ea1371461042c5780637dbdf1f51461045e5780638f77968f1461048557600080fd5b80635056ffa61461033e5780635580f72a146103655780635fcbd285146103905780637020bc7d146103b757600080fd5b80632dc86624116101e45780632dc86624146102d9578063372500ab146102f35780633cb5d379146102fd57806342e359c41461033657600080fd5b8063200d2ed214610216578063218751b214610234578063271181ec146102735780632bcfaa801461029b575b600080fd5b61021e610695565b60405161022b9190612aa0565b60405180910390f35b61025b7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161022b565b61027b6106d6565b604080516001600160c01b0393841681529290911660208301520161022b565b6102c27f000000000000000000000000000000000000000000000000000000000000000081565b60405165ffffffffffff909116815260200161022b565b60025465ffffffffffff165b60405190815260200161022b565b6102fb6108a7565b005b6103247f000000000000000000000000000000000000000000000000000000000000000081565b60405160ff909116815260200161022b565b61027b610c29565b61025b7f000000000000000000000000000000000000000000000000000000000000000081565b610378610373366004612add565b610d40565b6040516001600160c01b03909116815260200161022b565b61025b7f000000000000000000000000000000000000000000000000000000000000000081565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b61025b7f000000000000000000000000000000000000000000000000000000000000000081565b610434610e05565b604080516001600160c01b039485168152928416602084015292169181019190915260600161022b565b61025b7f000000000000000000000000000000000000000000000000000000000000000081565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b6001546102c290600160c01b900465ffffffffffff1681565b600154610378906001600160c01b031681565b61027b611000565b600254600160301b90046001600160c01b0316610378565b6102c27f000000000000000000000000000000000000000000000000000000000000000081565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b61027b61057b366004612b09565b6110dd565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b6040516001815260200161022b565b60025461037890600160301b90046001600160c01b031681565b670de0b6b3a7640000610378565b600054610378906001600160c01b031681565b6102c27f000000000000000000000000000000000000000000000000000000000000000081565b6102fb61162e565b6102e57f000000000000000000000000000000000000000000000000000000000000000081565b61025b7f000000000000000000000000000000000000000000000000000000000000000081565b60025460009065ffffffffffff1665fffffffffffe19016106b65750600090565b6002544265ffffffffffff90911611156106d05750600190565b50600290565b600080306001600160a01b0316637d1ea1376040518163ffffffff1660e01b8152600401606060405180830381865afa925050508015610733575060408051601f3d908101601f1916820190925261073091810190612b42565b60015b61087a573d808015610761576040519150601f19603f3d011682016040523d82523d6000602084013e610766565b606091505b50805160000361077557600080fd5b60015460009061079490600160c01b900465ffffffffffff1642612b9b565b90507f000000000000000000000000000000000000000000000000000000000000000065ffffffffffff168165ffffffffffff16106107d95750600093849350915050565b600061083e610808837f0000000000000000000000000000000000000000000000000000000000000000612b9b565b65ffffffffffff167f000000000000000000000000000000000000000000000000000000000000000065ffffffffffff166119c8565b600054909150610857906001600160c01b031682611981565b600154909550610870906001600160c01b031682611981565b9350505050610881565b5090925090505b806001600160c01b0316826001600160c01b031611156108a3576108a3612bc1565b9091565b60007f000000000000000000000000000000000000000000000000000000000000000090506000816001600160a01b031663923c1d616040518163ffffffff1660e01b81526004016020604051808303816000875af115801561090e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109329190612bd7565b90506000826001600160a01b0316636a4874a16040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610976573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061099a9190612bd7565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156109e4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a089190612bf4565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610a52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a769190612bf4565b604051630c00007b60e41b81523060048201529091506001600160a01b0386169063c00007b090602401600060405180830381600087803b158015610aba57600080fd5b505af1158015610ace573d6000803e3d6000fd5b50506040516370a0823160e01b81523060048201528492506001600160a01b03871691506370a0823190602401602060405180830381865afa158015610b18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3c9190612bf4565b610b469190612c0d565b6040516001600160a01b038616907ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe90600090a36040516370a0823160e01b815230600482015281906001600160a01b038516906370a0823190602401602060405180830381865afa158015610bc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610be49190612bf4565b610bee9190612c0d565b6040516001600160a01b038516907ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe90600090a35050505050565b6040516366f15f4560e11b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260009182917f0000000000000000000000000000000000000000000000000000000000000000169063cde2be8a90602401602060405180830381865afa158015610cb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd89190612bd7565b6001600160a01b031663a035b1fe6040518163ffffffff1660e01b81526004016040805180830381865afa158015610d14573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d389190612c20565b915091509091565b6040516370a0823160e01b81526001600160a01b038281166004830152600091610dff917f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa158015610dad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd19190612bf4565b610dfa7f0000000000000000000000000000000000000000000000000000000000000000612c53565b6119e5565b92915050565b60008060008060006001600160c01b039050306001600160a01b03166342e359c46040518163ffffffff1660e01b81526004016040805180830381865afa925050508015610e70575060408051601f3d908101601f19168201909252610e6d91810190612c20565b60015b15610e7b5790925090505b600080610e8884846119f3565b915091506000610f9e7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f139190612bf4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f959190612c71565b610dfa90612c53565b9050610fb56001600160c01b038416826000611d21565b9750610fcc6001600160c01b038316826002611d21565b9650866001600160c01b0316886001600160c01b03161115610ff057610ff0612bc1565b5095969495506000949350505050565b600080306001600160a01b0316637d1ea1376040518163ffffffff1660e01b8152600401606060405180830381865afa92505050801561105d575060408051601f3d908101601f1916820190925261105a91810190612b42565b60015b6110b1573d80801561108b576040519150601f19603f3d011682016040523d82523d6000602084013e611090565b606091505b50805160000361109f57600080fd5b506000926001600160c01b0392509050565b816001600160c01b0316836001600160c01b031611156110d3576110d3612bc1565b5090939092509050565b6000807f000000000000000000000000000000000000000000000000000000000000000060ff168360ff161061115b5761113860017f0000000000000000000000000000000000000000000000000000000000000000612c8e565b604051632d85f8df60e21b815260ff909116600482015260240160405180910390fd5b6000670de0b6b3a7640000818060ff87168103611297576111c56001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b93507f000000000000000000000000000000000000000000000000000000000000000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316156112925761126c6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f000000000000000000000000000000000000000000000000000000000000000090505b611615565b8660ff166001036113c6576112f56001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b93507f000000000000000000000000000000000000000000000000000000000000000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316156112925761139c6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f00000000000000000000000000000000000000000000000000000000000000009050611615565b8660ff166002036114f5576114246001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b93507f000000000000000000000000000000000000000000000000000000000000000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031615611292576114cb6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f00000000000000000000000000000000000000000000000000000000000000009050611615565b6115486001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b93507f000000000000000000000000000000000000000000000000000000000000000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031615611615576115ef6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f000000000000000000000000000000000000000000000000000000000000000090505b61162184848484611ea0565b9550955050505050915091565b6002544265ffffffffffff909116116116a45761167c7f000000000000000000000000000000000000000000000000000000000000000061166d611f3e565b6001600160c01b031690611981565b600260066101000a8154816001600160c01b0302191690836001600160c01b03160217905550565b60006116ae610695565b905060006116ba611f3e565b905060006116f16001600160c01b0383167f0000000000000000000000000000000000000000000000000000000000000000611981565b6002549091506001600160c01b03600160301b9091048116908316101561174757600280546601000000000000600160f01b031916600160301b6001600160c01b0384160217815561174290611fca565b61178d565b6002546001600160c01b03600160301b9091048116908216111561178d57600280546601000000000000600160f01b031916600160301b6001600160c01b038416021790555b306001600160a01b0316637d1ea1376040518163ffffffff1660e01b8152600401606060405180830381865afa9250505080156117e7575060408051601f3d908101601f191682019092526117e491810190612b42565b60015b611839573d808015611815576040519150601f19603f3d011682016040523d82523d6000602084013e61181a565b606091505b50805160000361182957600080fd5b6118336001611fca565b506118f8565b6001600160c01b03828116101561189857600080546001600160c01b0319166001600160c01b0385811691909117909155600180549184166001600160f01b031990921691909117600160c01b4265ffffffffffff16021790556118af565b6001600160c01b038316156118af576118af612bc1565b6001600160c01b03831615806118c857506118c86120f0565b806118d657506118d661227e565b156118ea576118e56001611fca565b6118f4565b6118f46000611fca565b5050505b6000611902610695565b905080600281111561191657611916612a8a565b84600281111561192857611928612a8a565b1461197b5780600281111561193f5761193f612a8a565b84600281111561195157611951612a8a565b6040517f99cada7141db4d51b602b2e469ec310c78ffbba0eb05bc3e3e633f30672dea0290600090a35b50505050565b600061198f838360016123c6565b9392505050565b600061198f8284612ca7565b6000818310156119b2578161198f565b5090919050565b60008183106119b2578161198f565b600061198f6119e0670de0b6b3a764000085856123f3565b6124d6565b600061198f83836000612504565b600080600080611a016125d7565b915091506000611aea7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8c9190612bf4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b90506000611b026001600160c01b0385168383611d21565b90506000611b1b6001600160c01b038516846002611d21565b604051634903b0d160e01b815260016004820152909150600090611b8a906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690634903b0d190602401602060405180830381865afa158015611a68573d6000803e3d6000fd5b9050611ba16001600160c01b0384168260006123c6565b9750611bb86001600160c01b0383168260026123c6565b604051634903b0d160e01b8152600060048201819052919850611ca8906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690634903b0d190602401602060405180830381865afa158015611c26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c4a9190612bf4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b9050611cbf6001600160c01b038c168260006123c6565b611cc9908a612cc7565b98506000611cd98b836002612758565b90506001600160c01b03611cf18183168b8316612ce7565b10611d05576001600160c01b039850611d12565b611d0f818a612cc7565b98505b50505050505050509250929050565b6000611d546119e0611d44670de0b6b3a76400006001600160c01b038816612cfa565b856001600160c01b031685612890565b949350505050565b6000806000806000866001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015611da2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc69190612d2b565b9450945050935093508160001480611df557508369ffffffffffffffffffff168169ffffffffffffffffffff16105b15611e1357604051630cd5fa0760e11b815260040160405180910390fd5b6000611e1f8342612c0d565b90508665ffffffffffff168165ffffffffffff161115611e5257604051630cd5fa0760e11b815260040160405180910390fd5b611e9484896001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b98975050505050505050565b600080611f02611ecb611ebb85670de0b6b3a7640000612ca7565b6001600160c01b03881690611981565b6000611ef2611ee288670de0b6b3a7640000612ca7565b6001600160c01b038b1690611981565b6001600160c01b031691906123c6565b9150611f33611f1c611ebb85670de0b6b3a7640000612cc7565b6002611ef2611ee288670de0b6b3a7640000612cc7565b905094509492505050565b6000611fc57f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663bb7b8b806040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fa1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119e09190612bf4565b905090565b6002544265ffffffffffff90911611611fe05750565b6000816002811115611ff457611ff4612a8a565b03612013576002805465ffffffffffff191665ffffffffffff17905550565b600181600281111561202757612027612a8a565b036120ba57600061206065ffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001642612ce7565b905065ffffffffffff811061208a576002805465ffffffffffff191665ffffffffffff1790555050565b60025465ffffffffffff168110156120b6576002805465ffffffffffff191665ffffffffffff83161790555b5050565b60028160028111156120ce576120ce612a8a565b036120ed576002805465ffffffffffff19164265ffffffffffff161790555b50565b6000805b7f000000000000000000000000000000000000000000000000000000000000000060ff168160ff16101561227657604051635a0c800f60e11b815260ff82166004820152309063b419001e906024016040805180830381865afa92505050801561217b575060408051601f3d908101601f1916820190925261217891810190612c20565b60015b6121c6573d8080156121a9576040519150601f19603f3d011682016040523d82523d6000602084013e6121ae565b606091505b5080516000036121bd57600080fd5b60019250505090565b600060026121d48385612cc7565b6121de9190612d91565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160c01b0316816001600160c01b0316108061225157507f00000000000000000000000000000000000000000000000000000000000000006001600160c01b0316816001600160c01b0316115b1561226157600194505050505090565b5050508061226e81612db7565b9150506120f4565b506000905090565b6000306001600160a01b03166342e359c46040518163ffffffff1660e01b81526004016040805180830381865afa9250505080156122d9575060408051601f3d908101601f191682019092526122d691810190612c20565b60015b612323573d808015612307576040519150601f19603f3d011682016040523d82523d6000602084013e61230c565b606091505b50805160000361231b57600080fd5b600191505090565b600060026123318385612cc7565b61233b9190612d91565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160c01b0316816001600160c01b031610806123ae57507f00000000000000000000000000000000000000000000000000000000000000006001600160c01b0316816001600160c01b0316115b156123bd576001935050505090565b50505050600090565b6000611d546119e06123e46001600160c01b03808716908816612cfa565b670de0b6b3a764000085612890565b6000806000612402868661292e565b915091508382106124265760405163f44398f560e01b815260040160405180910390fd5b6000848061243657612436612d7b565b86880990508181111561244a576001830392505b90819003906000859003851680868161246557612465612d7b565b04955080838161247757612477612d7b565b04925080816000038161248c5761248c612d7b565b046001019390930291909101600285810380870282030280870282030280870282030280870282030280870282030280870282030295860290039094029390930295945050505050565b60006001600160c01b038211156125005760405163f44398f560e01b815260040160405180910390fd5b5090565b6000836000036125165750600061198f565b605f198360000b1361254f57600282600281111561253657612536612a8a565b14612542576000612545565b60015b60ff16905061198f565b8260000b6028136125735760405163f44398f560e01b815260040160405180910390fd5b61257e601284612dd6565b9250600061258e8460000b61295b565b61259990600a612ed3565b90506000808560000b12156125b8576125b3868386612890565b6125c2565b6125c28287612cfa565b90506125cd816124d6565b9695505050505050565b60008060005b7f000000000000000000000000000000000000000000000000000000000000000060ff168160ff16101561275357600061261682612973565b604051634903b0d160e01b815260ff841660048201529091506000906126e9906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690634903b0d190602401602060405180830381865afa158015612687573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ab9190612bf4565b836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b90506000806126f7856110dd565b90925090506127116001600160c01b0384168360006123c6565b61271b9088612cc7565b96506127326001600160c01b0384168260026123c6565b61273c9087612cc7565b9550505050508061274c90612db7565b90506125dd565b509091565b60006001600160c01b038416158061277757506001600160c01b038316155b156127845750600061198f565b6001600160c01b0384811614806127a357506001600160c01b03838116145b156127b657506001600160c01b0361198f565b6001600160c01b038381169085168181029182816127d6576127d6612d7b565b04146127ec576001600160c01b0391505061198f565b80600184600281111561280157612801612a8a565b03612815576706f05b59d3b2000001612839565b600284600281111561282957612829612a8a565b0361283957670de0b6b3a763ffff015b81811015612852576001600160c01b039250505061198f565b6001600160c01b03670de0b6b3a76400008204111561287c576001600160c01b039250505061198f565b670de0b6b3a7640000900495945050505050565b60008061289d8486612edf565b905060008360028111156128b3576128b3612a8a565b036128bf57905061198f565b60018360028111156128d3576128d3612a8a565b036129125760026128e5600186612c0d565b6128ef9190612edf565b6128f98587612ef3565b111561290d578061290981612f07565b9150505b611d54565b600061291e8587612ef3565b1115611d5457806125cd81612f07565b6000808060001984860990508385029150818103925081811015612953576001830392505b509250929050565b600080821261296a5781610dff565b610dff82612f20565b60007f000000000000000000000000000000000000000000000000000000000000000060ff168260ff16106129cd5761113860017f0000000000000000000000000000000000000000000000000000000000000000612c8e565b8160ff166000036129ff57507f0000000000000000000000000000000000000000000000000000000000000000919050565b8160ff16600103612a3157507f0000000000000000000000000000000000000000000000000000000000000000919050565b8160ff16600203612a6357507f0000000000000000000000000000000000000000000000000000000000000000919050565b507f0000000000000000000000000000000000000000000000000000000000000000919050565b634e487b7160e01b600052602160045260246000fd5b6020810160038310612ac257634e487b7160e01b600052602160045260246000fd5b91905290565b6001600160a01b03811681146120ed57600080fd5b600060208284031215612aef57600080fd5b813561198f81612ac8565b60ff811681146120ed57600080fd5b600060208284031215612b1b57600080fd5b813561198f81612afa565b80516001600160c01b0381168114612b3d57600080fd5b919050565b600080600060608486031215612b5757600080fd5b612b6084612b26565b9250612b6e60208501612b26565b9150612b7c60408501612b26565b90509250925092565b634e487b7160e01b600052601160045260246000fd5b65ffffffffffff828116828216039080821115612bba57612bba612b85565b5092915050565b634e487b7160e01b600052600160045260246000fd5b600060208284031215612be957600080fd5b815161198f81612ac8565b600060208284031215612c0657600080fd5b5051919050565b81810381811115610dff57610dff612b85565b60008060408385031215612c3357600080fd5b612c3c83612b26565b9150612c4a60208401612b26565b90509250929050565b600081810b60808101612c6857612c68612b85565b60000392915050565b600060208284031215612c8357600080fd5b815161198f81612afa565b60ff8281168282160390811115610dff57610dff612b85565b6001600160c01b03828116828216039080821115612bba57612bba612b85565b6001600160c01b03818116838216019080821115612bba57612bba612b85565b80820180821115610dff57610dff612b85565b8082028115828204841417610dff57610dff612b85565b805169ffffffffffffffffffff81168114612b3d57600080fd5b600080600080600060a08688031215612d4357600080fd5b612d4c86612d11565b9450602086015193506040860151925060608601519150612d6f60808701612d11565b90509295509295909350565b634e487b7160e01b600052601260045260246000fd5b60006001600160c01b0383811680612dab57612dab612d7b565b92169190910492915050565b600060ff821660ff8103612dcd57612dcd612b85565b60010192915050565b600081810b9083900b01607f8113607f1982121715610dff57610dff612b85565b600181815b80851115612953578160001904821115612e1857612e18612b85565b80851615612e2557918102915b93841c9390800290612dfc565b600082612e4157506001610dff565b81612e4e57506000610dff565b8160018114612e645760028114612e6e57612e8a565b6001915050610dff565b60ff841115612e7f57612e7f612b85565b50506001821b610dff565b5060208310610133831016604e8410600b8410161715612ead575081810a610dff565b612eb78383612df7565b8060001904821115612ecb57612ecb612b85565b029392505050565b600061198f8383612e32565b600082612eee57612eee612d7b565b500490565b600082612f0257612f02612d7b565b500690565b600060018201612f1957612f19612b85565b5060010190565b6000600160ff1b8201612f3557612f35612b85565b506000039056fea26469706673582212204a3b8c820a143a61e31ae4e49c576deb395050e6cbaaa71febc19b5fd5001bb564736f6c634300081100330000000000000000000000000000000000000000000000000000000000093a800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000083cd6bd8591ac6090bd336c96e61062c103f0ad900000000000000000000000000000000000000000000d3c21bcecceda10000000000000000000000000000000000000000000000000000000000000000000001555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000000000000003f480000000000000000000000000000000000000000000000000000000e8d4a5100000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f00000000000000000000000000000000000000000000000000470de4df8200000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000dcef968d416a41cdac0ed8702fac8128a64241a20000000000000000000000003175df0976dfa876431c2e9ee6bc45b65d3473cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b9e1e3a9feff48998e45fa90847ed4d467e8bcfd00000000000000000000000000000000000000000000000000000000000000010000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000e4c000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000151bc0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000008e1bc9bf04000

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102115760003560e01c806395acc4ae11610125578063c55f29d1116100ad578063ddc0c7c81161007c578063ddc0c7c814610605578063e6a1505314610618578063f8ac93e81461063f578063fdfd591714610647578063ffc94f901461066e57600080fd5b8063c55f29d1146105a7578063c59b3d63146105ce578063cde5b5ee146105dd578063d9e8e670146105f757600080fd5b8063a7fa0faf116100f4578063a7fa0faf14610507578063abfeece51461051f578063ae4e187514610546578063b419001e1461056d578063b94d87391461058057600080fd5b806395acc4ae146104ac57806396f80ae9146104d35780639ec07272146104ec578063a035b1fe146104ff57600080fd5b80635056ffa6116101a857806374b629541161017757806374b62954146103de578063785e9e86146104055780637d1ea1371461042c5780637dbdf1f51461045e5780638f77968f1461048557600080fd5b80635056ffa61461033e5780635580f72a146103655780635fcbd285146103905780637020bc7d146103b757600080fd5b80632dc86624116101e45780632dc86624146102d9578063372500ab146102f35780633cb5d379146102fd57806342e359c41461033657600080fd5b8063200d2ed214610216578063218751b214610234578063271181ec146102735780632bcfaa801461029b575b600080fd5b61021e610695565b60405161022b9190612aa0565b60405180910390f35b61025b7f000000000000000000000000dcef968d416a41cdac0ed8702fac8128a64241a281565b6040516001600160a01b03909116815260200161022b565b61027b6106d6565b604080516001600160c01b0393841681529290911660208301520161022b565b6102c27f0000000000000000000000000000000000000000000000000000000000093a8081565b60405165ffffffffffff909116815260200161022b565b60025465ffffffffffff165b60405190815260200161022b565b6102fb6108a7565b005b6103247f000000000000000000000000000000000000000000000000000000000000001281565b60405160ff909116815260200161022b565b61027b610c29565b61025b7f000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f81565b610378610373366004612add565b610d40565b6040516001600160c01b03909116815260200161022b565b61025b7f0000000000000000000000003175df0976dfa876431c2e9ee6bc45b65d3473cc81565b6103787f0000000000000000000000000000000000000000000000000d99a8cec7e2000081565b6103787f0000000000000000000000000000000000000000000000000de0b5cad2bef00081565b61025b7f00000000000000000000000083cd6bd8591ac6090bd336c96e61062c103f0ad981565b610434610e05565b604080516001600160c01b039485168152928416602084015292169181019190915260600161022b565b61025b7f000000000000000000000000000000000000000000000000000000000000000181565b6103787f0000000000000000000000000000000000000000000000000e27c49886e6000081565b6103787f00000000000000000000000000000000000000000000d3c21bcecceda100000081565b6001546102c290600160c01b900465ffffffffffff1681565b600154610378906001600160c01b031681565b61027b611000565b600254600160301b90046001600160c01b0316610378565b6102c27f000000000000000000000000000000000000000000000000000000000000000181565b6103787f0000000000000000000000000000000000000000000000000e27c49886e6000081565b61027b61057b366004612b09565b6110dd565b6103787f0000000000000000000000000000000000000000000000000d99a8cec7e2000081565b6103787f000000000000000000000000000000000000000000000000000000000000000181565b6040516001815260200161022b565b60025461037890600160301b90046001600160c01b031681565b670de0b6b3a7640000610378565b600054610378906001600160c01b031681565b6102c27f000000000000000000000000000000000000000000000000000000000003f48081565b6102fb61162e565b6102e57f555344000000000000000000000000000000000000000000000000000000000081565b61025b7f000000000000000000000000a0d69e286b938e21cbf7e51d71f6a4c8918f482f81565b60025460009065ffffffffffff1665fffffffffffe19016106b65750600090565b6002544265ffffffffffff90911611156106d05750600190565b50600290565b600080306001600160a01b0316637d1ea1376040518163ffffffff1660e01b8152600401606060405180830381865afa925050508015610733575060408051601f3d908101601f1916820190925261073091810190612b42565b60015b61087a573d808015610761576040519150601f19603f3d011682016040523d82523d6000602084013e610766565b606091505b50805160000361077557600080fd5b60015460009061079490600160c01b900465ffffffffffff1642612b9b565b90507f0000000000000000000000000000000000000000000000000000000000093a8065ffffffffffff168165ffffffffffff16106107d95750600093849350915050565b600061083e610808837f0000000000000000000000000000000000000000000000000000000000093a80612b9b565b65ffffffffffff167f0000000000000000000000000000000000000000000000000000000000093a8065ffffffffffff166119c8565b600054909150610857906001600160c01b031682611981565b600154909550610870906001600160c01b031682611981565b9350505050610881565b5090925090505b806001600160c01b0316826001600160c01b031611156108a3576108a3612bc1565b9091565b60007f00000000000000000000000083cd6bd8591ac6090bd336c96e61062c103f0ad990506000816001600160a01b031663923c1d616040518163ffffffff1660e01b81526004016020604051808303816000875af115801561090e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109329190612bd7565b90506000826001600160a01b0316636a4874a16040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610976573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061099a9190612bd7565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156109e4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a089190612bf4565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610a52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a769190612bf4565b604051630c00007b60e41b81523060048201529091506001600160a01b0386169063c00007b090602401600060405180830381600087803b158015610aba57600080fd5b505af1158015610ace573d6000803e3d6000fd5b50506040516370a0823160e01b81523060048201528492506001600160a01b03871691506370a0823190602401602060405180830381865afa158015610b18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3c9190612bf4565b610b469190612c0d565b6040516001600160a01b038616907ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe90600090a36040516370a0823160e01b815230600482015281906001600160a01b038516906370a0823190602401602060405180830381865afa158015610bc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610be49190612bf4565b610bee9190612c0d565b6040516001600160a01b038516907ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe90600090a35050505050565b6040516366f15f4560e11b81526001600160a01b037f000000000000000000000000a0d69e286b938e21cbf7e51d71f6a4c8918f482f8116600483015260009182917f0000000000000000000000009b85ac04a09c8c813c37de9b3d563c2d3f936162169063cde2be8a90602401602060405180830381865afa158015610cb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd89190612bd7565b6001600160a01b031663a035b1fe6040518163ffffffff1660e01b81526004016040805180830381865afa158015610d14573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d389190612c20565b915091509091565b6040516370a0823160e01b81526001600160a01b038281166004830152600091610dff917f00000000000000000000000083cd6bd8591ac6090bd336c96e61062c103f0ad916906370a0823190602401602060405180830381865afa158015610dad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd19190612bf4565b610dfa7f0000000000000000000000000000000000000000000000000000000000000012612c53565b6119e5565b92915050565b60008060008060006001600160c01b039050306001600160a01b03166342e359c46040518163ffffffff1660e01b81526004016040805180830381865afa925050508015610e70575060408051601f3d908101601f19168201909252610e6d91810190612c20565b60015b15610e7b5790925090505b600080610e8884846119f3565b915091506000610f9e7f000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f6001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f139190612bf4565b7f000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f959190612c71565b610dfa90612c53565b9050610fb56001600160c01b038416826000611d21565b9750610fcc6001600160c01b038316826002611d21565b9650866001600160c01b0316886001600160c01b03161115610ff057610ff0612bc1565b5095969495506000949350505050565b600080306001600160a01b0316637d1ea1376040518163ffffffff1660e01b8152600401606060405180830381865afa92505050801561105d575060408051601f3d908101601f1916820190925261105a91810190612b42565b60015b6110b1573d80801561108b576040519150601f19603f3d011682016040523d82523d6000602084013e611090565b606091505b50805160000361109f57600080fd5b506000926001600160c01b0392509050565b816001600160c01b0316836001600160c01b031611156110d3576110d3612bc1565b5090939092509050565b6000807f000000000000000000000000000000000000000000000000000000000000000260ff168360ff161061115b5761113860017f0000000000000000000000000000000000000000000000000000000000000002612c8e565b604051632d85f8df60e21b815260ff909116600482015260240160405180910390fd5b6000670de0b6b3a7640000818060ff87168103611297576111c56001600160a01b037f000000000000000000000000b9e1e3a9feff48998e45fa90847ed4d467e8bcfd167f0000000000000000000000000000000000000000000000000000000000000e4c611d5c565b93507f000000000000000000000000000000000000000000000000002386f26fc1000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316156112925761126c6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f000000000000000000000000000000000000000000000000000000000000000090505b611615565b8660ff166001036113c6576112f56001600160a01b037f0000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f6167f00000000000000000000000000000000000000000000000000000000000151bc611d5c565b93507f0000000000000000000000000000000000000000000000000008e1bc9bf0400091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316156112925761139c6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f00000000000000000000000000000000000000000000000000000000000000009050611615565b8660ff166002036114f5576114246001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b93507f000000000000000000000000000000000000000000000000000000000000000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031615611292576114cb6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f00000000000000000000000000000000000000000000000000000000000000009050611615565b6115486001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b93507f000000000000000000000000000000000000000000000000000000000000000091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031615611615576115ef6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000611d5c565b92507f000000000000000000000000000000000000000000000000000000000000000090505b61162184848484611ea0565b9550955050505050915091565b6002544265ffffffffffff909116116116a45761167c7f0000000000000000000000000000000000000000000000000de0b5cad2bef00061166d611f3e565b6001600160c01b031690611981565b600260066101000a8154816001600160c01b0302191690836001600160c01b03160217905550565b60006116ae610695565b905060006116ba611f3e565b905060006116f16001600160c01b0383167f0000000000000000000000000000000000000000000000000de0b5cad2bef000611981565b6002549091506001600160c01b03600160301b9091048116908316101561174757600280546601000000000000600160f01b031916600160301b6001600160c01b0384160217815561174290611fca565b61178d565b6002546001600160c01b03600160301b9091048116908216111561178d57600280546601000000000000600160f01b031916600160301b6001600160c01b038416021790555b306001600160a01b0316637d1ea1376040518163ffffffff1660e01b8152600401606060405180830381865afa9250505080156117e7575060408051601f3d908101601f191682019092526117e491810190612b42565b60015b611839573d808015611815576040519150601f19603f3d011682016040523d82523d6000602084013e61181a565b606091505b50805160000361182957600080fd5b6118336001611fca565b506118f8565b6001600160c01b03828116101561189857600080546001600160c01b0319166001600160c01b0385811691909117909155600180549184166001600160f01b031990921691909117600160c01b4265ffffffffffff16021790556118af565b6001600160c01b038316156118af576118af612bc1565b6001600160c01b03831615806118c857506118c86120f0565b806118d657506118d661227e565b156118ea576118e56001611fca565b6118f4565b6118f46000611fca565b5050505b6000611902610695565b905080600281111561191657611916612a8a565b84600281111561192857611928612a8a565b1461197b5780600281111561193f5761193f612a8a565b84600281111561195157611951612a8a565b6040517f99cada7141db4d51b602b2e469ec310c78ffbba0eb05bc3e3e633f30672dea0290600090a35b50505050565b600061198f838360016123c6565b9392505050565b600061198f8284612ca7565b6000818310156119b2578161198f565b5090919050565b60008183106119b2578161198f565b600061198f6119e0670de0b6b3a764000085856123f3565b6124d6565b600061198f83836000612504565b600080600080611a016125d7565b915091506000611aea7f0000000000000000000000003175df0976dfa876431c2e9ee6bc45b65d3473cc6001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8c9190612bf4565b7f0000000000000000000000003175df0976dfa876431c2e9ee6bc45b65d3473cc6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b90506000611b026001600160c01b0385168383611d21565b90506000611b1b6001600160c01b038516846002611d21565b604051634903b0d160e01b815260016004820152909150600090611b8a906001600160a01b037f000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f1690634903b0d190602401602060405180830381865afa158015611a68573d6000803e3d6000fd5b9050611ba16001600160c01b0384168260006123c6565b9750611bb86001600160c01b0383168260026123c6565b604051634903b0d160e01b8152600060048201819052919850611ca8906001600160a01b037f000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f1690634903b0d190602401602060405180830381865afa158015611c26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c4a9190612bf4565b7f000000000000000000000000a0d69e286b938e21cbf7e51d71f6a4c8918f482f6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b9050611cbf6001600160c01b038c168260006123c6565b611cc9908a612cc7565b98506000611cd98b836002612758565b90506001600160c01b03611cf18183168b8316612ce7565b10611d05576001600160c01b039850611d12565b611d0f818a612cc7565b98505b50505050505050509250929050565b6000611d546119e0611d44670de0b6b3a76400006001600160c01b038816612cfa565b856001600160c01b031685612890565b949350505050565b6000806000806000866001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015611da2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc69190612d2b565b9450945050935093508160001480611df557508369ffffffffffffffffffff168169ffffffffffffffffffff16105b15611e1357604051630cd5fa0760e11b815260040160405180910390fd5b6000611e1f8342612c0d565b90508665ffffffffffff168165ffffffffffff161115611e5257604051630cd5fa0760e11b815260040160405180910390fd5b611e9484896001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b98975050505050505050565b600080611f02611ecb611ebb85670de0b6b3a7640000612ca7565b6001600160c01b03881690611981565b6000611ef2611ee288670de0b6b3a7640000612ca7565b6001600160c01b038b1690611981565b6001600160c01b031691906123c6565b9150611f33611f1c611ebb85670de0b6b3a7640000612cc7565b6002611ef2611ee288670de0b6b3a7640000612cc7565b905094509492505050565b6000611fc57f000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f6001600160a01b031663bb7b8b806040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fa1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119e09190612bf4565b905090565b6002544265ffffffffffff90911611611fe05750565b6000816002811115611ff457611ff4612a8a565b03612013576002805465ffffffffffff191665ffffffffffff17905550565b600181600281111561202757612027612a8a565b036120ba57600061206065ffffffffffff7f000000000000000000000000000000000000000000000000000000000003f4801642612ce7565b905065ffffffffffff811061208a576002805465ffffffffffff191665ffffffffffff1790555050565b60025465ffffffffffff168110156120b6576002805465ffffffffffff191665ffffffffffff83161790555b5050565b60028160028111156120ce576120ce612a8a565b036120ed576002805465ffffffffffff19164265ffffffffffff161790555b50565b6000805b7f000000000000000000000000000000000000000000000000000000000000000260ff168160ff16101561227657604051635a0c800f60e11b815260ff82166004820152309063b419001e906024016040805180830381865afa92505050801561217b575060408051601f3d908101601f1916820190925261217891810190612c20565b60015b6121c6573d8080156121a9576040519150601f19603f3d011682016040523d82523d6000602084013e6121ae565b606091505b5080516000036121bd57600080fd5b60019250505090565b600060026121d48385612cc7565b6121de9190612d91565b90507f0000000000000000000000000000000000000000000000000d99a8cec7e200006001600160c01b0316816001600160c01b0316108061225157507f0000000000000000000000000000000000000000000000000e27c49886e600006001600160c01b0316816001600160c01b0316115b1561226157600194505050505090565b5050508061226e81612db7565b9150506120f4565b506000905090565b6000306001600160a01b03166342e359c46040518163ffffffff1660e01b81526004016040805180830381865afa9250505080156122d9575060408051601f3d908101601f191682019092526122d691810190612c20565b60015b612323573d808015612307576040519150601f19603f3d011682016040523d82523d6000602084013e61230c565b606091505b50805160000361231b57600080fd5b600191505090565b600060026123318385612cc7565b61233b9190612d91565b90507f0000000000000000000000000000000000000000000000000d99a8cec7e200006001600160c01b0316816001600160c01b031610806123ae57507f0000000000000000000000000000000000000000000000000e27c49886e600006001600160c01b0316816001600160c01b0316115b156123bd576001935050505090565b50505050600090565b6000611d546119e06123e46001600160c01b03808716908816612cfa565b670de0b6b3a764000085612890565b6000806000612402868661292e565b915091508382106124265760405163f44398f560e01b815260040160405180910390fd5b6000848061243657612436612d7b565b86880990508181111561244a576001830392505b90819003906000859003851680868161246557612465612d7b565b04955080838161247757612477612d7b565b04925080816000038161248c5761248c612d7b565b046001019390930291909101600285810380870282030280870282030280870282030280870282030280870282030280870282030295860290039094029390930295945050505050565b60006001600160c01b038211156125005760405163f44398f560e01b815260040160405180910390fd5b5090565b6000836000036125165750600061198f565b605f198360000b1361254f57600282600281111561253657612536612a8a565b14612542576000612545565b60015b60ff16905061198f565b8260000b6028136125735760405163f44398f560e01b815260040160405180910390fd5b61257e601284612dd6565b9250600061258e8460000b61295b565b61259990600a612ed3565b90506000808560000b12156125b8576125b3868386612890565b6125c2565b6125c28287612cfa565b90506125cd816124d6565b9695505050505050565b60008060005b7f000000000000000000000000000000000000000000000000000000000000000260ff168160ff16101561275357600061261682612973565b604051634903b0d160e01b815260ff841660048201529091506000906126e9906001600160a01b037f000000000000000000000000dcef968d416a41cdac0ed8702fac8128a64241a21690634903b0d190602401602060405180830381865afa158015612687573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ab9190612bf4565b836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f71573d6000803e3d6000fd5b90506000806126f7856110dd565b90925090506127116001600160c01b0384168360006123c6565b61271b9088612cc7565b96506127326001600160c01b0384168260026123c6565b61273c9087612cc7565b9550505050508061274c90612db7565b90506125dd565b509091565b60006001600160c01b038416158061277757506001600160c01b038316155b156127845750600061198f565b6001600160c01b0384811614806127a357506001600160c01b03838116145b156127b657506001600160c01b0361198f565b6001600160c01b038381169085168181029182816127d6576127d6612d7b565b04146127ec576001600160c01b0391505061198f565b80600184600281111561280157612801612a8a565b03612815576706f05b59d3b2000001612839565b600284600281111561282957612829612a8a565b0361283957670de0b6b3a763ffff015b81811015612852576001600160c01b039250505061198f565b6001600160c01b03670de0b6b3a76400008204111561287c576001600160c01b039250505061198f565b670de0b6b3a7640000900495945050505050565b60008061289d8486612edf565b905060008360028111156128b3576128b3612a8a565b036128bf57905061198f565b60018360028111156128d3576128d3612a8a565b036129125760026128e5600186612c0d565b6128ef9190612edf565b6128f98587612ef3565b111561290d578061290981612f07565b9150505b611d54565b600061291e8587612ef3565b1115611d5457806125cd81612f07565b6000808060001984860990508385029150818103925081811015612953576001830392505b509250929050565b600080821261296a5781610dff565b610dff82612f20565b60007f000000000000000000000000000000000000000000000000000000000000000260ff168260ff16106129cd5761113860017f0000000000000000000000000000000000000000000000000000000000000002612c8e565b8160ff166000036129ff57507f000000000000000000000000853d955acef822db058eb8505911ed77f175b99e919050565b8160ff16600103612a3157507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48919050565b8160ff16600203612a6357507f0000000000000000000000000000000000000000000000000000000000000000919050565b507f0000000000000000000000000000000000000000000000000000000000000000919050565b634e487b7160e01b600052602160045260246000fd5b6020810160038310612ac257634e487b7160e01b600052602160045260246000fd5b91905290565b6001600160a01b03811681146120ed57600080fd5b600060208284031215612aef57600080fd5b813561198f81612ac8565b60ff811681146120ed57600080fd5b600060208284031215612b1b57600080fd5b813561198f81612afa565b80516001600160c01b0381168114612b3d57600080fd5b919050565b600080600060608486031215612b5757600080fd5b612b6084612b26565b9250612b6e60208501612b26565b9150612b7c60408501612b26565b90509250925092565b634e487b7160e01b600052601160045260246000fd5b65ffffffffffff828116828216039080821115612bba57612bba612b85565b5092915050565b634e487b7160e01b600052600160045260246000fd5b600060208284031215612be957600080fd5b815161198f81612ac8565b600060208284031215612c0657600080fd5b5051919050565b81810381811115610dff57610dff612b85565b60008060408385031215612c3357600080fd5b612c3c83612b26565b9150612c4a60208401612b26565b90509250929050565b600081810b60808101612c6857612c68612b85565b60000392915050565b600060208284031215612c8357600080fd5b815161198f81612afa565b60ff8281168282160390811115610dff57610dff612b85565b6001600160c01b03828116828216039080821115612bba57612bba612b85565b6001600160c01b03818116838216019080821115612bba57612bba612b85565b80820180821115610dff57610dff612b85565b8082028115828204841417610dff57610dff612b85565b805169ffffffffffffffffffff81168114612b3d57600080fd5b600080600080600060a08688031215612d4357600080fd5b612d4c86612d11565b9450602086015193506040860151925060608601519150612d6f60808701612d11565b90509295509295909350565b634e487b7160e01b600052601260045260246000fd5b60006001600160c01b0383811680612dab57612dab612d7b565b92169190910492915050565b600060ff821660ff8103612dcd57612dcd612b85565b60010192915050565b600081810b9083900b01607f8113607f1982121715610dff57610dff612b85565b600181815b80851115612953578160001904821115612e1857612e18612b85565b80851615612e2557918102915b93841c9390800290612dfc565b600082612e4157506001610dff565b81612e4e57506000610dff565b8160018114612e645760028114612e6e57612e8a565b6001915050610dff565b60ff841115612e7f57612e7f612b85565b50506001821b610dff565b5060208310610133831016604e8410600b8410161715612ead575081810a610dff565b612eb78383612df7565b8060001904821115612ecb57612ecb612b85565b029392505050565b600061198f8383612e32565b600082612eee57612eee612d7b565b500490565b600082612f0257612f02612d7b565b500690565b600060018201612f1957612f19612b85565b5060010190565b6000600160ff1b8201612f3557612f35612b85565b506000039056fea26469706673582212204a3b8c820a143a61e31ae4e49c576deb395050e6cbaaa71febc19b5fd5001bb564736f6c63430008110033

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

0000000000000000000000000000000000000000000000000000000000093a800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000083cd6bd8591ac6090bd336c96e61062c103f0ad900000000000000000000000000000000000000000000d3c21bcecceda10000000000000000000000000000000000000000000000000000000000000000000001555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000000000000003f480000000000000000000000000000000000000000000000000000000e8d4a5100000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f00000000000000000000000000000000000000000000000000470de4df8200000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000dcef968d416a41cdac0ed8702fac8128a64241a20000000000000000000000003175df0976dfa876431c2e9ee6bc45b65d3473cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b9e1e3a9feff48998e45fa90847ed4d467e8bcfd00000000000000000000000000000000000000000000000000000000000000010000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000e4c000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000151bc0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000008e1bc9bf04000

-----Decoded View---------------
Arg [0] : config (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : revenueHiding (uint192): 1000000000000
Arg [2] : ptConfig (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [3] : metapoolToken_ (address): 0xAEda92e6A3B1028edc139A4ae56Ec881f3064D4F
Arg [4] : pairedTokenDefaultThreshold_ (uint192): 20000000000000000

-----Encoded View---------------
41 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000093a80
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [3] : 00000000000000000000000083cd6bd8591ac6090bd336c96e61062c103f0ad9
Arg [4] : 00000000000000000000000000000000000000000000d3c21bcecceda1000000
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [6] : 5553440000000000000000000000000000000000000000000000000000000000
Arg [7] : 00000000000000000000000000000000000000000000000000470de4df820000
Arg [8] : 000000000000000000000000000000000000000000000000000000000003f480
Arg [9] : 000000000000000000000000000000000000000000000000000000e8d4a51000
Arg [10] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [11] : 000000000000000000000000aeda92e6a3b1028edc139a4ae56ec881f3064d4f
Arg [12] : 00000000000000000000000000000000000000000000000000470de4df820000
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [14] : 000000000000000000000000dcef968d416a41cdac0ed8702fac8128a64241a2
Arg [15] : 0000000000000000000000003175df0976dfa876431c2e9ee6bc45b65d3473cc
Arg [16] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [17] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [18] : 00000000000000000000000000000000000000000000000000000000000001c0
Arg [19] : 00000000000000000000000000000000000000000000000000000000000002a0
Arg [20] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [21] : 0000000000000000000000000000000000000000000000000000000000000040
Arg [22] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [23] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [24] : 000000000000000000000000b9e1e3a9feff48998e45fa90847ed4d467e8bcfd
Arg [25] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [26] : 0000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f6
Arg [27] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [28] : 0000000000000000000000000000000000000000000000000000000000000040
Arg [29] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [30] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [31] : 0000000000000000000000000000000000000000000000000000000000000e4c
Arg [32] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [33] : 00000000000000000000000000000000000000000000000000000000000151bc
Arg [34] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [35] : 0000000000000000000000000000000000000000000000000000000000000040
Arg [36] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [37] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [38] : 000000000000000000000000000000000000000000000000002386f26fc10000
Arg [39] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [40] : 0000000000000000000000000000000000000000000000000008e1bc9bf04000


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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