ETH Price: $3,942.27 (+5.87%)

Contract

0x4986fD36b6b16f49b43282Ee2e24C5cF90ed166d
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Approve202502182024-07-06 21:40:59151 days ago1720302059IN
0x4986fD36...F90ed166d
0 ETH0.000036081.48225225
Approve197351922024-04-25 21:53:23223 days ago1714082003IN
0x4986fD36...F90ed166d
0 ETH0.000146076
Approve190477652024-01-20 11:25:35320 days ago1705749935IN
0x4986fD36...F90ed166d
0 ETH0.000342514.06812256
Redeem183792462023-10-18 19:13:11413 days ago1697656391IN
0x4986fD36...F90ed166d
0 ETH0.003001213.80364601
Redeem182894662023-10-06 5:46:23426 days ago1696571183IN
0x4986fD36...F90ed166d
0 ETH0.001347926.19926316
Redeem180552222023-09-03 9:57:23459 days ago1693735043IN
0x4986fD36...F90ed166d
0 ETH0.001979349.88085772
Redeem178480072023-08-05 9:54:47488 days ago1691229287IN
0x4986fD36...F90ed166d
0 ETH0.0026874613.41580893
Redeem177075172023-07-16 18:05:35507 days ago1689530735IN
0x4986fD36...F90ed166d
0 ETH0.0028390813.20560315
Redeem175675302023-06-27 1:44:59527 days ago1687830299IN
0x4986fD36...F90ed166d
0 ETH0.0026135612.02077716
Redeem174735922023-06-13 20:57:47540 days ago1686689867IN
0x4986fD36...F90ed166d
0 ETH0.0031093515.52184121
Redeem172603022023-05-14 19:55:47570 days ago1684094147IN
0x4986fD36...F90ed166d
0 ETH0.0083528641.69739675
Redeem169726292023-04-04 2:32:23611 days ago1680575543IN
0x4986fD36...F90ed166d
0 ETH0.0037153519.01245093
Approve167812042023-03-08 4:36:47638 days ago1678250207IN
0x4986fD36...F90ed166d
0 ETH0.0010175121.82102699
Redeem166499492023-02-17 17:36:47656 days ago1676655407IN
0x4986fD36...F90ed166d
0 ETH0.0179186982.45420216
Redeem166249832023-02-14 5:43:35660 days ago1676353415IN
0x4986fD36...F90ed166d
0 ETH0.0027066513.51941609
Approve166038352023-02-11 6:49:47663 days ago1676098187IN
0x4986fD36...F90ed166d
0 ETH0.0008347217.9010977
Redeem166033342023-02-11 5:08:59663 days ago1676092139IN
0x4986fD36...F90ed166d
0 ETH0.0036909716.98332973
Redeem165980692023-02-10 11:30:35664 days ago1676028635IN
0x4986fD36...F90ed166d
0 ETH0.0039972519.96342909
Approve165566942023-02-04 16:45:35669 days ago1675529135IN
0x4986fD36...F90ed166d
0 ETH0.0014531331.16312929
Deposit165472062023-02-03 8:57:35671 days ago1675414655IN
0x4986fD36...F90ed166d
0 ETH0.0051665121.81641362
Send Fees165378832023-02-02 1:36:23672 days ago1675301783IN
0x4986fD36...F90ed166d
0 ETH0.0064324925.45537248
Redeem165328692023-02-01 8:47:23673 days ago1675241243IN
0x4986fD36...F90ed166d
0 ETH0.0036064316.78389689
Redeem165306232023-02-01 1:15:23673 days ago1675214123IN
0x4986fD36...F90ed166d
0 ETH0.0037485118.72000951
Redeem164896982023-01-26 8:08:59679 days ago1674720539IN
0x4986fD36...F90ed166d
0 ETH0.0032033914.7422874
Redeem164799502023-01-24 23:27:47680 days ago1674602867IN
0x4986fD36...F90ed166d
0 ETH0.0051797225.87057855
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Cellar

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 34 : Cellar.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import { ERC4626, SafeERC20 } from "./ERC4626.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { Registry } from "src/Registry.sol";
import { SwapRouter } from "src/modules/swap-router/SwapRouter.sol";
import { PriceRouter } from "src/modules/price-router/PriceRouter.sol";
import { IGravity } from "src/interfaces/external/IGravity.sol";
import { AddressArray } from "src/utils/AddressArray.sol";
import { Math } from "../utils/Math.sol";
// import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { Owned } from "@solmate/auth/Owned.sol";
import { ReentrancyGuard } from "@solmate/utils/ReentrancyGuard.sol";

/**
 * @title Sommelier Cellar
 * @notice A composable ERC4626 that can use a set of other ERC4626 or ERC20 positions to earn yield.
 * @author Brian Le
 */
contract Cellar is ERC4626, Owned, ReentrancyGuard {
    using AddressArray for address[];
    using AddressArray for ERC20[];
    using SafeERC20 for ERC20;
    using SafeCast for uint256;
    using Math for uint256;

    // ========================================= POSITIONS CONFIG =========================================

    /**
     * @notice Emitted when a position is added.
     * @param position address of position that was added
     * @param index index that position was added at
     */
    event PositionAdded(address indexed position, uint256 index);

    /**
     * @notice Emitted when a position is removed.
     * @param position address of position that was removed
     * @param index index that position was removed from
     */
    event PositionRemoved(address indexed position, uint256 index);

    /**
     * @notice Emitted when the positions at two indexes are swapped.
     * @param newPosition1 address of position (previously at index2) that replaced index1.
     * @param newPosition2 address of position (previously at index1) that replaced index2.
     * @param index1 index of first position involved in the swap
     * @param index2 index of second position involved in the swap.
     */
    event PositionSwapped(address indexed newPosition1, address indexed newPosition2, uint256 index1, uint256 index2);

    /**
     * @notice Attempted an operation on an untrusted position.
     * @param position address of the position
     */
    error Cellar__UntrustedPosition(address position);

    /**
     * @notice Attempted to add a position that is already being used.
     * @param position address of the position
     */
    error Cellar__PositionAlreadyUsed(address position);

    /**
     * @notice Attempted an action on a position that is required to be empty before the action can be performed.
     * @param position address of the non-empty position
     * @param sharesRemaining amount of shares remaining in the position
     */
    error Cellar__PositionNotEmpty(address position, uint256 sharesRemaining);

    /**
     * @notice Attempted an operation with an asset that was different then the one expected.
     * @param asset address of the asset
     * @param expectedAsset address of the expected asset
     */
    error Cellar__AssetMismatch(address asset, address expectedAsset);

    /**
     * @notice Attempted an action on a position that is not being used by the cellar but must be for
     *         the operation to succeed.
     * @param position address of the invalid position
     */
    error Cellar__InvalidPosition(address position);

    /**
     * @notice Attempted to remove holding position.
     */
    error Cellar__RemoveHoldingPosition();

    /**
     * @notice Attempted to add a position when the position array is full.
     * @param maxPositions maximum number of positions that can be used
     */
    error Cellar__PositionArrayFull(uint256 maxPositions);

    /**
     * @notice Value specifying the interface a position uses.
     * @param ERC20 an ERC20 token
     * @param ERC4626 an ERC4626 vault
     * @param Cellar a cellar
     */
    enum PositionType {
        ERC20,
        ERC4626,
        Cellar
    }

    /**
     * @notice Addresses of the positions currently used by the cellar.
     */
    address[] public positions;

    /**
     * @notice Tell whether a position is currently used.
     */
    mapping(address => bool) public isPositionUsed;

    /**
     * @notice Get the type related to a position.
     */
    mapping(address => PositionType) public getPositionType;

    /**
     * @notice Get the addresses of the positions current used by the cellar.
     */
    function getPositions() external view returns (address[] memory) {
        return positions;
    }

    /**
     * @notice Maximum amount of positions a cellar can use at once.
     */
    uint8 public constant MAX_POSITIONS = 32;

    /**
     * @notice Insert a trusted position to the list of positions used by the cellar at a given index.
     * @param index index at which to insert the position
     * @param position address of position to add
     */
    function addPosition(uint256 index, address position) external onlyOwner whenNotShutdown {
        if (positions.length >= MAX_POSITIONS) revert Cellar__PositionArrayFull(MAX_POSITIONS);
        if (!isTrusted[position]) revert Cellar__UntrustedPosition(position);

        // Check if position is already being used.
        if (isPositionUsed[position]) revert Cellar__PositionAlreadyUsed(position);

        // Add new position at a specified index.
        positions.add(index, position);
        isPositionUsed[position] = true;

        emit PositionAdded(position, index);
    }

    /**
     * @notice Push a trusted position to the end of the list of positions used by the cellar.
     * @dev If you know you are going to add a position to the end of the array, this is more
     *      efficient then `addPosition`.
     * @param position address of position to add
     */
    function pushPosition(address position) external onlyOwner whenNotShutdown {
        if (positions.length >= MAX_POSITIONS) revert Cellar__PositionArrayFull(MAX_POSITIONS);
        if (!isTrusted[position]) revert Cellar__UntrustedPosition(position);

        // Check if position is already being used.
        if (isPositionUsed[position]) revert Cellar__PositionAlreadyUsed(position);

        // Add new position to the end of the positions.
        positions.push(position);
        isPositionUsed[position] = true;

        emit PositionAdded(position, positions.length - 1);
    }

    /**
     * @notice Remove the position at a given index from the list of positions used by the cellar.
     * @param index index at which to remove the position
     */
    function removePosition(uint256 index) external onlyOwner {
        // Get position being removed.
        address position = positions[index];

        // Only remove position if it is empty, and if it is not the holding position.
        uint256 positionBalance = _balanceOf(position);
        if (positionBalance > 0) revert Cellar__PositionNotEmpty(position, positionBalance);
        if (position == holdingPosition) revert Cellar__RemoveHoldingPosition();

        // Remove position at the given index.
        positions.remove(index);
        isPositionUsed[position] = false;

        emit PositionRemoved(position, index);
    }

    /**
     * @notice Swap the positions at two given indexes.
     * @param index1 index of first position to swap
     * @param index2 index of second position to swap
     */
    function swapPositions(uint256 index1, uint256 index2) external onlyOwner {
        // Get the new positions that will be at each index.
        address newPosition1 = positions[index2];
        address newPosition2 = positions[index1];

        // Swap positions.
        (positions[index1], positions[index2]) = (newPosition1, newPosition2);

        emit PositionSwapped(newPosition1, newPosition2, index1, index2);
    }

    // ============================================ TRUST CONFIG ============================================

    /**
     * @notice Emitted when trust for a position is changed.
     * @param position address of position that trust was changed for
     * @param isTrusted whether the position is trusted
     */
    event TrustChanged(address indexed position, bool isTrusted);

    /**
     * @notice Attempted to trust a position not being used.
     * @param position address of the invalid position
     */
    error Cellar__PositionPricingNotSetUp(address position);

    /**
     * @notice Addresses of the positions currently used by the cellar.
     */
    uint256 public constant PRICE_ROUTER_REGISTRY_SLOT = 2;

    /**
     * @notice Tell whether a position is trusted.
     */
    mapping(address => bool) public isTrusted;

    /**
     * @notice Trust a position to be used by the cellar.
     * @param position address of position to trust
     * @param positionType value specifying the interface the position uses
     */
    function trustPosition(address position, PositionType positionType) external onlyOwner {
        // Trust position.
        isTrusted[position] = true;

        // Set position type.
        getPositionType[position] = positionType;

        // Now that position type is set up, check that asset of position is supported for pricing operations.
        ERC20 positionAsset = _assetOf(position);
        if (!PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)).isSupported(positionAsset))
            revert Cellar__PositionPricingNotSetUp(address(positionAsset));

        emit TrustChanged(position, true);
    }

    // ============================================ WITHDRAW CONFIG ============================================

    /**
     * @notice Emitted when withdraw type configuration is changed.
     * @param oldType previous withdraw type
     * @param newType new withdraw type
     */
    event WithdrawTypeChanged(WithdrawType oldType, WithdrawType newType);

    /**
     * @notice The withdraw type to use for the cellar.
     * @param ORDERLY use `positions` in specify the order in which assets are withdrawn (eg.
     *                `positions[0]` is withdrawn from first); least impactful positions (position
     *                that will have its core positions impacted the least by having funds removed)
     *                should be withdrawn from first and most impactful position should be last
     * @param PROPORTIONAL pull assets from each position proportionally when withdrawing, used if
     *                     trying to maintain a specific ratio
     */
    enum WithdrawType {
        ORDERLY,
        PROPORTIONAL
    }

    /**
     * @notice The withdraw type to used by the cellar.
     */
    WithdrawType public withdrawType;

    /**
     * @notice Set the withdraw type used by the cellar.
     * @param newWithdrawType value of the new withdraw type to use
     */
    function setWithdrawType(WithdrawType newWithdrawType) external onlyOwner {
        emit WithdrawTypeChanged(withdrawType, newWithdrawType);

        withdrawType = newWithdrawType;
    }

    // ============================================ HOLDINGS CONFIG ============================================

    /**
     * @notice Emitted when the holdings position is changed.
     * @param oldPosition address of the old holdings position
     * @param newPosition address of the new holdings position
     */
    event HoldingPositionChanged(address indexed oldPosition, address indexed newPosition);

    /**
     * @notice The "default" position which uses the same asset as the cellar. It is the position
     *         deposited assets will automatically go into (perhaps while waiting to be rebalanced
     *         to other positions) and commonly the first position withdrawn assets will be pulled
     *         from if using orderly withdraws.
     * @dev MUST accept the same asset as the cellar's `asset`. MUST be a position present in
     *      `positions`. Should be a static (eg. just holding) or lossless (eg. lending on Aave)
     *      position. Should not be expensive to move assets in or out of as this will occur
     *      frequently. It is highly recommended to choose a "simple" holding position.
     */
    address public holdingPosition;

    /**
     * @notice Set the holding position used by the cellar.
     * @param newHoldingPosition address of the new holding position to use
     */
    function setHoldingPosition(address newHoldingPosition) external onlyOwner {
        if (!isPositionUsed[newHoldingPosition]) revert Cellar__InvalidPosition(newHoldingPosition);

        ERC20 holdingPositionAsset = _assetOf(newHoldingPosition);
        if (holdingPositionAsset != asset) revert Cellar__AssetMismatch(address(holdingPositionAsset), address(asset));

        emit HoldingPositionChanged(holdingPosition, newHoldingPosition);

        holdingPosition = newHoldingPosition;
    }

    // ============================================ ACCRUAL STORAGE ============================================

    /**
     * @notice Timestamp of when the last accrual occurred.
     * @dev Used for determining the amount of platform fees that can be taken during an accrual period.
     */
    uint64 public lastAccrual;

    // =============================================== FEES CONFIG ===============================================

    /**
     * @notice Emitted when platform fees is changed.
     * @param oldPlatformFee value platform fee was changed from
     * @param newPlatformFee value platform fee was changed to
     */
    event PlatformFeeChanged(uint64 oldPlatformFee, uint64 newPlatformFee);

    /**
     * @notice Emitted when performance fees is changed.
     * @param oldPerformanceFee value performance fee was changed from
     * @param newPerformanceFee value performance fee was changed to
     */
    event PerformanceFeeChanged(uint64 oldPerformanceFee, uint64 newPerformanceFee);

    /**
     * @notice Emitted when fees distributor is changed.
     * @param oldFeesDistributor address of fee distributor was changed from
     * @param newFeesDistributor address of fee distributor was changed to
     */
    event FeesDistributorChanged(bytes32 oldFeesDistributor, bytes32 newFeesDistributor);

    /**
     * @notice Emitted when strategist performance fee cut is changed.
     * @param oldPerformanceCut value strategist performance fee cut was changed from
     * @param newPerformanceCut value strategist performance fee cut was changed to
     */
    event StrategistPerformanceCutChanged(uint64 oldPerformanceCut, uint64 newPerformanceCut);

    /**
     * @notice Emitted when strategist platform fee cut is changed.
     * @param oldPlatformCut value strategist platform fee cut was changed from
     * @param newPlatformCut value strategist platform fee cut was changed to
     */
    event StrategistPlatformCutChanged(uint64 oldPlatformCut, uint64 newPlatformCut);

    /**
     * @notice Emitted when strategists payout address is changed.
     * @param oldPayoutAddress value strategists payout address was changed from
     * @param newPayoutAddress value strategists payout address was changed to
     */
    event StrategistPayoutAddressChanged(address oldPayoutAddress, address newPayoutAddress);

    /**
     * @notice Attempted to use an invalid cosmos address.
     */
    error Cellar__InvalidCosmosAddress();

    /**
     * @notice Attempted to change strategist fee cut with invalid value.
     */
    error Cellar__InvalidFeeCut();

    /**
     * @notice Attempted to change performance/platform fee with invalid value.
     */
    error Cellar__InvalidFee();

    /**
     * @notice Data related to fees.
     * @param highWatermark Stores the share price to be used as a High Watermark to calculate performance fees.
     * @param strategistPerformanceCut Determines how much performance fees go to strategist.
     *                                 This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%).
     * @param strategistPlatformCut Determines how much platform fees go to strategist.
     *                              This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%).
     * @param platformFee The percentage of total assets accrued as platform fees over a year.
                          This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%).
     * @param performanceFee The percentage of total assets accrued as platform fees over a year.
     *                       This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%).
     * @param feesDistributor Cosmos address of module that distributes fees, specified as a hex value.
     *                        The Gravity contract expects a 32-byte value formatted in a specific way.
     * @param strategistPayoutAddress Address to send the strategists fee shares.
     */
    struct FeeData {
        uint256 highWatermark;
        uint64 strategistPerformanceCut;
        uint64 strategistPlatformCut;
        uint64 platformFee;
        uint64 performanceFee;
        bytes32 feesDistributor;
        address strategistPayoutAddress;
    }

    /**
     * @notice Stores all fee data for cellar.
     */
    FeeData public feeData =
        FeeData({
            highWatermark: 0,
            strategistPerformanceCut: 0.75e18,
            strategistPlatformCut: 0.75e18,
            platformFee: 0.02e18,
            performanceFee: 0.1e18,
            feesDistributor: hex"000000000000000000000000b813554b423266bbd4c16c32fa383394868c1f55", // 20 bytes, so need 12 bytes of zero
            strategistPayoutAddress: address(0)
        });

    uint64 public constant MAX_PERFORMANCE_FEE = 0.5e18;
    uint64 public constant MAX_PLATFORM_FEE = 0.2e18;
    uint64 public constant MAX_FEE_CUT = 1e18;

    /**
     * @notice Set the percentage of platform fees accrued over a year.
     * @param newPlatformFee value out of 1e18 that represents new platform fee percentage
     */
    function setPlatformFee(uint64 newPlatformFee) external onlyOwner {
        if (newPlatformFee > MAX_PLATFORM_FEE) revert Cellar__InvalidFee();
        emit PlatformFeeChanged(feeData.platformFee, newPlatformFee);

        feeData.platformFee = newPlatformFee;
    }

    /**
     * @notice Set the percentage of performance fees accrued from yield.
     * @param newPerformanceFee value out of 1e18 that represents new performance fee percentage
     */
    function setPerformanceFee(uint64 newPerformanceFee) external onlyOwner {
        if (newPerformanceFee > MAX_PERFORMANCE_FEE) revert Cellar__InvalidFee();
        emit PerformanceFeeChanged(feeData.performanceFee, newPerformanceFee);

        feeData.performanceFee = newPerformanceFee;
    }

    /**
     * @notice Set the address of the fee distributor on the Sommelier chain.
     * @dev IMPORTANT: Ensure that the address is formatted in the specific way that the Gravity contract
     *      expects it to be.
     * @param newFeesDistributor formatted address of the new fee distributor module
     */
    function setFeesDistributor(bytes32 newFeesDistributor) external onlyOwner {
        if (uint256(newFeesDistributor) > type(uint160).max) revert Cellar__InvalidCosmosAddress();
        emit FeesDistributorChanged(feeData.feesDistributor, newFeesDistributor);

        feeData.feesDistributor = newFeesDistributor;
    }

    /**
     * @notice Sets the Strategists cut of performance fees
     * @param cut the performance cut for the strategist
     */
    function setStrategistPerformanceCut(uint64 cut) external onlyOwner {
        if (cut > MAX_FEE_CUT) revert Cellar__InvalidFeeCut();
        emit StrategistPerformanceCutChanged(feeData.strategistPerformanceCut, cut);

        feeData.strategistPerformanceCut = cut;
    }

    /**
     * @notice Sets the Strategists cut of platform fees
     * @param cut the platform cut for the strategist
     */
    function setStrategistPlatformCut(uint64 cut) external onlyOwner {
        if (cut > MAX_FEE_CUT) revert Cellar__InvalidFeeCut();
        emit StrategistPlatformCutChanged(feeData.strategistPlatformCut, cut);

        feeData.strategistPlatformCut = cut;
    }

    /**
     * @notice Sets the Strategists payout address
     * @param payout the new strategist payout address
     */
    function setStrategistPayoutAddress(address payout) external onlyOwner {
        emit StrategistPayoutAddressChanged(feeData.strategistPayoutAddress, payout);

        feeData.strategistPayoutAddress = payout;
    }

    // ============================================= LIMITS CONFIG =============================================

    /**
     * @notice Emitted when the liquidity limit is changed.
     * @param oldLimit amount the limit was changed from
     * @param newLimit amount the limit was changed to
     */
    event LiquidityLimitChanged(uint256 oldLimit, uint256 newLimit);

    /**
     * @notice Emitted when the deposit limit is changed.
     * @param oldLimit amount the limit was changed from
     * @param newLimit amount the limit was changed to
     */
    event DepositLimitChanged(uint256 oldLimit, uint256 newLimit);

    /**
     * @notice Attempted deposit more than the max deposit.
     * @param assets the assets user attempted to deposit
     * @param maxDeposit the max assets that can be deposited
     */
    error Cellar__DepositRestricted(uint256 assets, uint256 maxDeposit);

    /**
     * @notice Maximum amount of assets that can be managed by the cellar. Denominated in the same decimals
     *         as the current asset.
     * @dev Set to `type(uint256).max` to have no limit.
     */
    uint256 public liquidityLimit = type(uint256).max;

    /**
     * @notice Maximum amount of assets per wallet. Denominated in the same decimals as the current asset.
     * @dev Set to `type(uint256).max` to have no limit.
     */
    uint256 public depositLimit = type(uint256).max;

    /**
     * @notice Set the maximum liquidity that cellar can manage. Uses the same decimals as the current asset.
     * @param newLimit amount of assets to set as the new limit
     */
    function setLiquidityLimit(uint256 newLimit) external onlyOwner {
        emit LiquidityLimitChanged(liquidityLimit, newLimit);

        liquidityLimit = newLimit;
    }

    /**
     * @notice Set the per-wallet deposit limit. Uses the same decimals as the current asset.
     * @param newLimit amount of assets to set as the new limit
     */
    function setDepositLimit(uint256 newLimit) external onlyOwner {
        emit DepositLimitChanged(depositLimit, newLimit);

        depositLimit = newLimit;
    }

    // =========================================== EMERGENCY LOGIC ===========================================

    /**
     * @notice Emitted when cellar emergency state is changed.
     * @param isShutdown whether the cellar is shutdown
     */
    event ShutdownChanged(bool isShutdown);

    /**
     * @notice Attempted action was prevented due to contract being shutdown.
     */
    error Cellar__ContractShutdown();

    /**
     * @notice Attempted action was prevented due to contract not being shutdown.
     */
    error Cellar__ContractNotShutdown();

    /**
     * @notice Whether or not the contract is shutdown in case of an emergency.
     */
    bool public isShutdown;

    /**
     * @notice Prevent a function from being called during a shutdown.
     */
    modifier whenNotShutdown() {
        if (isShutdown) revert Cellar__ContractShutdown();

        _;
    }

    /**
     * @notice Shutdown the cellar. Used in an emergency or if the cellar has been deprecated.
     * @dev In the case where
     */
    function initiateShutdown() external whenNotShutdown onlyOwner {
        isShutdown = true;

        emit ShutdownChanged(true);
    }

    /**
     * @notice Restart the cellar.
     */
    function liftShutdown() external onlyOwner {
        if (!isShutdown) revert Cellar__ContractNotShutdown();
        isShutdown = false;

        emit ShutdownChanged(false);
    }

    // =========================================== CONSTRUCTOR ===========================================

    /**
     * @notice Address of the platform's registry contract. Used to get the latest address of modules.
     */
    Registry public immutable registry;

    /**
     * @dev Owner should be set to the Gravity Bridge, which relays instructions from the Steward
     *      module to the cellars.
     *      https://github.com/PeggyJV/steward
     *      https://github.com/cosmos/gravity-bridge/blob/main/solidity/contracts/Gravity.sol
     * @param _registry address of the platform's registry contract
     * @param _asset address of underlying token used for the for accounting, depositing, and withdrawing
     * @param _positions addresses of the positions to initialize the cellar with
     * @param _positionTypes types of each positions used
     * @param _holdingPosition address of the position to use as the holding position
     * @param _withdrawType withdraw type to use for the cellar
     * @param _name name of this cellar's share token
     * @param _name symbol of this cellar's share token
     * @param _strategistPayout The address to send the strategists fee shares.
     */
    constructor(
        Registry _registry,
        ERC20 _asset,
        address[] memory _positions,
        PositionType[] memory _positionTypes,
        address _holdingPosition,
        WithdrawType _withdrawType,
        string memory _name,
        string memory _symbol,
        address _strategistPayout
    ) ERC4626(_asset, _name, _symbol) Owned(_registry.getAddress(0)) {
        registry = _registry;

        // Initialize positions.
        positions = _positions;
        ERC20 positionAsset;
        for (uint256 i; i < _positions.length; i++) {
            address position = _positions[i];

            if (isPositionUsed[position]) revert Cellar__PositionAlreadyUsed(position);

            isTrusted[position] = true;
            isPositionUsed[position] = true;
            getPositionType[position] = _positionTypes[i];

            positionAsset = _assetOf(position);
            if (!PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)).isSupported(positionAsset))
                revert Cellar__PositionPricingNotSetUp(address(positionAsset));
        }

        // Initialize holding position.
        if (!isPositionUsed[_holdingPosition]) revert Cellar__InvalidPosition(_holdingPosition);

        ERC20 holdingPositionAsset = _assetOf(_holdingPosition);
        if (holdingPositionAsset != _asset)
            revert Cellar__AssetMismatch(address(holdingPositionAsset), address(_asset));

        holdingPosition = _holdingPosition;

        // Initialize withdraw type.
        withdrawType = _withdrawType;

        // Initialize last accrual timestamp to time that cellar was created, otherwise the first
        // `accrue` will take platform fees from 1970 to the time it is called.
        lastAccrual = uint64(block.timestamp);

        feeData.strategistPayoutAddress = _strategistPayout;
    }

    // =========================================== CORE LOGIC ===========================================

    /**
     * @notice Emitted when withdraws are made from a position.
     * @param position the position assets were withdrawn from
     * @param amount the amount of assets withdrawn
     */
    event PulledFromPosition(address indexed position, uint256 amount);

    /**
     * @notice Emitted when share locking period is changed.
     * @param oldPeriod the old locking period
     * @param newPeriod the new locking period
     */
    event ShareLockingPeriodChanged(uint256 oldPeriod, uint256 newPeriod);

    /**
     * @notice Attempted an action with zero shares.
     */
    error Cellar__ZeroShares();

    /**
     * @notice Attempted an action with zero assets.
     */
    error Cellar__ZeroAssets();

    /**
     * @notice Withdraw did not withdraw all assets.
     * @param assetsOwed the remaining assets owed that were not withdrawn.
     */
    error Cellar__IncompleteWithdraw(uint256 assetsOwed);

    /**
     * @notice Attempted to withdraw an illiquid position.
     * @param illiquidPosition the illiquid position.
     */
    error Cellar__IlliquidWithdraw(address illiquidPosition);

    /**
     * @notice Attempted to set `shareLockPeriod` to an invalid number.
     */
    error Cellar__InvalidShareLockPeriod();

    /**
     * @notice Attempted to burn shares when they are locked.
     * @param blockSharesAreUnlocked the block number when caller can transfer/redeem shares
     * @param currentBlock the current block number.
     */
    error Cellar__SharesAreLocked(uint256 blockSharesAreUnlocked, uint256 currentBlock);

    /**
     * @notice Attempted deposit on behalf of a user without being approved.
     */
    error Cellar__NotApprovedToDepositOnBehalf(address depositor);

    /**
     * @notice Shares must be locked for atleaset 8 blocks after minting.
     */
    uint256 public constant MINIMUM_SHARE_LOCK_PERIOD = 8;

    /**
     * @notice Shares can be locked for at most 7200 blocks after minting.
     */
    uint256 public constant MAXIMUM_SHARE_LOCK_PERIOD = 7200;

    /**
     * @notice After deposits users must wait `shareLockPeriod` blocks before being able to transfer or withdraw their shares.
     */
    uint256 public shareLockPeriod = MAXIMUM_SHARE_LOCK_PERIOD;

    /**
     * @notice mapping that stores every users last block they minted shares.
     */
    mapping(address => uint256) public userShareLockStartBlock;

    /**
     * @notice Allows share lock period to be updated.
     * @param newLock the new lock period
     */
    function setShareLockPeriod(uint256 newLock) external onlyOwner {
        if (newLock < MINIMUM_SHARE_LOCK_PERIOD || newLock > MAXIMUM_SHARE_LOCK_PERIOD)
            revert Cellar__InvalidShareLockPeriod();
        uint256 oldLockingPeriod = shareLockPeriod;
        shareLockPeriod = newLock;
        emit ShareLockingPeriodChanged(oldLockingPeriod, newLock);
    }

    /**
     * @notice helper function that checks enough blocks have passed to unlock shares.
     * @param owner the address of the user to check
     */
    function _checkIfSharesLocked(address owner) internal view {
        uint256 lockBlock = userShareLockStartBlock[owner];
        if (lockBlock != 0) {
            uint256 blockSharesAreUnlocked = lockBlock + shareLockPeriod;
            if (blockSharesAreUnlocked > block.number)
                revert Cellar__SharesAreLocked(blockSharesAreUnlocked, block.number);
        }
    }

    /**
     * @notice modifies before transfer hook to check that shares are not locked
     * @param from the address transferring shares
     */
    function _beforeTokenTransfer(
        address from,
        address,
        uint256
    ) internal view override {
        _checkIfSharesLocked(from);
    }

    /**
     * @notice called at the beginning of deposit.
     * @param assets amount of assets deposited by user.
     * @param receiver address receiving the shares.
     */
    function beforeDeposit(
        uint256 assets,
        uint256,
        address receiver
    ) internal override whenNotShutdown {
        if (msg.sender != receiver) {
            if (!registry.approvedForDepositOnBehalf(msg.sender))
                revert Cellar__NotApprovedToDepositOnBehalf(msg.sender);
        }
        uint256 maxAssets = maxDeposit(receiver);
        if (assets > maxAssets) revert Cellar__DepositRestricted(assets, maxAssets);
        feeData.highWatermark += assets;
    }

    /**
     * @notice called at the end of deposit.
     * @param assets amount of assets deposited by user.
     */
    function afterDeposit(
        uint256 assets,
        uint256,
        address receiver
    ) internal override {
        _depositTo(holdingPosition, assets);
        userShareLockStartBlock[receiver] = block.number;
    }

    /**
     * @notice called at the beginning of withdraw.
     * @param assets amount of assets withdrawn by user.
     */
    function beforeWithdraw(
        uint256 assets,
        uint256,
        address,
        address owner
    ) internal override {
        // Make sure users shares are not locked.
        _checkIfSharesLocked(owner);

        // Need to check if assets is greater than the high watermark
        // because if the performanceFee is set to zero, and all cellar shares are redeemed,
        // if the cellar has earned any yield, assets will be greater than the high watermark.
        // Becuase the high watermark is only updated when performance fees are minted.
        uint256 highWatermark = feeData.highWatermark;
        feeData.highWatermark = assets > highWatermark ? 0 : highWatermark - assets;
    }

    /**
     * @notice Deposits assets into the cellar, and returns shares to receiver.
     * @param assets amount of assets deposited by user.
     * @param receiver address to receive the shares.
     * @return shares amount of shares given for deposit.
     */
    function deposit(uint256 assets, address receiver) public override nonReentrant returns (uint256 shares) {
        uint256 _totalAssets = totalAssets();

        _takePerformanceFees(_totalAssets);

        // Check for rounding error since we round down in previewDeposit.
        if ((shares = _convertToShares(assets, _totalAssets)) == 0) revert Cellar__ZeroShares();

        beforeDeposit(assets, shares, receiver);

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);

        afterDeposit(assets, shares, receiver);
    }

    /**
     * @notice Mints shares from the cellar, and returns shares to receiver.
     * @param shares amount of shares requested by user.
     * @param receiver address to receive the shares.
     * @return assets amount of assets deposited into the cellar.
     */
    function mint(uint256 shares, address receiver) public override nonReentrant returns (uint256 assets) {
        uint256 _totalAssets = totalAssets();

        _takePerformanceFees(_totalAssets);

        // previewMintRoundsUp, but iniital mint could return zero assets, so check for rounding error.
        if ((assets = _previewMint(shares, _totalAssets)) == 0) revert Cellar__ZeroAssets(); // No need to check for rounding error, previewMint rounds up.

        beforeDeposit(assets, shares, receiver);

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);

        afterDeposit(assets, shares, receiver);
    }

    /**
     * @notice helper function that checks if msg.sender has the allowance to spend owner's shares.
     * @dev reverts if msg.sender != owner, and msg.sender does not have enough allowance.
     */
    function _checkAllowance(address owner, uint256 shares) internal {
        if (msg.sender != owner) {
            _spendAllowance(owner, msg.sender, shares);
        }
    }

    /**
     * @notice Withdraw assets from the cellar by redeeming shares.
     * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver.
     *      Since there are no swaps involved in this function, the receiver may receive multiple
     *      assets. The value of all the assets returned will be equal to the amount defined by
     *      `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets`
     *      is 1000, then the receiver will receive $1000 worth of assets in either one or many
     *      tokens).
     * @param assets equivalent value of the assets withdrawn, denominated in the cellar's asset
     * @param receiver address that will receive withdrawn assets
     * @param owner address that owns the shares being redeemed
     * @return shares amount of shares redeemed
     */
    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) public override nonReentrant returns (uint256 shares) {
        // Get data efficiently.
        (
            uint256 _totalAssets, // Store totalHoldings and pass into _withdrawInOrder if no stack errors.
            address[] memory _positions,
            ERC20[] memory positionAssets,
            uint256[] memory positionBalances,
            uint256[] memory withdrawableBalances
        ) = _getData();

        _takePerformanceFees(_totalAssets);

        // No need to check for rounding error, `previewWithdraw` rounds up.
        shares = _previewWithdraw(assets, _totalAssets);

        beforeWithdraw(assets, shares, receiver, owner);

        _checkAllowance(owner, shares);

        uint256 totalShares = totalSupply();

        _burn(owner, shares);

        emit Withdraw(msg.sender, receiver, owner, assets, shares);

        withdrawType == WithdrawType.ORDERLY
            ? _withdrawInOrder(assets, receiver, _positions, positionAssets, positionBalances, withdrawableBalances)
            : _withdrawInProportion(shares, totalShares, receiver, _positions, positionBalances, withdrawableBalances);

        afterWithdraw(assets, shares, receiver, owner);
    }

    /**
     * @notice Redeem shares to withdraw assets from the cellar.
     * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver.
     *      Since there are no swaps involved in this function, the receiver may receive multiple
     *      assets. The value of all the assets returned will be equal to the amount defined by
     *      `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets`
     *      is 1000, then the receiver will receive $1000 worth of assets in either one or many
     *      tokens).
     * @param shares amount of shares to redeem
     * @param receiver address that will receive withdrawn assets
     * @param owner address that owns the shares being redeemed
     * @return assets equivalent value of the assets withdrawn, denominated in the cellar's asset
     */
    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) public override nonReentrant returns (uint256 assets) {
        // Get data efficiently.
        (
            uint256 _totalAssets, // Store totalHoldings and pass into _withdrawInOrder if no stack errors.
            address[] memory _positions,
            ERC20[] memory positionAssets,
            uint256[] memory positionBalances,
            uint256[] memory withdrawableBalances
        ) = _getData();

        _takePerformanceFees(_totalAssets);

        _checkAllowance(owner, shares);

        // Check for rounding error since we round down in previewRedeem.
        if ((assets = _convertToAssets(shares, _totalAssets)) == 0) revert Cellar__ZeroAssets();

        beforeWithdraw(assets, shares, receiver, owner);

        uint256 totalShares = totalSupply();

        _burn(owner, shares);

        emit Withdraw(msg.sender, receiver, owner, assets, shares);

        withdrawType == WithdrawType.ORDERLY
            ? _withdrawInOrder(assets, receiver, _positions, positionAssets, positionBalances, withdrawableBalances)
            : _withdrawInProportion(shares, totalShares, receiver, _positions, positionBalances, withdrawableBalances);

        afterWithdraw(assets, shares, receiver, owner);
    }

    /**
     * @dev Withdraw from positions in the order defined by `positions`. Used if the withdraw type
     *      is `ORDERLY`.
     * @param assets the amount of assets to withdraw from cellar
     * @param receiver the address to sent withdrawn assets to
     * @param _positions positions to withdraw from
     * @param positionAssets underlying asset for each position
     * @param positionBalances underlying balances for each position
     */
    function _withdrawInOrder(
        uint256 assets,
        address receiver,
        address[] memory _positions,
        ERC20[] memory positionAssets,
        uint256[] memory positionBalances,
        uint256[] memory withdrawableBalances
    ) internal {
        // Get the price router.
        PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT));

        for (uint256 i; i < _positions.length; i++) {
            // Move on to next position if this one is empty.
            if (positionBalances[i] == 0) continue;

            uint256 onePositionAsset = 10**positionAssets[i].decimals();
            uint256 exchangeRate = priceRouter.getExchangeRate(positionAssets[i], asset);

            // Denominate withdrawable position balance in cellar's asset.
            uint256 totalWithdrawableBalanceInAssets = withdrawableBalances[i].mulDivDown(
                exchangeRate,
                onePositionAsset
            );

            // We want to pull as much as we can from this position, but no more than needed.
            uint256 amount;

            if (totalWithdrawableBalanceInAssets > assets) {
                amount = assets.mulDivDown(onePositionAsset, exchangeRate);
                assets = 0;
            } else {
                amount = withdrawableBalances[i];
                assets = assets - totalWithdrawableBalanceInAssets;
            }

            // Withdraw from position.
            _withdrawFrom(_positions[i], amount, receiver);

            emit PulledFromPosition(_positions[i], amount);

            // Stop if no more assets to withdraw.
            if (assets == 0) break;
        }
        // If withdraw did not remove all assets owed, revert.
        if (assets > 0) revert Cellar__IncompleteWithdraw(assets);
    }

    /**
     * @dev Withdraw from each position proportional to that of shares redeemed. Used if the
     *      withdraw type is `PROPORTIONAL`.
     * @dev It is possible that the `amount` calculated to withdraw is zero. This is only a problem
     *      for a low percision ERC20, which we have no plans to support.
     * @param shares the user is burning to withdraw
     * @param totalShares the total amount of oustanding shares
     * @param receiver the address to sent withdrawn assets to
     * @param _positions positions to withdraw from
     * @param positionBalances underlying balances for each position
     */
    function _withdrawInProportion(
        uint256 shares,
        uint256 totalShares,
        address receiver,
        address[] memory _positions,
        uint256[] memory positionBalances,
        uint256[] memory withdrawableBalances
    ) internal {
        // Withdraw assets from positions in proportion to shares redeemed.
        for (uint256 i; i < _positions.length; i++) {
            address position = _positions[i];
            uint256 positionBalance = positionBalances[i];

            // Move on to next position if this one is empty.
            if (positionBalance == 0) continue;

            // Get the amount of assets to withdraw from this position based on proportion to shares redeemed.
            uint256 amount = positionBalance.mulDivDown(shares, totalShares);

            // If straetgist locks the enirety of a positions funds, then all withdraw calls revert.
            // If this happens,  goverance should vote out malicious strategist, then change withdraw type to in oder, and move bad position to back of queue.
            if (amount > withdrawableBalances[i]) revert Cellar__IlliquidWithdraw(position);

            // Withdraw from position to receiver.
            _withdrawFrom(position, amount, receiver);

            emit PulledFromPosition(position, amount);
        }
    }

    // ========================================= ACCOUNTING LOGIC =========================================

    /**
     * @notice The total amount of assets in the cellar.
     * @dev EIP4626 states totalAssets needs to be inclusive of fees.
     * Since performance fees mint shares, total assets remains unchanged,
     * so this implementation is inclusive of fees even though it does not explicitly show it.
     * @dev EIP4626 states totalAssets must not revert, but it is possible for `totalAssets` to revert
     * so it does NOT conform to ERC4626 standards.
     */
    function totalAssets() public view override returns (uint256 assets) {
        uint256 numOfPositions = positions.length;
        ERC20[] memory positionAssets = new ERC20[](numOfPositions);
        uint256[] memory balances = new uint256[](numOfPositions);

        for (uint256 i; i < numOfPositions; i++) {
            address position = positions[i];
            positionAssets[i] = _assetOf(position);
            balances[i] = _balanceOf(position);
        }

        PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT));
        assets = priceRouter.getValues(positionAssets, balances, asset);
    }

    /**
     * @notice The total amount of assets in the cellar.
     * @dev Excludes locked yield that hasn't been distributed.
     */
    function totalAssetsWithdrawable() public view returns (uint256 assets) {
        uint256 numOfPositions = positions.length;
        ERC20[] memory positionAssets = new ERC20[](numOfPositions);
        uint256[] memory balances = new uint256[](numOfPositions);

        for (uint256 i; i < numOfPositions; i++) {
            address position = positions[i];
            positionAssets[i] = _assetOf(position);
            balances[i] = _withdrawableFrom(position);
        }

        PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT));
        assets = priceRouter.getValues(positionAssets, balances, asset);
    }

    /**
     * @notice The amount of assets that the cellar would exchange for the amount of shares provided.
     * @notice is NOT inclusive of performance fees.
     * @param shares amount of shares to convert
     * @return assets the shares can be exchanged for
     */
    function convertToAssets(uint256 shares) public view override returns (uint256 assets) {
        assets = _convertToAssets(shares, totalAssets());
    }

    /**
     * @notice The amount of shares that the cellar would exchange for the amount of assets provided.
     * @param assets amount of assets to convert
     * @return shares the assets can be exchanged for
     */
    function convertToShares(uint256 assets) public view override returns (uint256 shares) {
        shares = _convertToShares(assets, totalAssets());
    }

    /**
     * @notice Simulate the effects of minting shares at the current block, given current on-chain conditions.
     * @param shares amount of shares to mint
     * @return assets that will be deposited
     */
    function previewMint(uint256 shares) public view override returns (uint256 assets) {
        uint256 _totalAssets = totalAssets();
        uint256 feeInAssets = _previewPerformanceFees(_totalAssets);
        assets = _previewMint(shares, _totalAssets - feeInAssets);
    }

    /**
     * @notice Simulate the effects of withdrawing assets at the current block, given current on-chain conditions.
     * @param assets amount of assets to withdraw
     * @return shares that will be redeemed
     */
    function previewWithdraw(uint256 assets) public view override returns (uint256 shares) {
        uint256 _totalAssets = totalAssets();
        uint256 feeInAssets = _previewPerformanceFees(_totalAssets);
        shares = _previewWithdraw(assets, _totalAssets - feeInAssets);
    }

    /**
     * @notice Simulate the effects of depositing assets at the current block, given current on-chain conditions.
     * @param assets amount of assets to deposit
     * @return shares that will be minted
     */
    function previewDeposit(uint256 assets) public view override returns (uint256 shares) {
        uint256 _totalAssets = totalAssets();
        uint256 feeInAssets = _previewPerformanceFees(_totalAssets);
        shares = _convertToShares(assets, _totalAssets - feeInAssets);
    }

    /**
     * @notice Simulate the effects of redeeming shares at the current block, given current on-chain conditions.
     * @param shares amount of shares to redeem
     * @return assets that will be returned
     */
    function previewRedeem(uint256 shares) public view override returns (uint256 assets) {
        uint256 _totalAssets = totalAssets();
        uint256 feeInAssets = _previewPerformanceFees(_totalAssets);
        assets = _convertToAssets(shares, _totalAssets - feeInAssets);
    }

    /**
     * @notice Finds the max amount of value an `owner` can remove from the cellar.
     * @param owner address of the user to find max value.
     * @param inShares if false, then returns value in terms of assets
     *                 if true then returns value in terms of shares
     */
    function _findMax(address owner, bool inShares) internal view returns (uint256 maxOut) {
        // Check if owner shares are locked, return 0 if so.
        uint256 lockBlock = userShareLockStartBlock[owner];
        if (lockBlock != 0) {
            uint256 blockSharesAreUnlocked = lockBlock + shareLockPeriod;
            if (blockSharesAreUnlocked > block.number) return 0;
        }
        // Get amount of assets to withdraw with fees accounted for.
        uint256 _totalAssets = totalAssets();
        uint256 feeInAssets = _previewPerformanceFees(_totalAssets);
        uint256 assets = _convertToAssets(balanceOf(owner), _totalAssets - feeInAssets);

        if (withdrawType == WithdrawType.ORDERLY) {
            uint256 withdrawable = totalAssetsWithdrawable();
            maxOut = assets <= withdrawable ? assets : withdrawable;
        } else {
            (, , , uint256[] memory positionBalances, uint256[] memory withdrawableBalances) = _getData();
            uint256 totalShares = totalSupply();
            uint256 shares = balanceOf(owner);
            uint256 smallestPercentWithdrawable = 1e18;
            for (uint256 i = 0; i < withdrawableBalances.length; i++) {
                if (positionBalances[i] == 0) continue;
                if (withdrawableBalances[i] == 0) return 0;
                uint256 percentWithdrawable = withdrawableBalances[i].mulDivDown(1e18, positionBalances[i]);
                if (percentWithdrawable < smallestPercentWithdrawable)
                    smallestPercentWithdrawable = percentWithdrawable;
            }
            uint256 userOwnershipPercent = shares.mulDivDown(1e18, totalShares);
            maxOut = userOwnershipPercent <= smallestPercentWithdrawable
                ? assets
                : (_totalAssets - feeInAssets).mulDivDown(smallestPercentWithdrawable, 1e18);
        }
        if (inShares) maxOut = _convertToShares(maxOut, _totalAssets - feeInAssets);
        // else leave maxOut in terms of assets.
    }

    /**
     * @notice Returns the max amount withdrawable by a user inclusive of performance fees
     * @dev EIP4626 states maxWithdraw must not revert, but it is possible for `totalAssets` to revert
     * so it does NOT conform to ERC4626 standards.
     * @param owner address to check maxWithdraw of.
     * @return the max amount of assets withdrawable by `owner`.
     */
    function maxWithdraw(address owner) public view override returns (uint256) {
        return _findMax(owner, false);
    }

    /**
     * @notice Returns the max amount shares redeemable by a user
     * @dev EIP4626 states maxRedeem must not revert, but it is possible for `totalAssets` to revert
     * so it does NOT conform to ERC4626 standards.
     * @param owner address to check maxRedeem of.
     * @return the max amount of shares redeemable by `owner`.
     */
    function maxRedeem(address owner) public view override returns (uint256) {
        return _findMax(owner, true);
    }

    /**
     * @dev Used to more efficiently convert amount of shares to assets using a stored `totalAssets` value.
     */
    function _convertToAssets(uint256 shares, uint256 _totalAssets) internal view returns (uint256 assets) {
        uint256 totalShares = totalSupply();

        assets = totalShares == 0
            ? shares.changeDecimals(18, asset.decimals())
            : shares.mulDivDown(_totalAssets, totalShares);
    }

    /**
     * @dev Used to more efficiently convert amount of assets to shares using a stored `totalAssets` value.
     */
    function _convertToShares(uint256 assets, uint256 _totalAssets) internal view returns (uint256 shares) {
        uint256 totalShares = totalSupply();

        shares = totalShares == 0
            ? assets.changeDecimals(asset.decimals(), 18)
            : assets.mulDivDown(totalShares, _totalAssets);
    }

    /**
     * @dev Used to more efficiently simulate minting shares using a stored `totalAssets` value.
     */
    function _previewMint(uint256 shares, uint256 _totalAssets) internal view returns (uint256 assets) {
        uint256 totalShares = totalSupply();

        assets = totalShares == 0
            ? shares.changeDecimals(18, asset.decimals())
            : shares.mulDivUp(_totalAssets, totalShares);
    }

    /**
     * @dev Used to more efficiently simulate withdrawing assets using a stored `totalAssets` value.
     */
    function _previewWithdraw(uint256 assets, uint256 _totalAssets) internal view returns (uint256 shares) {
        uint256 totalShares = totalSupply();

        shares = totalShares == 0
            ? assets.changeDecimals(asset.decimals(), 18)
            : assets.mulDivUp(totalShares, _totalAssets);
    }

    /**
     * @dev Used to efficiently get and store accounting information to avoid having to expensively
     *      recompute it.
     */
    function _getData()
        internal
        view
        returns (
            uint256 _totalAssets,
            address[] memory _positions,
            ERC20[] memory positionAssets,
            uint256[] memory positionBalances,
            uint256[] memory withdrawableBalances
        )
    {
        uint256 len = positions.length;

        _positions = new address[](len);
        positionAssets = new ERC20[](len);
        positionBalances = new uint256[](len);
        positionBalances = new uint256[](len);
        withdrawableBalances = new uint256[](len);

        for (uint256 i; i < len; i++) {
            address position = positions[i];

            _positions[i] = position;
            positionAssets[i] = _assetOf(position);
            positionBalances[i] = _balanceOf(position);
            withdrawableBalances[i] = _withdrawableFrom(position);
        }

        PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT));
        _totalAssets = priceRouter.getValues(positionAssets, positionBalances, asset);
    }

    // =========================================== POSITION LOGIC ===========================================

    /**
     * @notice Emitted on rebalancing positions.
     * @param fromPosition the address of the position rebalanced from
     * @param toPosition the address of the position rebalanced to
     * @param assetsFrom the amount of assets withdrawn from the position rebalanced from
     * @param assetsTo the amount of assets desposited to the position rebalanced to
     */
    event Rebalance(address indexed fromPosition, address indexed toPosition, uint256 assetsFrom, uint256 assetsTo);

    /**
     * @notice Emitted on when the rebalance deviation is changed.
     * @param oldDeviation the old rebalance deviation
     * @param newDeviation the new rebalance deviation
     */
    event RebalanceDeviationChanged(uint256 oldDeviation, uint256 newDeviation);

    /**
     * @notice totalAssets deviated outside the range set by `allowedRebalanceDeviation`.
     * @param assets the total assets in the cellar
     * @param min the minimum allowed assets
     * @param max the maximum allowed assets
     */
    error Cellar__TotalAssetDeviatedOutsideRange(uint256 assets, uint256 min, uint256 max);

    /**
     * @notice Total shares in a cellar changed when they should stay constant.
     * @param current the current amount of total shares
     * @param expected the expected amount of total shares
     */
    error Cellar__TotalSharesMustRemainConstant(uint256 current, uint256 expected);

    /**
     * @notice Total shares in a cellar changed when they should stay constant.
     * @param requested the requested rebalance  deviation
     * @param max the max rebalance deviation.
     */
    error Cellar__InvalidRebalanceDeviation(uint256 requested, uint256 max);

    uint64 public constant MAX_REBALANCE_DEVIATION = 0.1e18;

    /**
     * @notice The percent the total assets of a cellar may deviate during a rebalance call.
     */
    uint256 public allowedRebalanceDeviation = 0.003e18; // Currently set to 0.3%

    /**
     * @notice Allows governance to change this cellars rebalance deviation.
     * @param newDeviation the new reabalance deviation value.
     */
    function setRebalanceDeviation(uint256 newDeviation) external onlyOwner {
        if (newDeviation > MAX_REBALANCE_DEVIATION)
            revert Cellar__InvalidRebalanceDeviation(newDeviation, MAX_REBALANCE_DEVIATION);

        uint256 oldDeviation = allowedRebalanceDeviation;
        allowedRebalanceDeviation = newDeviation;

        emit RebalanceDeviationChanged(oldDeviation, newDeviation);
    }

    /**
     * @notice Move assets between positions. To move assets from/to this cellar's holdings, specify
     *         the address of this cellar as the `fromPosition`/`toPosition`.
     * @param fromPosition address of the position to move assets from
     * @param toPosition address of the position to move assets to
     * @param assetsFrom amount of assets to move from the from position
     */
    function rebalance(
        address fromPosition,
        address toPosition,
        uint256 assetsFrom,
        SwapRouter.Exchange exchange,
        bytes calldata params
    ) external onlyOwner whenNotShutdown nonReentrant returns (uint256 assetsTo) {
        // Check that position being rebalanced to is currently being used.
        if (!isPositionUsed[toPosition]) revert Cellar__InvalidPosition(address(toPosition));

        // Before making any external calls save the current `totalAssets` and `totalSupply`.
        uint256 assets = totalAssets();
        uint256 totalShares = totalSupply();

        // Withdraw from position.
        _withdrawFrom(fromPosition, assetsFrom, address(this));

        // Swap to the asset of the other position if necessary.
        ERC20 fromAsset = _assetOf(fromPosition);
        ERC20 toAsset = _assetOf(toPosition);
        assetsTo = fromAsset != toAsset
            ? _swap(fromAsset, toAsset, assetsFrom, exchange, params, address(this))
            : assetsFrom;

        // Deposit into position.
        _depositTo(toPosition, assetsTo);

        // After making every external call, check that the totalAssets haas not deviated significantly, and that totalShares is the same.
        uint256 minimumAllowedAssets = assets.mulDivUp((1e18 - allowedRebalanceDeviation), 1e18);
        uint256 maximumAllowedAssets = assets.mulDivDown((1e18 + allowedRebalanceDeviation), 1e18);
        assets = totalAssets();
        if (assets > maximumAllowedAssets || assets < minimumAllowedAssets)
            revert Cellar__TotalAssetDeviatedOutsideRange(assets, minimumAllowedAssets, maximumAllowedAssets);
        if (totalShares != totalSupply()) revert Cellar__TotalSharesMustRemainConstant(totalSupply(), totalShares);

        emit Rebalance(fromPosition, toPosition, assetsFrom, assetsTo);
    }

    // ============================================ LIMITS LOGIC ============================================

    /**
     * @notice Total amount of assets that can be deposited for a user.
     * @dev This function does not take into account performance fees.
     *      Performance fees would reduce `receiver`s `ownedAssets`,
     *      making the `assets` value returned lower than actual
     * @dev EIP4626 states maxDeposit must not revert, but it is possible for `totalAssets` to revert
     * so it does NOT conform to ERC4626 standards.
     * @param receiver address of account that would receive the shares
     * @return assets maximum amount of assets that can be deposited
     */
    function maxDeposit(address receiver) public view override returns (uint256 assets) {
        if (isShutdown) return 0;

        uint256 asssetDepositLimit = depositLimit;
        uint256 asssetLiquidityLimit = liquidityLimit;
        if (asssetDepositLimit == type(uint256).max && asssetLiquidityLimit == type(uint256).max)
            return type(uint256).max;

        // Get data efficiently.
        uint256 _totalAssets = totalAssets();
        uint256 ownedAssets = _convertToAssets(balanceOf(receiver), _totalAssets);

        uint256 leftUntilDepositLimit = asssetDepositLimit.subMinZero(ownedAssets);
        uint256 leftUntilLiquidityLimit = asssetLiquidityLimit.subMinZero(_totalAssets);

        // Only return the more relevant of the two.
        assets = Math.min(leftUntilDepositLimit, leftUntilLiquidityLimit);
    }

    /**
     * @notice Total amount of shares that can be minted for a user.
     * @dev This function does not take into account performance fees.
     *      Performance fees would reduce `receiver`s `ownedAssets`,
     *      making the `shares` value returned lower than actual
     * @dev EIP4626 states maxMint must not revert, but it is possible for `totalAssets` to revert
     * so it does NOT conform to ERC4626 standards.
     * @param receiver address of account that would receive the shares
     * @return shares maximum amount of shares that can be minted
     */
    function maxMint(address receiver) public view override returns (uint256) {
        uint256 amount = maxDeposit(receiver);
        return amount == type(uint256).max ? amount : convertToShares(amount);
    }

    // ========================================= FEES LOGIC =========================================

    /**
     * @notice Emitted when High Watermark is reset.
     * @param newHighWatermark new high watermark
     */
    event HighWatermarkReset(uint256 newHighWatermark);

    /**
     * @notice Attempted to send fee shares to strategist payout address, when address is not set.
     */
    error Cellar__PayoutNotSet();

    /**
     * @notice Resets High Watermark to equal current total assets.
     * @notice This function can be abused by Strategists, so it should only be callable by governance.
     */
    function resetHighWatermark() external onlyOwner {
        uint256 _totalAssets = totalAssets();
        feeData.highWatermark = _totalAssets;

        emit HighWatermarkReset(_totalAssets);
    }

    /**
     * @notice Calculates how many assets Strategist would earn performance fees
     * @param _totalAssets uint256 value of the total assets in the cellar
     * @return feeInAssets amount of assets to take as fees
     */
    function _previewPerformanceFees(uint256 _totalAssets) internal view returns (uint256 feeInAssets) {
        uint64 performanceFee = feeData.performanceFee;
        if (performanceFee == 0 || _totalAssets == 0) return 0;

        uint256 highWatermark = feeData.highWatermark;

        if (_totalAssets > highWatermark) {
            uint256 yield = _totalAssets - highWatermark;
            feeInAssets = yield.mulWadDown(performanceFee);
        }
    }

    /**
     * @notice Mints cellar performance fee shares if current share price is above high watermark
     * @dev If performance fees are minted, the resulting HWM will be greater than the current share price
     *      since performance fees dilute share value.
     * @param _totalAssets uint256 value of the total assets in the cellar
     */
    function _takePerformanceFees(uint256 _totalAssets) internal {
        uint256 feeInAssets = _previewPerformanceFees(_totalAssets);
        if (feeInAssets > 0) {
            uint256 platformFeesInShares = _convertToFees(_convertToShares(feeInAssets, _totalAssets));
            if (platformFeesInShares > 0) {
                feeData.highWatermark = _totalAssets;
                _mint(address(this), platformFeesInShares);
            }
        }
    }

    /**
     * @dev Calculate the amount of fees to mint such that value of fees after minting is not diluted.
     */
    function _convertToFees(uint256 feesInShares) internal view returns (uint256 fees) {
        // Saves an SLOAD.
        uint256 totalShares = totalSupply();

        // Get the amount of fees to mint. Without this, the value of fees minted would be slightly
        // diluted because total shares increased while total assets did not. This counteracts that.
        if (totalShares > feesInShares) {
            // Denominator is greater than zero
            uint256 denominator = totalShares - feesInShares;
            fees = feesInShares.mulDivUp(totalShares, denominator);
        }
        // If denominator is less than or equal to zero, `fees` should be zero.
    }

    /**
     * @notice Emitted when platform fees are send to the Sommelier chain.
     * @param feesInSharesRedeemed amount of fees redeemed for assets to send
     * @param feesInAssetsSent amount of assets fees were redeemed for that were sent
     */
    event SendFees(uint256 feesInSharesRedeemed, uint256 feesInAssetsSent);

    /**
     * @notice Transfer accrued fees to the Sommelier chain to distribute.
     * @dev Fees are accrued as shares and redeemed upon transfer.
     * @dev assumes cellar's accounting asset is able to be transferred and sent to Cosmos
     */
    function sendFees() external nonReentrant {
        address strategistPayoutAddress = feeData.strategistPayoutAddress;
        if (strategistPayoutAddress == address(0)) revert Cellar__PayoutNotSet();

        uint256 _totalAssets = totalAssets();

        // Since this action mints shares, calculate outstanding performance fees due.
        _takePerformanceFees(_totalAssets);

        uint256 totalFees = balanceOf(address(this));

        uint256 strategistFeeSharesDue = totalFees.mulWadDown(feeData.strategistPerformanceCut);

        // Calculate platform fees earned.
        uint256 elapsedTime = block.timestamp - lastAccrual;
        uint256 platformFeeInAssets = (_totalAssets * elapsedTime * feeData.platformFee) / 1e18 / 365 days;
        uint256 platformFees = _convertToFees(_convertToShares(platformFeeInAssets, _totalAssets));
        _mint(address(this), platformFees);
        totalFees += platformFees;

        strategistFeeSharesDue += platformFees.mulWadDown(feeData.strategistPlatformCut);
        if (strategistFeeSharesDue > 0) {
            //transfer shares to strategist
            _transfer(address(this), strategistPayoutAddress, strategistFeeSharesDue);

            totalFees -= strategistFeeSharesDue;
        }

        lastAccrual = uint32(block.timestamp);

        // Redeem our fee shares for assets to send to the fee distributor module.
        uint256 assets = _convertToAssets(totalFees, _totalAssets);
        if (assets > 0) {
            // Without this, assets paid out as fees would be counted as a loss.
            feeData.highWatermark -= assets;

            _burn(address(this), totalFees);

            // Transfer assets to a fee distributor on the Sommelier chain.
            IGravity gravityBridge = IGravity(registry.getAddress(0));
            asset.safeApprove(address(gravityBridge), assets);
            gravityBridge.sendToCosmos(address(asset), feeData.feesDistributor, assets);
        }

        emit SendFees(totalFees, assets);
    }

    // ========================================== HELPER FUNCTIONS ==========================================

    /**
     * @dev Deposit into a position according to its position type and update related state.
     * @param position address to deposit funds into
     * @param assets the amount of assets to deposit into the position
     */
    function _depositTo(address position, uint256 assets) internal {
        PositionType positionType = getPositionType[position];

        // Deposit into position.
        if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) {
            ERC4626(position).asset().safeApprove(position, assets);
            ERC4626(position).deposit(assets, address(this));
        }
    }

    /**
     * @dev Withdraw from a position according to its position type and update related state.
     * @param position address to withdraw funds from
     * @param assets the amount of assets to withdraw from the position
     * @param receiver the address to sent withdrawn assets to
     */
    function _withdrawFrom(
        address position,
        uint256 assets,
        address receiver
    ) internal {
        PositionType positionType = getPositionType[position];

        // Withdraw from position.
        if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) {
            ERC4626(position).withdraw(assets, receiver, address(this));
        } else {
            if (receiver != address(this)) ERC20(position).safeTransfer(receiver, assets);
        }
    }

    /**
     * @dev Get the withdrawable balance of a position according to its position type.
     * @param position position to get the withdrawable balance of
     */
    function _withdrawableFrom(address position) internal view returns (uint256) {
        PositionType positionType = getPositionType[position];

        if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) {
            return ERC4626(position).maxWithdraw(address(this));
        } else {
            return ERC20(position).balanceOf(address(this));
        }
    }

    /**
     * @dev Get the balance of a position according to its position type.
     * @dev For ERC4626 position balances, this uses `previewRedeem` as opposed
     *      to `convertToAssets` so that balanceOf ERC4626 positions includes fees taken on withdraw.
     * @param position position to get the balance of
     */
    function _balanceOf(address position) internal view returns (uint256) {
        PositionType positionType = getPositionType[position];

        if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) {
            return ERC4626(position).previewRedeem(ERC4626(position).balanceOf(address(this)));
        } else {
            return ERC20(position).balanceOf(address(this));
        }
    }

    /**
     * @dev Get the asset of a position according to its position type.
     * @param position to get the asset of
     */
    function _assetOf(address position) internal view returns (ERC20) {
        PositionType positionType = getPositionType[position];

        if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) {
            return ERC4626(position).asset();
        } else {
            return ERC20(position);
        }
    }

    /**
     * @notice Attempted to swap with bad parameters.
     */
    error Cellar__WrongSwapParams();

    /**
     * @dev Perform a swap using the swap router and check that it behaves as expected.
     * @param assetIn the asset to sell
     * @param amountIn the amount of `assetIn` to sell
     * @param exchange the exchange to sell `assetIn` on
     * @param params Abi encoded swap parameters dependent on the `exchange` selected.
     *               Refer to SwapRouter.sol for `params` makeup
     * @param receiver the address to send the swapped assets to
     */
    function _swap(
        ERC20 assetIn,
        ERC20 assetOut,
        uint256 amountIn,
        SwapRouter.Exchange exchange,
        bytes calldata params,
        address receiver
    ) internal returns (uint256 amountOut) {
        // Store the expected amount of the asset in that we expect to have after the swap.
        uint256 expectedAssetsInAfter = assetIn.balanceOf(address(this)) - amountIn;

        // Get the address of the latest swap router.
        SwapRouter swapRouter = SwapRouter(registry.getAddress(1));

        // Approve swap router to swap assets.
        assetIn.safeApprove(address(swapRouter), amountIn);

        // Perform swap.
        amountOut = swapRouter.swap(exchange, params, receiver, assetIn, assetOut);

        // Check that the amount of assets swapped is what is expected. Will revert if the `params`
        // specified a different amount of assets to swap then `amountIn`.
        if (assetIn.balanceOf(address(this)) != expectedAssetsInAfter) revert Cellar__WrongSwapParams();
    }
}

File 2 of 34 : ERC4626.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Math } from "src/utils/Math.sol";

/// @notice Minimal ERC4626 tokenized Vault implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol)
abstract contract ERC4626 is ERC20, ERC20Permit {
    using SafeERC20 for ERC20;
    using Math for uint256;

    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed caller,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /*//////////////////////////////////////////////////////////////
                               IMMUTABLES
    //////////////////////////////////////////////////////////////*/

    ERC20 public immutable asset;

    constructor(
        ERC20 _asset,
        string memory _name,
        string memory _symbol
    ) ERC20(_name, _symbol) ERC20Permit(_name) {
        asset = _asset;
    }

    /*//////////////////////////////////////////////////////////////
                        DEPOSIT/WITHDRAWAL LOGIC
    //////////////////////////////////////////////////////////////*/

    function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) {
        // Check for rounding error since we round down in previewDeposit.
        require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

        beforeDeposit(assets, shares, receiver);

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);

        afterDeposit(assets, shares, receiver);
    }

    function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) {
        assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.

        beforeDeposit(assets, shares, receiver);

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);

        afterDeposit(assets, shares, receiver);
    }

    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) public virtual returns (uint256 shares) {
        shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up.

        if (msg.sender != owner) {
            _spendAllowance(owner, msg.sender, shares);
        }

        beforeWithdraw(assets, shares, receiver, owner);

        _burn(owner, shares);

        emit Withdraw(msg.sender, receiver, owner, assets, shares);

        asset.safeTransfer(receiver, assets);

        afterWithdraw(assets, shares, receiver, owner);
    }

    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) public virtual returns (uint256 assets) {
        if (msg.sender != owner) {
            _spendAllowance(owner, msg.sender, shares);
        }

        // Check for rounding error since we round down in previewRedeem.
        require((assets = previewRedeem(shares)) != 0, "ZERO_ASSETS");

        beforeWithdraw(assets, shares, receiver, owner);

        _burn(owner, shares);

        emit Withdraw(msg.sender, receiver, owner, assets, shares);

        asset.safeTransfer(receiver, assets);

        afterWithdraw(assets, shares, receiver, owner);
    }

    /*//////////////////////////////////////////////////////////////
                            ACCOUNTING LOGIC
    //////////////////////////////////////////////////////////////*/

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

    function convertToShares(uint256 assets) public view virtual returns (uint256) {
        uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets());
    }

    function convertToAssets(uint256 shares) public view virtual returns (uint256) {
        uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply);
    }

    function previewDeposit(uint256 assets) public view virtual returns (uint256) {
        return convertToShares(assets);
    }

    function previewMint(uint256 shares) public view virtual returns (uint256) {
        uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply);
    }

    function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
        uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets());
    }

    function previewRedeem(uint256 shares) public view virtual returns (uint256) {
        return convertToAssets(shares);
    }

    /*//////////////////////////////////////////////////////////////
                     DEPOSIT/WITHDRAWAL LIMIT LOGIC
    //////////////////////////////////////////////////////////////*/

    function maxDeposit(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    function maxMint(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    function maxWithdraw(address owner) public view virtual returns (uint256) {
        return convertToAssets(balanceOf(owner));
    }

    function maxRedeem(address owner) public view virtual returns (uint256) {
        return balanceOf(owner);
    }

    /*//////////////////////////////////////////////////////////////
                          INTERNAL HOOKS LOGIC
    //////////////////////////////////////////////////////////////*/

    function beforeDeposit(
        uint256 assets,
        uint256 shares,
        address receiver
    ) internal virtual {}

    function afterDeposit(
        uint256 assets,
        uint256 shares,
        address receiver
    ) internal virtual {}

    function beforeWithdraw(
        uint256 assets,
        uint256 shares,
        address receiver,
        address owner
    ) internal virtual {}

    function afterWithdraw(
        uint256 assets,
        uint256 shares,
        address receiver,
        address owner
    ) internal virtual {}
}

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

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

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

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

File 4 of 34 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 5 of 34 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.4.1) (utils/math/SafeCast.sol)

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248) {
        require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits");
        return int248(value);
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240) {
        require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits");
        return int240(value);
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232) {
        require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits");
        return int232(value);
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224) {
        require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits");
        return int224(value);
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216) {
        require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits");
        return int216(value);
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208) {
        require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits");
        return int208(value);
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200) {
        require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits");
        return int200(value);
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192) {
        require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits");
        return int192(value);
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184) {
        require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits");
        return int184(value);
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176) {
        require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits");
        return int176(value);
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168) {
        require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits");
        return int168(value);
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160) {
        require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits");
        return int160(value);
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152) {
        require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits");
        return int152(value);
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144) {
        require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits");
        return int144(value);
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136) {
        require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits");
        return int136(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120) {
        require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits");
        return int120(value);
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112) {
        require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits");
        return int112(value);
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104) {
        require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits");
        return int104(value);
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96) {
        require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits");
        return int96(value);
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88) {
        require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits");
        return int88(value);
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80) {
        require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits");
        return int80(value);
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72) {
        require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits");
        return int72(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56) {
        require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits");
        return int56(value);
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48) {
        require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits");
        return int48(value);
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40) {
        require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits");
        return int40(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24) {
        require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits");
        return int24(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 6 of 34 : Registry.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

contract Registry is Ownable {
    // ============================================= ADDRESS CONFIG =============================================

    /**
     * @notice Emitted when the address of a contract is changed.
     * @param id value representing the unique ID tied to the changed contract
     * @param oldAddress address of the contract before the change
     * @param newAddress address of the contract after the contract
     */
    event AddressChanged(uint256 indexed id, address oldAddress, address newAddress);

    /**
     * @notice Attempted to set the address of a contract that is not registered.
     * @param id id of the contract that is not registered
     */
    error Registry__ContractNotRegistered(uint256 id);

    /**
     * @notice Emitted when depositor privilege changes.
     * @param depositor depositor address
     * @param state the new state of the depositor privilege
     */
    event DepositorOnBehalfChanged(address depositor, bool state);

    /**
     * @notice The unique ID that the next registered contract will have.
     */
    uint256 public nextId;

    /**
     * @notice Get the address associated with an id.
     */
    mapping(uint256 => address) public getAddress;

    /**
     * @notice In order for an address to make deposits on behalf of users they must be approved.
     */
    mapping(address => bool) public approvedForDepositOnBehalf;

    /**
     * @notice toggles a depositors  ability to deposit into cellars on behalf of users.
     */
    function setApprovedForDepositOnBehalf(address depositor, bool state) external onlyOwner {
        approvedForDepositOnBehalf[depositor] = state;
        emit DepositorOnBehalfChanged(depositor, state);
    }

    /**
     * @notice Set the address of the contract at a given id.
     */
    function setAddress(uint256 id, address newAddress) external onlyOwner {
        if (id >= nextId) revert Registry__ContractNotRegistered(id);

        emit AddressChanged(id, getAddress[id], newAddress);

        getAddress[id] = newAddress;
    }

    // ============================================= INITIALIZATION =============================================

    /**
     * @param gravityBridge address of GravityBridge contract
     * @param swapRouter address of SwapRouter contract
     * @param priceRouter address of PriceRouter contract
     */
    constructor(
        address gravityBridge,
        address swapRouter,
        address priceRouter
    ) Ownable() {
        _register(gravityBridge);
        _register(swapRouter);
        _register(priceRouter);
    }

    // ============================================ REGISTER CONFIG ============================================

    /**
     * @notice Emitted when a new contract is registered.
     * @param id value representing the unique ID tied to the new contract
     * @param newContract address of the new contract
     */
    event Registered(uint256 indexed id, address indexed newContract);

    /**
     * @notice Register the address of a new contract.
     * @param newContract address of the new contract to register
     */
    function register(address newContract) external onlyOwner {
        _register(newContract);
    }

    function _register(address newContract) internal {
        getAddress[nextId] = newContract;

        emit Registered(nextId, newContract);

        nextId++;
    }
}

File 7 of 34 : SwapRouter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Multicall } from "src/base/Multicall.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IUniswapV2Router02 as IUniswapV2Router } from "src/interfaces/external/IUniswapV2Router02.sol";
import { IUniswapV3Router } from "src/interfaces/external/IUniswapV3Router.sol";

/**
 * @title Sommelier Swap Router
 * @notice Provides a universal interface allowing Sommelier contracts to interact with multiple
 *         different exchanges to perform swaps.
 * @dev Perform multiple swaps using Multicall.
 * @author crispymangoes, Brian Le
 */
contract SwapRouter is Multicall {
    using SafeERC20 for ERC20;

    /**
     * @param UNIV2 Uniswap V2
     * @param UNIV3 Uniswap V3
     */
    enum Exchange {
        UNIV2,
        UNIV3
    }

    /**
     * @notice Get the selector of the function to call in order to perform swap with a given exchange.
     */
    mapping(Exchange => bytes4) public getExchangeSelector;

    // ========================================== CONSTRUCTOR ==========================================

    /**
     * @notice Uniswap V2 swap router contract.
     */
    IUniswapV2Router public immutable uniswapV2Router; // 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D

    /**
     * @notice Uniswap V3 swap router contract.
     */
    IUniswapV3Router public immutable uniswapV3Router; // 0xE592427A0AEce92De3Edee1F18E0157C05861564

    /**
     * @param _uniswapV2Router address of the Uniswap V2 swap router contract
     * @param _uniswapV3Router address of the Uniswap V3 swap router contract
     */
    constructor(IUniswapV2Router _uniswapV2Router, IUniswapV3Router _uniswapV3Router) {
        // Set up all exchanges.
        uniswapV2Router = _uniswapV2Router;
        uniswapV3Router = _uniswapV3Router;

        // Set up mapping between IDs and selectors.
        getExchangeSelector[Exchange.UNIV2] = SwapRouter(this).swapWithUniV2.selector;
        getExchangeSelector[Exchange.UNIV3] = SwapRouter(this).swapWithUniV3.selector;
    }

    // ======================================= SWAP OPERATIONS =======================================

    /**
     * @notice Attempted to perform a swap that reverted without a message.
     */
    error SwapRouter__SwapReverted();

    /**
     * @notice Attempted to perform a swap with mismatched assetIn and swap data.
     * @param actual the address encoded into the swap data
     * @param expected the address passed in with assetIn
     */
    error SwapRouter__AssetInMisMatch(address actual, address expected);

    /**
     * @notice Attempted to perform a swap with mismatched assetOut and swap data.
     * @param actual the address encoded into the swap data
     * @param expected the address passed in with assetIn
     */
    error SwapRouter__AssetOutMisMatch(address actual, address expected);

    /**
     * @notice Perform a swap using a supported exchange.
     * @param exchange value dictating which exchange to use to make the swap
     * @param swapData encoded data used for the swap
     * @param receiver address to send the received assets to
     * @return amountOut amount of assets received from the swap
     */
    function swap(
        Exchange exchange,
        bytes memory swapData,
        address receiver,
        ERC20 assetIn,
        ERC20 assetOut
    ) external returns (uint256 amountOut) {
        // Route swap call to appropriate function using selector.
        (bool success, bytes memory result) = address(this).delegatecall(
            abi.encodeWithSelector(getExchangeSelector[exchange], swapData, receiver, assetIn, assetOut)
        );

        if (!success) {
            // If there is return data, the call reverted with a reason or a custom error so we
            // bubble up the error message.
            if (result.length > 0) {
                assembly {
                    let returndata_size := mload(result)
                    revert(add(32, result), returndata_size)
                }
            } else {
                revert SwapRouter__SwapReverted();
            }
        }

        amountOut = abi.decode(result, (uint256));
    }

    /**
     * @notice Perform a swap using Uniswap V2.
     * @param swapData bytes variable storing the following swap information:
     *      address[] path: array of addresses dictating what swap path to follow
     *      uint256 amount: amount of the first asset in the path to swap
     *      uint256 amountOutMin: the minimum amount of the last asset in the path to receive
     * @param receiver address to send the received assets to
     * @return amountOut amount of assets received from the swap
     */
    function swapWithUniV2(
        bytes memory swapData,
        address receiver,
        ERC20 assetIn,
        ERC20 assetOut
    ) public returns (uint256 amountOut) {
        (address[] memory path, uint256 amount, uint256 amountOutMin) = abi.decode(
            swapData,
            (address[], uint256, uint256)
        );

        // Check that path matches assetIn and assetOut.
        if (assetIn != ERC20(path[0])) revert SwapRouter__AssetInMisMatch(path[0], address(assetIn));
        if (assetOut != ERC20(path[path.length - 1]))
            revert SwapRouter__AssetOutMisMatch(path[path.length - 1], address(assetOut));

        // Transfer assets to this contract to swap.
        assetIn.safeTransferFrom(msg.sender, address(this), amount);

        // Approve assets to be swapped through the router.
        assetIn.safeApprove(address(uniswapV2Router), amount);

        // Execute the swap.
        uint256[] memory amountsOut = uniswapV2Router.swapExactTokensForTokens(
            amount,
            amountOutMin,
            path,
            receiver,
            block.timestamp + 60
        );

        amountOut = amountsOut[amountsOut.length - 1];
    }

    /**
     * @notice Perform a swap using Uniswap V3.
     * @param swapData bytes variable storing the following swap information
     *      address[] path: array of addresses dictating what swap path to follow
     *      uint24[] poolFees: array of pool fees dictating what swap pools to use
     *      uint256 amount: amount of the first asset in the path to swap
     *      uint256 amountOutMin: the minimum amount of the last asset in the path to receive
     * @param receiver address to send the received assets to
     * @return amountOut amount of assets received from the swap
     */
    function swapWithUniV3(
        bytes memory swapData,
        address receiver,
        ERC20 assetIn,
        ERC20 assetOut
    ) public returns (uint256 amountOut) {
        (address[] memory path, uint24[] memory poolFees, uint256 amount, uint256 amountOutMin) = abi.decode(
            swapData,
            (address[], uint24[], uint256, uint256)
        );

        // Check that path matches assetIn and assetOut.
        if (assetIn != ERC20(path[0])) revert SwapRouter__AssetInMisMatch(path[0], address(assetIn));
        if (assetOut != ERC20(path[path.length - 1]))
            revert SwapRouter__AssetOutMisMatch(path[path.length - 1], address(assetOut));

        // Transfer assets to this contract to swap.
        assetIn.safeTransferFrom(msg.sender, address(this), amount);

        // Approve assets to be swapped through the router.
        assetIn.safeApprove(address(uniswapV3Router), amount);

        // Encode swap parameters.
        bytes memory encodePackedPath = abi.encodePacked(address(assetIn));
        for (uint256 i = 1; i < path.length; i++)
            encodePackedPath = abi.encodePacked(encodePackedPath, poolFees[i - 1], path[i]);

        // Execute the swap.
        amountOut = uniswapV3Router.exactInput(
            IUniswapV3Router.ExactInputParams({
                path: encodePackedPath,
                recipient: receiver,
                deadline: block.timestamp + 60,
                amountIn: amount,
                amountOutMinimum: amountOutMin
            })
        );
    }
}

File 8 of 34 : PriceRouter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { FeedRegistryInterface } from "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol";
import { AggregatorV2V3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
import { IChainlinkAggregator } from "src/interfaces/external/IChainlinkAggregator.sol";
import { Denominations } from "@chainlink/contracts/src/v0.8/Denominations.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { Math } from "src/utils/Math.sol";

/**
 * @title Sommelier Price Router
 * @notice Provides a universal interface allowing Sommelier contracts to retrieve secure pricing
 *         data from Chainlink.
 * @author crispymangoes, Brian Le
 */
contract PriceRouter is Ownable {
    using SafeERC20 for ERC20;
    using SafeCast for int256;
    using Math for uint256;

    event AddAsset(address indexed asset);

    // =========================================== ASSETS CONFIG ===========================================

    /**
     * @param minPrice minimum price in USD for the asset before reverting
     * @param maxPrice maximum price in USD for the asset before reverting
     * @param isPriceRangeInETH if true price range values are given in ETH, if false price range is given in USD
     * @param heartbeat maximum allowed time that can pass with no update before price data is considered stale
     * @param isSupported whether this asset is supported by the platform or not
     */
    struct AssetConfig {
        uint256 minPrice;
        uint256 maxPrice;
        bool isPriceRangeInETH;
        uint96 heartbeat;
        bool isSupported;
    }

    /**
     * @notice Get the asset data for a given asset.
     */
    mapping(ERC20 => AssetConfig) public getAssetConfig;

    uint96 public constant DEFAULT_HEART_BEAT = 1 days;

    // ======================================= ADAPTOR OPERATIONS =======================================

    /**
     * @notice Attempted to set a minimum price below the Chainlink minimum price (with buffer).
     * @param minPrice minimum price attempted to set
     * @param bufferedMinPrice minimum price that can be set including buffer
     */
    error PriceRouter__InvalidMinPrice(uint256 minPrice, uint256 bufferedMinPrice);

    /**
     * @notice Attempted to set a maximum price above the Chainlink maximum price (with buffer).
     * @param maxPrice maximum price attempted to set
     * @param bufferedMaxPrice maximum price that can be set including buffer
     */
    error PriceRouter__InvalidMaxPrice(uint256 maxPrice, uint256 bufferedMaxPrice);

    /**
     * @notice Attempted to add an invalid asset.
     * @param asset address of the invalid asset
     */
    error PriceRouter__InvalidAsset(address asset);

    /**
     * @notice Attempted to add an asset with a certain price range denomination, but actual denomination was different.
     * @param expected price range denomination
     * @param actual price range denomination
     * @dev If an asset has price feeds in USD and ETH, the feed in USD is favored
     */
    error PriceRouter__PriceRangeDenominationMisMatch(bool expected, bool actual);

    /**
     * @notice Attempted to add an asset with invalid min/max prices.
     * @param min price
     * @param max price
     */
    error PriceRouter__MinPriceGreaterThanMaxPrice(uint256 min, uint256 max);

    /**
     * @notice Add an asset for the price router to support.
     * @param asset address of asset to support on the platform
     * @param minPrice minimum price in USD with 8 decimals for the asset before reverting,
     *                 set to `0` to use Chainlink's default
     * @param maxPrice maximum price in USD with 8 decimals for the asset before reverting,
     *                 set to `0` to use Chainlink's default
     * @param heartbeat maximum amount of time that can pass without the price data being updated
     *                  before reverting, set to `0` to use the default of 1 day
     */
    function addAsset(
        ERC20 asset,
        uint256 minPrice,
        uint256 maxPrice,
        bool rangeInETH,
        uint96 heartbeat
    ) external onlyOwner {
        if (address(asset) == address(0)) revert PriceRouter__InvalidAsset(address(asset));

        // Use Chainlink to get the min and max of the asset.
        ERC20 assetToQuery = _remap(asset);
        (uint256 minFromChainklink, uint256 maxFromChainlink, bool isETH) = _getPriceRange(assetToQuery);

        // Check if callers expected price range  denomination matches actual.
        if (rangeInETH != isETH) revert PriceRouter__PriceRangeDenominationMisMatch(rangeInETH, isETH);

        // Add a ~10% buffer to minimum and maximum price from Chainlink because Chainlink can stop updating
        // its price before/above the min/max price.
        uint256 bufferedMinPrice = minFromChainklink.mulWadDown(1.1e18);
        uint256 bufferedMaxPrice = maxFromChainlink.mulWadDown(0.9e18);

        if (minPrice == 0) {
            minPrice = bufferedMinPrice;
        } else {
            if (minPrice < bufferedMinPrice) revert PriceRouter__InvalidMinPrice(minPrice, bufferedMinPrice);
        }

        if (maxPrice == 0) {
            maxPrice = bufferedMaxPrice;
        } else {
            if (maxPrice > bufferedMaxPrice) revert PriceRouter__InvalidMaxPrice(maxPrice, bufferedMaxPrice);
        }

        if (minPrice >= maxPrice) revert PriceRouter__MinPriceGreaterThanMaxPrice(minPrice, maxPrice);

        getAssetConfig[asset] = AssetConfig({
            minPrice: minPrice,
            maxPrice: maxPrice,
            isPriceRangeInETH: isETH,
            heartbeat: heartbeat != 0 ? heartbeat : DEFAULT_HEART_BEAT,
            isSupported: true
        });

        emit AddAsset(address(asset));
    }

    function isSupported(ERC20 asset) external view returns (bool) {
        return getAssetConfig[asset].isSupported;
    }

    // ======================================= PRICING OPERATIONS =======================================

    /**
     * @notice Get the value of an asset in terms of another asset.
     * @param baseAsset address of the asset to get the price of in terms of the quote asset
     * @param amount amount of the base asset to price
     * @param quoteAsset address of the asset that the base asset is priced in terms of
     * @return value value of the amount of base assets specified in terms of the quote asset
     */
    function getValue(
        ERC20 baseAsset,
        uint256 amount,
        ERC20 quoteAsset
    ) external view returns (uint256 value) {
        value = amount.mulDivDown(getExchangeRate(baseAsset, quoteAsset), 10**baseAsset.decimals());
    }

    /**
     * @notice Attempted an operation with arrays of unequal lengths that were expected to be equal length.
     */
    error PriceRouter__LengthMismatch();

    /**
     * @notice Get the total value of multiple assets in terms of another asset.
     * @param baseAssets addresses of the assets to get the price of in terms of the quote asset
     * @param amounts amounts of each base asset to price
     * @param quoteAsset address of the assets that the base asset is priced in terms of
     * @return value total value of the amounts of each base assets specified in terms of the quote asset
     */
    function getValues(
        ERC20[] memory baseAssets,
        uint256[] memory amounts,
        ERC20 quoteAsset
    ) external view returns (uint256 value) {
        uint256 numOfAssets = baseAssets.length;
        if (numOfAssets != amounts.length) revert PriceRouter__LengthMismatch();

        uint8 quoteAssetDecimals = quoteAsset.decimals();

        for (uint256 i; i < numOfAssets; i++) {
            ERC20 baseAsset = baseAssets[i];

            value += amounts[i].mulDivDown(
                _getExchangeRate(baseAsset, quoteAsset, quoteAssetDecimals),
                10**baseAsset.decimals()
            );
        }
    }

    /**
     * @notice Get the exchange rate between two assets.
     * @param baseAsset address of the asset to get the exchange rate of in terms of the quote asset
     * @param quoteAsset address of the asset that the base asset is exchanged for
     * @return exchangeRate rate of exchange between the base asset and the quote asset
     */
    function getExchangeRate(ERC20 baseAsset, ERC20 quoteAsset) public view returns (uint256 exchangeRate) {
        exchangeRate = _getExchangeRate(baseAsset, quoteAsset, quoteAsset.decimals());
    }

    /**
     * @notice Get the exchange rates between multiple assets and another asset.
     * @param baseAssets addresses of the assets to get the exchange rates of in terms of the quote asset
     * @param quoteAsset address of the asset that the base assets are exchanged for
     * @return exchangeRates rate of exchange between the base assets and the quote asset
     */
    function getExchangeRates(ERC20[] memory baseAssets, ERC20 quoteAsset)
        external
        view
        returns (uint256[] memory exchangeRates)
    {
        uint8 quoteAssetDecimals = quoteAsset.decimals();

        uint256 numOfAssets = baseAssets.length;
        exchangeRates = new uint256[](numOfAssets);
        for (uint256 i; i < numOfAssets; i++)
            exchangeRates[i] = _getExchangeRate(baseAssets[i], quoteAsset, quoteAssetDecimals);
    }

    /**
     * @notice Get the minimum and maximum valid price for an asset.
     * @param asset address of the asset to get the price range of
     * @return min minimum valid price for the asset
     * @return max maximum valid price for the asset
     */
    function getPriceRange(ERC20 asset)
        public
        view
        returns (
            uint256 min,
            uint256 max,
            bool isETH
        )
    {
        AssetConfig memory config = getAssetConfig[asset];

        if (!config.isSupported) revert PriceRouter__UnsupportedAsset(address(asset));

        (min, max, isETH) = (config.minPrice, config.maxPrice, config.isPriceRangeInETH);
    }

    /**
     * @notice Get the minimum and maximum valid prices for an asset.
     * @param _assets addresses of the assets to get the price ranges for
     * @return min minimum valid price for each asset
     * @return max maximum valid price for each asset
     */
    function getPriceRanges(ERC20[] memory _assets)
        external
        view
        returns (
            uint256[] memory min,
            uint256[] memory max,
            bool[] memory isETH
        )
    {
        uint256 numOfAssets = _assets.length;
        (min, max, isETH) = (new uint256[](numOfAssets), new uint256[](numOfAssets), new bool[](numOfAssets));
        for (uint256 i; i < numOfAssets; i++) (min[i], max[i], isETH[i]) = getPriceRange(_assets[i]);
    }

    // =========================================== HELPER FUNCTIONS ===========================================

    ERC20 private constant WETH = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
    ERC20 private constant WBTC = ERC20(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599);

    function _remap(ERC20 asset) internal pure returns (ERC20) {
        if (asset == WETH) return ERC20(Denominations.ETH);
        if (asset == WBTC) return ERC20(Denominations.BTC);
        return asset;
    }

    /**
     * @notice Gets the exchange rate between a base and a quote asset
     * @param baseAsset the asset to convert into quoteAsset
     * @param quoteAsset the asset base asset is converted into
     * @return exchangeRate value of base asset in terms of quote asset
     */
    function _getExchangeRate(
        ERC20 baseAsset,
        ERC20 quoteAsset,
        uint8 quoteAssetDecimals
    ) internal view returns (uint256 exchangeRate) {
        exchangeRate = getValueInUSD(baseAsset).mulDivDown(10**quoteAssetDecimals, getValueInUSD(quoteAsset));
    }

    /**
     * @notice Attempted to update the asset to one that is not supported by the platform.
     * @param asset address of the unsupported asset
     */
    error PriceRouter__UnsupportedAsset(address asset);

    /**
     * @notice Attempted an operation to price an asset that under its minimum valid price.
     * @param asset address of the asset that is under its minimum valid price
     * @param price price of the asset
     * @param minPrice minimum valid price of the asset
     */
    error PriceRouter__AssetBelowMinPrice(address asset, uint256 price, uint256 minPrice);

    /**
     * @notice Attempted an operation to price an asset that under its maximum valid price.
     * @param asset address of the asset that is under its maximum valid price
     * @param price price of the asset
     * @param maxPrice maximum valid price of the asset
     */
    error PriceRouter__AssetAboveMaxPrice(address asset, uint256 price, uint256 maxPrice);

    /**
     * @notice Attempted to fetch a price for an asset that has not been updated in too long.
     * @param asset address of the asset thats price is stale
     * @param timeSinceLastUpdate seconds since the last price update
     * @param heartbeat maximum allowed time between price updates
     */
    error PriceRouter__StalePrice(address asset, uint256 timeSinceLastUpdate, uint256 heartbeat);

    // =========================================== CHAINLINK PRICING FUNCTIONS ===========================================\
    /**
     * @notice Feed Registry contract used to get chainlink data feeds, use getFeed!!
     */
    FeedRegistryInterface public constant feedRegistry =
        FeedRegistryInterface(0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf);

    /**
     * @notice Could not find an asset's price in USD or ETH.
     * @param asset address of the asset
     */
    error PriceRouter__PriceNotAvailable(address asset);

    /**
     * @notice Interacts with Chainlink feed registry and first tries to get `asset` price in USD,
     *         if that fails, then it tries to get `asset` price in ETH, and then converts the answer into USD.
     * @param asset the ERC20 token to get the price of.
     * @return price the price of `asset` in USD
     */
    function getValueInUSD(ERC20 asset) public view returns (uint256 price) {
        AssetConfig memory config = getAssetConfig[asset];

        // Make sure asset is supported.
        if (!config.isSupported) revert PriceRouter__UnsupportedAsset(address(asset));

        // Remap asset if need be.
        asset = _remap(asset);

        if (!config.isPriceRangeInETH) {
            // Price feed is in USD.
            (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(address(asset), Denominations.USD);
            price = _price.toUint256();
            _checkPriceFeed(asset, price, _timestamp, config);
        } else {
            // Price feed is in ETH.
            (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(address(asset), Denominations.ETH);
            price = _price.toUint256();
            _checkPriceFeed(asset, price, _timestamp, config);

            // Convert price from ETH to USD.
            price = _price.toUint256().mulWadDown(_getExchangeRateFromETHToUSD());
        }
    }

    /**
     * @notice Could not find an asset's price range in USD or ETH.
     * @param asset address of the asset
     */
    error PriceRouter__PriceRangeNotAvailable(address asset);

    /**
     * @notice Interacts with Chainlink feed registry and first tries to get `asset` price range in USD,
     *         if that fails, then it tries to get `asset` price range in ETH, and then converts the range into USD.
     * @param asset the ERC20 token to get the price range of.
     * @return min the minimum price where Chainlink nodes stop updating the oracle
     * @return max the maximum price where Chainlink nodes stop updating the oracle
     */
    function _getPriceRange(ERC20 asset)
        internal
        view
        returns (
            uint256 min,
            uint256 max,
            bool isETH
        )
    {
        try feedRegistry.getFeed(address(asset), Denominations.USD) returns (AggregatorV2V3Interface aggregator) {
            IChainlinkAggregator chainlinkAggregator = IChainlinkAggregator(address(aggregator));

            min = uint256(uint192(chainlinkAggregator.minAnswer()));
            max = uint256(uint192(chainlinkAggregator.maxAnswer()));
            isETH = false;
        } catch {
            // If we can't find the USD price, then try the ETH price.
            try feedRegistry.getFeed(address(asset), Denominations.ETH) returns (AggregatorV2V3Interface aggregator) {
                IChainlinkAggregator chainlinkAggregator = IChainlinkAggregator(address(aggregator));

                min = uint256(uint192(chainlinkAggregator.minAnswer()));
                max = uint256(uint192(chainlinkAggregator.maxAnswer()));
                isETH = true;
            } catch {
                revert PriceRouter__PriceRangeNotAvailable(address(asset));
            }
        }
    }

    /**
     * @notice helper function to grab pricing data for ETH in USD
     * @return exchangeRate the exchange rate for ETH in terms of USD
     * @dev It is inefficient to re-calculate _checkPriceFeed for ETH -> USD multiple times for a single TX,
     * but this is done in the explicit way because it is simpler and less prone to logic errors.
     */
    function _getExchangeRateFromETHToUSD() internal view returns (uint256 exchangeRate) {
        (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(Denominations.ETH, Denominations.USD);
        exchangeRate = _price.toUint256();
        _checkPriceFeed(WETH, exchangeRate, _timestamp, getAssetConfig[WETH]);
    }

    /**
     * @notice helper function to validate a price feed is safe to use.
     * @param asset ERC20 asset price feed data is for.
     * @param value the price value the price feed gave.
     * @param timestamp the last timestamp the price feed was updated.
     * @param config the assets config storing min price, max price, and heartbeat requirements.
     */
    function _checkPriceFeed(
        ERC20 asset,
        uint256 value,
        uint256 timestamp,
        AssetConfig memory config
    ) internal view {
        uint256 minPrice = config.minPrice;
        if (value < minPrice) revert PriceRouter__AssetBelowMinPrice(address(asset), value, minPrice);

        uint256 maxPrice = config.maxPrice;
        if (value > maxPrice) revert PriceRouter__AssetAboveMaxPrice(address(asset), value, maxPrice);

        uint256 heartbeat = config.heartbeat;
        uint256 timeSinceLastUpdate = block.timestamp - timestamp;
        if (timeSinceLastUpdate > heartbeat)
            revert PriceRouter__StalePrice(address(asset), timeSinceLastUpdate, heartbeat);
    }
}

File 9 of 34 : IGravity.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

interface IGravity {
    function sendToCosmos(
        address _tokenContract,
        bytes32 _destination,
        uint256 _amount
    ) external;
}

File 10 of 34 : AddressArray.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/**
 * @notice A library to extend the address array data type.
 */
library AddressArray {
    // =========================================== ADDRESS STORAGE ===========================================

    /**
     * @notice Add an address to the array at a given index.
     * @param array address array to add the address to
     * @param index index to add the address at
     * @param value address to add to the array
     */
    function add(
        address[] storage array,
        uint256 index,
        address value
    ) internal {
        uint256 len = array.length;

        if (len > 0) {
            array.push(array[len - 1]);

            for (uint256 i = len - 1; i > index; i--) array[i] = array[i - 1];

            array[index] = value;
        } else {
            array.push(value);
        }
    }

    /**
     * @notice Remove an address from the array at a given index.
     * @param array address array to remove the address from
     * @param index index to remove the address at
     */
    function remove(address[] storage array, uint256 index) internal {
        uint256 len = array.length;

        require(index < len, "Index out of bounds");

        for (uint256 i = index; i < len - 1; i++) array[i] = array[i + 1];

        array.pop();
    }

    /**
     * @notice Remove the first occurrence of a value in an array.
     * @param array address array to remove the address from
     * @param value address to remove from the array
     */
    function remove(address[] storage array, address value) internal {
        uint256 len = array.length;

        for (uint256 i; i < len; i++)
            if (array[i] == value) {
                for (i; i < len - 1; i++) array[i] = array[i + 1];

                array.pop();

                return;
            }

        revert("Value not found");
    }

    /**
     * @notice Check whether an array contains an address.
     * @param array address array to check
     * @param value address to check for
     */
    function contains(address[] storage array, address value) internal view returns (bool) {
        for (uint256 i; i < array.length; i++) if (value == array[i]) return true;

        return false;
    }
}

File 11 of 34 : Math.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

library Math {
    /**
     * @notice Substract with a floor of 0 for the result.
     */
    function subMinZero(uint256 x, uint256 y) internal pure returns (uint256) {
        return x > y ? x - y : 0;
    }

    /**
     * @notice Used to change the decimals of precision used for an amount.
     */
    function changeDecimals(
        uint256 amount,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (uint256) {
        if (fromDecimals == toDecimals) {
            return amount;
        } else if (fromDecimals < toDecimals) {
            return amount * 10**(toDecimals - fromDecimals);
        } else {
            return amount / 10**(fromDecimals - toDecimals);
        }
    }

    // ===================================== OPENZEPPELIN'S MATH =====================================

    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    // ================================= SOLMATE's FIXEDPOINTMATHLIB =================================

    uint256 public constant WAD = 1e18; // The scalar of ETH and most ERC20s.

    function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
        return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
    }

    function mulDivDown(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 z) {
        assembly {
            // Store x * y in z for now.
            z := mul(x, y)

            // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
            if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
                revert(0, 0)
            }

            // Divide z by the denominator.
            z := div(z, denominator)
        }
    }

    function mulDivUp(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 z) {
        assembly {
            // Store x * y in z for now.
            z := mul(x, y)

            // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
            if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
                revert(0, 0)
            }

            // First, divide z - 1 by the denominator and add 1.
            // We allow z - 1 to underflow if z is 0, because we multiply the
            // end result by 0 if z is zero, ensuring we return 0 if z is zero.
            z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1))
        }
    }
}

File 12 of 34 : Owned.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event OwnerUpdated(address indexed user, address indexed newOwner);

    /*//////////////////////////////////////////////////////////////
                            OWNERSHIP STORAGE
    //////////////////////////////////////////////////////////////*/

    address public owner;

    modifier onlyOwner() virtual {
        require(msg.sender == owner, "UNAUTHORIZED");

        _;
    }

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(address _owner) {
        owner = _owner;

        emit OwnerUpdated(address(0), _owner);
    }

    /*//////////////////////////////////////////////////////////////
                             OWNERSHIP LOGIC
    //////////////////////////////////////////////////////////////*/

    function setOwner(address newOwner) public virtual onlyOwner {
        owner = newOwner;

        emit OwnerUpdated(msg.sender, newOwner);
    }
}

File 13 of 34 : ReentrancyGuard.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    uint256 private locked = 1;

    modifier nonReentrant() virtual {
        require(locked == 1, "REENTRANCY");

        locked = 2;

        _;

        locked = 1;
    }
}

File 14 of 34 : draft-ERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/extensions/draft-ERC20Permit.sol)

pragma solidity ^0.8.0;

import "./draft-IERC20Permit.sol";
import "../ERC20.sol";
import "../../../utils/cryptography/draft-EIP712.sol";
import "../../../utils/cryptography/ECDSA.sol";
import "../../../utils/Counters.sol";

/**
 * @dev Implementation 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.
 *
 * _Available since v3.4._
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
    using Counters for Counters.Counter;

    mapping(address => Counters.Counter) private _nonces;

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private constant _PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    /**
     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
     * However, to ensure consistency with the upgradeable transpiler, we will continue
     * to reserve a slot.
     * @custom:oz-renamed-from _PERMIT_TYPEHASH
     */
    // solhint-disable-next-line var-name-mixedcase
    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {}

    /**
     * @dev See {IERC20Permit-permit}.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual override {
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _approve(owner, spender, value);
    }

    /**
     * @dev See {IERC20Permit-nonces}.
     */
    function nonces(address owner) public view virtual override returns (uint256) {
        return _nonces[owner].current();
    }

    /**
     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view override returns (bytes32) {
        return _domainSeparatorV4();
    }

    /**
     * @dev "Consume a nonce": return the current value and increment.
     *
     * _Available since v4.1._
     */
    function _useNonce(address owner) internal virtual returns (uint256 current) {
        Counters.Counter storage nonce = _nonces[owner];
        current = nonce.current();
        nonce.increment();
    }
}

File 15 of 34 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

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

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

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

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

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

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

File 16 of 34 : 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 17 of 34 : 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 18 of 34 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 19 of 34 : Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;

import { IMulticall } from "src/interfaces/IMulticall.sol";

/**
 * @title Multicall
 * @notice Enables calling multiple methods in a single call to the contract
 * From: https://github.com/Uniswap/v3-periphery/contracts/base/Multicall.sol
 */
abstract contract Multicall is IMulticall {
    /// @inheritdoc IMulticall
    function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);

            if (!success) {
                // Next 5 lines from https://ethereum.stackexchange.com/a/83577
                // solhint-disable-next-line reason-string
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }

            results[i] = result;
        }
    }
}

File 20 of 34 : IUniswapV2Router02.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);

    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (
            uint256 amountToken,
            uint256 amountETH,
            uint256 liquidity
        );

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);

    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETHWithPermit(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountToken, uint256 amountETH);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) external pure returns (uint256 amountB);

    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountOut);

    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountIn);

    function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);

    function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts);
}

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountETH);

    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}

File 21 of 34 : IUniswapV3Router.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface IUniswapV3Router is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 22 of 34 : FeedRegistryInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;

import "./AggregatorV2V3Interface.sol";

interface FeedRegistryInterface {
  struct Phase {
    uint16 phaseId;
    uint80 startingAggregatorRoundId;
    uint80 endingAggregatorRoundId;
  }

  event FeedProposed(
    address indexed asset,
    address indexed denomination,
    address indexed proposedAggregator,
    address currentAggregator,
    address sender
  );
  event FeedConfirmed(
    address indexed asset,
    address indexed denomination,
    address indexed latestAggregator,
    address previousAggregator,
    uint16 nextPhaseId,
    address sender
  );

  // V3 AggregatorV3Interface

  function decimals(address base, address quote) external view returns (uint8);

  function description(address base, address quote) external view returns (string memory);

  function version(address base, address quote) external view returns (uint256);

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

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

  // V2 AggregatorInterface

  function latestAnswer(address base, address quote) external view returns (int256 answer);

  function latestTimestamp(address base, address quote) external view returns (uint256 timestamp);

  function latestRound(address base, address quote) external view returns (uint256 roundId);

  function getAnswer(
    address base,
    address quote,
    uint256 roundId
  ) external view returns (int256 answer);

  function getTimestamp(
    address base,
    address quote,
    uint256 roundId
  ) external view returns (uint256 timestamp);

  // Registry getters

  function getFeed(address base, address quote) external view returns (AggregatorV2V3Interface aggregator);

  function getPhaseFeed(
    address base,
    address quote,
    uint16 phaseId
  ) external view returns (AggregatorV2V3Interface aggregator);

  function isFeedEnabled(address aggregator) external view returns (bool);

  function getPhase(
    address base,
    address quote,
    uint16 phaseId
  ) external view returns (Phase memory phase);

  // Round helpers

  function getRoundFeed(
    address base,
    address quote,
    uint80 roundId
  ) external view returns (AggregatorV2V3Interface aggregator);

  function getPhaseRange(
    address base,
    address quote,
    uint16 phaseId
  ) external view returns (uint80 startingRoundId, uint80 endingRoundId);

  function getPreviousRoundId(
    address base,
    address quote,
    uint80 roundId
  ) external view returns (uint80 previousRoundId);

  function getNextRoundId(
    address base,
    address quote,
    uint80 roundId
  ) external view returns (uint80 nextRoundId);

  // Feed management

  function proposeFeed(
    address base,
    address quote,
    address aggregator
  ) external;

  function confirmFeed(
    address base,
    address quote,
    address aggregator
  ) external;

  // Proposed aggregator

  function getProposedFeed(address base, address quote)
    external
    view
    returns (AggregatorV2V3Interface proposedAggregator);

  function proposedGetRoundData(
    address base,
    address quote,
    uint80 roundId
  )
    external
    view
    returns (
      uint80 id,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function proposedLatestRoundData(address base, address quote)
    external
    view
    returns (
      uint80 id,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  // Phases
  function getCurrentPhaseId(address base, address quote) external view returns (uint16 currentPhaseId);
}

File 23 of 34 : AggregatorV2V3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./AggregatorInterface.sol";
import "./AggregatorV3Interface.sol";

interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}

File 24 of 34 : IChainlinkAggregator.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";

interface IChainlinkAggregator is AggregatorV2V3Interface {
    function maxAnswer() external view returns (int192);

    function minAnswer() external view returns (int192);
}

File 25 of 34 : Denominations.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

library Denominations {
  address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
  address public constant BTC = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;

  // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217
  address public constant USD = address(840);
  address public constant GBP = address(826);
  address public constant EUR = address(978);
  address public constant JPY = address(392);
  address public constant KRW = address(410);
  address public constant CNY = address(156);
  address public constant AUD = address(36);
  address public constant CAD = address(124);
  address public constant CHF = address(756);
  address public constant ARS = address(32);
  address public constant PHP = address(608);
  address public constant NZD = address(554);
  address public constant SGD = address(702);
  address public constant NGN = address(566);
  address public constant ZAR = address(710);
  address public constant RUB = address(643);
  address public constant INR = address(356);
  address public constant BRL = address(986);
}

File 26 of 34 : draft-IERC20Permit.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 IERC20Permit {
    /**
     * @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 27 of 34 : draft-EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }
}

File 28 of 34 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 29 of 34 : Counters.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 30 of 34 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 31 of 34 : IMulticall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;

/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
// From: https://github.com/Uniswap/v3-periphery/contracts/interfaces/IMulticall.sol
interface IMulticall {
    /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
    /// @dev The `msg.value` should not be trusted for any method callable from multicall.
    /// @param data The encoded function data for each of the calls to make to this contract
    /// @return results The results from each of the calls passed in via data
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

File 32 of 34 : AggregatorInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorInterface {
  function latestAnswer() external view returns (int256);

  function latestTimestamp() external view returns (uint256);

  function latestRound() external view returns (uint256);

  function getAnswer(uint256 roundId) external view returns (int256);

  function getTimestamp(uint256 roundId) external view returns (uint256);

  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt);

  event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
}

File 33 of 34 : 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);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  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 34 of 34 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

Settings
{
  "remappings": [
    "@chainlink/=lib/chainlink/",
    "@ds-test/=lib/forge-std/lib/ds-test/src/",
    "@forge-std/=lib/forge-std/src/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@solmate/=lib/solmate/src/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "chainlink/=lib/chainlink/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solmate/=lib/solmate/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract Registry","name":"_registry","type":"address"},{"internalType":"contract ERC20","name":"_asset","type":"address"},{"internalType":"address[]","name":"_positions","type":"address[]"},{"internalType":"enum Cellar.PositionType[]","name":"_positionTypes","type":"uint8[]"},{"internalType":"address","name":"_holdingPosition","type":"address"},{"internalType":"enum Cellar.WithdrawType","name":"_withdrawType","type":"uint8"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_strategistPayout","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"expectedAsset","type":"address"}],"name":"Cellar__AssetMismatch","type":"error"},{"inputs":[],"name":"Cellar__ContractNotShutdown","type":"error"},{"inputs":[],"name":"Cellar__ContractShutdown","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"maxDeposit","type":"uint256"}],"name":"Cellar__DepositRestricted","type":"error"},{"inputs":[{"internalType":"address","name":"illiquidPosition","type":"address"}],"name":"Cellar__IlliquidWithdraw","type":"error"},{"inputs":[{"internalType":"uint256","name":"assetsOwed","type":"uint256"}],"name":"Cellar__IncompleteWithdraw","type":"error"},{"inputs":[],"name":"Cellar__InvalidCosmosAddress","type":"error"},{"inputs":[],"name":"Cellar__InvalidFee","type":"error"},{"inputs":[],"name":"Cellar__InvalidFeeCut","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__InvalidPosition","type":"error"},{"inputs":[{"internalType":"uint256","name":"requested","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"Cellar__InvalidRebalanceDeviation","type":"error"},{"inputs":[],"name":"Cellar__InvalidShareLockPeriod","type":"error"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"}],"name":"Cellar__NotApprovedToDepositOnBehalf","type":"error"},{"inputs":[],"name":"Cellar__PayoutNotSet","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__PositionAlreadyUsed","type":"error"},{"inputs":[{"internalType":"uint256","name":"maxPositions","type":"uint256"}],"name":"Cellar__PositionArrayFull","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"},{"internalType":"uint256","name":"sharesRemaining","type":"uint256"}],"name":"Cellar__PositionNotEmpty","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__PositionPricingNotSetUp","type":"error"},{"inputs":[],"name":"Cellar__RemoveHoldingPosition","type":"error"},{"inputs":[{"internalType":"uint256","name":"blockSharesAreUnlocked","type":"uint256"},{"internalType":"uint256","name":"currentBlock","type":"uint256"}],"name":"Cellar__SharesAreLocked","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"Cellar__TotalAssetDeviatedOutsideRange","type":"error"},{"inputs":[{"internalType":"uint256","name":"current","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"Cellar__TotalSharesMustRemainConstant","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__UntrustedPosition","type":"error"},{"inputs":[],"name":"Cellar__WrongSwapParams","type":"error"},{"inputs":[],"name":"Cellar__ZeroAssets","type":"error"},{"inputs":[],"name":"Cellar__ZeroShares","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"DepositLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"oldFeesDistributor","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"newFeesDistributor","type":"bytes32"}],"name":"FeesDistributorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newHighWatermark","type":"uint256"}],"name":"HighWatermarkReset","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldPosition","type":"address"},{"indexed":true,"internalType":"address","name":"newPosition","type":"address"}],"name":"HoldingPositionChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"LiquidityLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPerformanceFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPerformanceFee","type":"uint64"}],"name":"PerformanceFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"PlatformFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newPosition1","type":"address"},{"indexed":true,"internalType":"address","name":"newPosition2","type":"address"},{"indexed":false,"internalType":"uint256","name":"index1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"index2","type":"uint256"}],"name":"PositionSwapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"PulledFromPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fromPosition","type":"address"},{"indexed":true,"internalType":"address","name":"toPosition","type":"address"},{"indexed":false,"internalType":"uint256","name":"assetsFrom","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assetsTo","type":"uint256"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldDeviation","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newDeviation","type":"uint256"}],"name":"RebalanceDeviationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesInSharesRedeemed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesInAssetsSent","type":"uint256"}],"name":"SendFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldPeriod","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPeriod","type":"uint256"}],"name":"ShareLockingPeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isShutdown","type":"bool"}],"name":"ShutdownChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldPayoutAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newPayoutAddress","type":"address"}],"name":"StrategistPayoutAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPerformanceCut","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPerformanceCut","type":"uint64"}],"name":"StrategistPerformanceCutChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformCut","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformCut","type":"uint64"}],"name":"StrategistPlatformCutChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"bool","name":"isTrusted","type":"bool"}],"name":"TrustChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum Cellar.WithdrawType","name":"oldType","type":"uint8"},{"indexed":false,"internalType":"enum Cellar.WithdrawType","name":"newType","type":"uint8"}],"name":"WithdrawTypeChanged","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAXIMUM_SHARE_LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE_CUT","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PERFORMANCE_FEE","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PLATFORM_FEE","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_POSITIONS","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_REBALANCE_DEVIATION","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_SHARE_LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_ROUTER_REGISTRY_SLOT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"position","type":"address"}],"name":"addPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowedRebalanceDeviation","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeData","outputs":[{"internalType":"uint256","name":"highWatermark","type":"uint256"},{"internalType":"uint64","name":"strategistPerformanceCut","type":"uint64"},{"internalType":"uint64","name":"strategistPlatformCut","type":"uint64"},{"internalType":"uint64","name":"platformFee","type":"uint64"},{"internalType":"uint64","name":"performanceFee","type":"uint64"},{"internalType":"bytes32","name":"feesDistributor","type":"bytes32"},{"internalType":"address","name":"strategistPayoutAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getPositionType","outputs":[{"internalType":"enum Cellar.PositionType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositions","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"holdingPosition","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initiateShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isPositionUsed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isTrusted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastAccrual","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liftShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidityLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positions","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"pushPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"fromPosition","type":"address"},{"internalType":"address","name":"toPosition","type":"address"},{"internalType":"uint256","name":"assetsFrom","type":"uint256"},{"internalType":"enum SwapRouter.Exchange","name":"exchange","type":"uint8"},{"internalType":"bytes","name":"params","type":"bytes"}],"name":"rebalance","outputs":[{"internalType":"uint256","name":"assetsTo","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract Registry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"removePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resetHighWatermark","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sendFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"setDepositLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newFeesDistributor","type":"bytes32"}],"name":"setFeesDistributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newHoldingPosition","type":"address"}],"name":"setHoldingPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"setLiquidityLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"newPerformanceFee","type":"uint64"}],"name":"setPerformanceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"setPlatformFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDeviation","type":"uint256"}],"name":"setRebalanceDeviation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLock","type":"uint256"}],"name":"setShareLockPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"payout","type":"address"}],"name":"setStrategistPayoutAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"cut","type":"uint64"}],"name":"setStrategistPerformanceCut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"cut","type":"uint64"}],"name":"setStrategistPlatformCut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum Cellar.WithdrawType","name":"newWithdrawType","type":"uint8"}],"name":"setWithdrawType","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shareLockPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index1","type":"uint256"},{"internalType":"uint256","name":"index2","type":"uint256"}],"name":"swapPositions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssetsWithdrawable","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"},{"internalType":"enum Cellar.PositionType","name":"positionType","type":"uint8"}],"name":"trustPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userShareLockStartBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawType","outputs":[{"internalType":"enum Cellar.WithdrawType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"}]

60016008556102606040526000610180819052670a688906bd8b00006101a08190526101c05266470de4df8200006101e05267016345785d8a00006102005273b813554b423266bbd4c16c32fa383394868c1f55610220819052610240829052600e919091557f016345785d8a000000470de4df8200000a688906bd8b00000a688906bd8b0000600f55601055601180546001600160a01b03191690556000196012819055601355611c20601555660aa87bee538000601755348015620000c557600080fd5b5060405162006d8338038062006d83833981016040819052620000e891620009a4565b604051635c9fcd8560e11b8152600060048201526001600160a01b038a169063b93f9b0a90602401602060405180830381865afa1580156200012e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000154919062000abc565b8884848180604051806040016040528060018152602001603160f81b8152508484816003908162000186919062000b65565b50600462000195828262000b65565b5050825160208085019190912083518483012060e08290526101008190524660a0818152604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81880181905281830187905260608201869052608082019490945230818401528151808203909301835260c0019052805194019390932091935091906080523060c05261012052505050506001600160a01b03938416610140525050600780546001600160a01b0319169284169283179055506040516000907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506001600160a01b038916610160528651620002a09060099060208a0190620006fd565b506000805b8851811015620004e6576000898281518110620002c657620002c662000c31565b6020908102919091018101516001600160a01b0381166000908152600a90925260409091205490915060ff16156200032157604051630af67d9160e31b81526001600160a01b03821660048201526024015b60405180910390fd5b6001600160a01b0381166000908152600c602090815260408083208054600160ff199182168117909255600a909352922080549091169091179055885189908390811062000373576200037362000c31565b6020908102919091018101516001600160a01b0383166000908152600b9092526040909120805460ff19166001836002811115620003b557620003b562000c47565b0217905550620003c5816200062a565b61016051604051635c9fcd8560e11b8152600260048201529194506001600160a01b03169063b93f9b0a90602401602060405180830381865afa15801562000411573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000437919062000abc565b604051634f129c5360e01b81526001600160a01b0385811660048301529190911690634f129c5390602401602060405180830381865afa15801562000480573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620004a6919062000c5d565b620004d057604051637eb56edb60e11b81526001600160a01b038416600482015260240162000318565b5080620004dd8162000c81565b915050620002a5565b506001600160a01b0386166000908152600a602052604090205460ff166200052d57604051631ec7bcd360e01b81526001600160a01b038716600482015260240162000318565b60006200053a876200062a565b9050896001600160a01b0316816001600160a01b031614620005835760405163298473c760e11b81526001600160a01b0380831660048301528b16602482015260440162000318565b600d8054610100600160a81b031981166101006001600160a01b038b160290811783558892916001600160a81b03191660ff199091161760018381811115620005d057620005d062000c47565b021790555050600d8054600160a81b600160e81b031916600160a81b426001600160401b03160217905550601180546001600160a01b0319166001600160a01b03929092169190911790555062000ca99650505050505050565b6001600160a01b0381166000908152600b602052604081205460ff1660018160028111156200065d576200065d62000c47565b14806200067e575060028160028111156200067c576200067c62000c47565b145b15620006f057826001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620006c3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006e9919062000abc565b9392505050565b5090919050565b50919050565b82805482825590600052602060002090810192821562000755579160200282015b828111156200075557825182546001600160a01b0319166001600160a01b039091161782556020909201916001909101906200071e565b506200076392915062000767565b5090565b5b8082111562000763576000815560010162000768565b6001600160a01b03811681146200079457600080fd5b50565b8051620007a4816200077e565b919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715620007ea57620007ea620007a9565b604052919050565b60006001600160401b038211156200080e576200080e620007a9565b5060051b60200190565b600082601f8301126200082a57600080fd5b81516020620008436200083d83620007f2565b620007bf565b82815260059290921b840181019181810190868411156200086357600080fd5b8286015b848110156200088b5780516200087d816200077e565b835291830191830162000867565b509695505050505050565b600082601f830112620008a857600080fd5b81516020620008bb6200083d83620007f2565b82815260059290921b84018101918181019086841115620008db57600080fd5b8286015b848110156200088b57805160038110620008f95760008081fd5b8352918301918301620008df565b805160028110620007a457600080fd5b600082601f8301126200092957600080fd5b81516001600160401b03811115620009455762000945620007a9565b60206200095b601f8301601f19168201620007bf565b82815285828487010111156200097057600080fd5b60005b838110156200099057858101830151828201840152820162000973565b506000928101909101919091529392505050565b60008060008060008060008060006101208a8c031215620009c457600080fd5b620009cf8a62000797565b9850620009df60208b0162000797565b60408b01519098506001600160401b0380821115620009fd57600080fd5b62000a0b8d838e0162000818565b985060608c015191508082111562000a2257600080fd5b62000a308d838e0162000896565b975062000a4060808d0162000797565b965062000a5060a08d0162000907565b955060c08c015191508082111562000a6757600080fd5b62000a758d838e0162000917565b945060e08c015191508082111562000a8c57600080fd5b5062000a9b8c828d0162000917565b92505062000aad6101008b0162000797565b90509295985092959850929598565b60006020828403121562000acf57600080fd5b8151620006e9816200077e565b600181811c9082168062000af157607f821691505b602082108103620006f757634e487b7160e01b600052602260045260246000fd5b601f82111562000b6057600081815260208120601f850160051c8101602086101562000b3b5750805b601f850160051c820191505b8181101562000b5c5782815560010162000b47565b5050505b505050565b81516001600160401b0381111562000b815762000b81620007a9565b62000b998162000b92845462000adc565b8462000b12565b602080601f83116001811462000bd1576000841562000bb85750858301515b600019600386901b1c1916600185901b17855562000b5c565b600085815260208120601f198616915b8281101562000c025788860151825594840194600190910190840162000be1565b508582101562000c215787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b60006020828403121562000c7057600080fd5b81518015158114620006e957600080fd5b60006001820162000ca257634e487b7160e01b600052601160045260246000fd5b5060010190565b60805160a05160c05160e05161010051610120516101405161016051615ff662000d8d6000396000818161071b01528181610c5a01528181612b4c01528181612d9301528181613a7b01528181613fe001528181614581015261496801526000818161058301528181610cf8015281816118d501528181611bca01528181611c2001528181611d3801528181612bce01528181612c0f015281816132b0015281816134e60152818161461f0152614ac20152600061384c0152600061389b01526000613876015260006137cf015260006137f9015260006138230152615ff66000f3fe608060405234801561001057600080fd5b50600436106104745760003560e01c806394bf804d11610257578063c046742211610146578063dff90b5b116100c3578063ef8b30f711610087578063ef8b30f714610aa3578063f7b24e0814610ab6578063fc44459114610abe578063fc4d43be14610ade578063fdd230b914610af157600080fd5b8063dff90b5b146109d2578063e39448e0146109da578063e753e600146109f4578063ecf7085814610a8b578063eef33eca14610a9457600080fd5b8063ce96cb771161010a578063ce96cb7714610973578063d505accf14610986578063d905777e14610999578063dd62ed3e146109ac578063df05a52a146109bf57600080fd5b8063c046742214610929578063c244245a1461093c578063c63d75b614610945578063c6e6f59214610958578063c85e5e131461096b57600080fd5b8063a8144e48116101d4578063b5292a9911610198578063b5292a99146108d4578063ba087652146108e7578063bdc8144b146108fa578063bdca91651461090d578063bf86d6901461091c57600080fd5b8063a8144e4814610880578063a9059cbb14610888578063b0a75d361461089b578063b3d7f6b9146108ae578063b460af94146108c157600080fd5b80639c552ca81161021b5780639c552ca8146108095780639c5f00c21461081c5780639e35c65b146108345780639fdb11b614610864578063a457c2d71461086d57600080fd5b806394bf804d146107a557806395d89b41146107b857806396d64879146107c057806399fbab88146107e35780639b6fd18e146107f657600080fd5b8063402d267d116103735780636ff1c02a116102f05780637b3baab4116102b45780637b3baab41461073d5780637ecebe0014610757578063802758601461076a5780638b0cebf71461077f5780638da5cb5b1461079257600080fd5b80636ff1c02a146106c257806370a08231146106d157806370af7df6146106fa578063721637151461070d5780637b1039991461071657600080fd5b8063583845731161033757806358384573146106795780635a400d251461068c5780635e2c576e146106945780636e553f651461069c5780636e85f183146106af57600080fd5b8063402d267d1461060a578063472090fe1461061d5780634cdad506146106405780634eca8a8314610653578063530a37141461066657600080fd5b806318160ddd11610401578063389a7294116103c5578063389a72941461056b57806338d52e0f1461057e57806339509351146105bd5780633998a681146105d05780633cf99a46146105f757600080fd5b806318160ddd1461052057806323b872dd146105285780632f3b5a131461053b578063313ce5671461054e5780633644e5151461056357600080fd5b806307a2d13a1161044857806307a2d13a146104ba578063095ea7b3146104cd5780630a28a477146104f05780630a680e181461050357806313af40351461050d57600080fd5b806251a3b71461047957806301e1d114146104945780630402ab631461049c57806306fdde03146104a5575b600080fd5b610481600881565b6040519081526020015b60405180910390f35b610481610b04565b610481611c2081565b6104ad610d6a565b60405161048b91906157a3565b6104816104c83660046157d6565b610dfc565b6104e06104db366004615804565b610e15565b604051901515815260200161048b565b6104816104fe3660046157d6565b610e2d565b61050b610e62565b005b61050b61051b366004615830565b610eff565b600254610481565b6104e061053636600461584d565b610f75565b61050b61054936600461589b565b610f9b565b60125b60405160ff909116815260200161048b565b61048161102c565b6104816105793660046158b8565b61103b565b6105a57f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161048b565b6104e06105cb366004615804565b6112ab565b6105df6702c68af0bb14000081565b6040516001600160401b03909116815260200161048b565b61050b61060536600461596a565b6112cd565b610481610618366004615830565b61139f565b6104e061062b366004615830565b600a6020526000908152604090205460ff1681565b61048161064e3660046157d6565b611447565b61050b610661366004615993565b61146f565b61050b6106743660046157d6565b6115d9565b61050b6106873660046159c3565b611683565b610481600281565b61050b6117ca565b6104816106aa366004615993565b611852565b61050b6106bd3660046157d6565b611964565b6105df67016345785d8a000081565b6104816106df366004615830565b6001600160a01b031660009081526020819052604090205490565b61050b61070836600461596a565b6119f7565b61048160125481565b6105a57f000000000000000000000000000000000000000000000000000000000000000081565b600d546105df90600160a81b90046001600160401b031681565b610481610765366004615830565b611ace565b610772611aec565b60405161048b91906159e5565b61050b61078d366004615830565b611b4d565b6007546105a5906001600160a01b031681565b6104816107b3366004615993565b611cb5565b6104ad611dbb565b6104e06107ce366004615830565b600c6020526000908152604090205460ff1681565b6105a56107f13660046157d6565b611dca565b61050b61080436600461596a565b611df4565b61050b6108173660046157d6565b611eba565b600d546105a59061010090046001600160a01b031681565b610857610842366004615830565b600b6020526000908152604090205460ff1681565b60405161048b9190615a48565b61048160155481565b6104e061087b366004615804565b611f50565b610481611fd6565b6104e0610896366004615804565b612112565b61050b6108a9366004615830565b612120565b6104816108bc3660046157d6565b6121b3565b6104816108cf366004615a62565b6121e0565b61050b6108e236600461596a565b612300565b6104816108f5366004615a62565b6123dc565b61050b6109083660046157d6565b612505565b6105df6706f05b59d3b2000081565b6014546104e09060ff1681565b61050b6109373660046157d6565b612570565b61048160175481565b610481610953366004615830565b61269f565b6104816109663660046157d6565b6126c4565b61050b6126d7565b610481610981366004615830565b612749565b61050b610994366004615ab3565b612756565b6104816109a7366004615830565b6128ba565b6104816109ba366004615b24565b6128c7565b61050b6109cd3660046157d6565b6128f2565b61050b61295d565b600d546109e79060ff1681565b60405161048b9190615b62565b600e54600f54601054601154610a3c93926001600160401b0380821693600160401b8304821693600160801b8404831693600160c01b9004909216916001600160a01b031687565b604080519788526001600160401b039687166020890152948616948701949094529184166060860152909216608084015260a08301919091526001600160a01b031660c082015260e00161048b565b61048160135481565b6105df670de0b6b3a764000081565b610481610ab13660046157d6565b612ccd565b610551602081565b610481610acc366004615830565b60166020526000908152604090205481565b61050b610aec366004615b6f565b612cf5565b61050b610aff366004615830565b612ed6565b60095460009081816001600160401b03811115610b2357610b23615ba1565b604051908082528060200260200182016040528015610b4c578160200160208202803683370190505b5090506000826001600160401b03811115610b6957610b69615ba1565b604051908082528060200260200182016040528015610b92578160200160208202803683370190505b50905060005b83811015610c4057600060098281548110610bb557610bb5615bb7565b6000918252602090912001546001600160a01b03169050610bd581613077565b848381518110610be757610be7615bb7565b60200260200101906001600160a01b031690816001600160a01b031681525050610c1081613138565b838381518110610c2257610c22615bb7565b60209081029190910101525080610c3881615be3565b915050610b98565b50604051635c9fcd8560e11b8152600260048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015610ca9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ccd9190615bfc565b60405163b333a17560e01b81529091506001600160a01b0382169063b333a17590610d2090869086907f000000000000000000000000000000000000000000000000000000000000000090600401615c19565b602060405180830381865afa158015610d3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d619190615cab565b94505050505090565b606060038054610d7990615cc4565b80601f0160208091040260200160405190810160405280929190818152602001828054610da590615cc4565b8015610df25780601f10610dc757610100808354040283529160200191610df2565b820191906000526020600020905b815481529060010190602001808311610dd557829003601f168201915b5050505050905090565b6000610e0f82610e0a610b04565b613285565b92915050565b600033610e23818585613338565b5060019392505050565b600080610e38610b04565b90506000610e458261345c565b9050610e5a84610e558385615cf8565b6134c2565b949350505050565b60145460ff1615610e86576040516337a5332d60e11b815260040160405180910390fd5b6007546001600160a01b03163314610eb95760405162461bcd60e51b8152600401610eb090615d0b565b60405180910390fd5b6014805460ff191660019081179091556040519081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c906020015b60405180910390a1565b6007546001600160a01b03163314610f295760405162461bcd60e51b8152600401610eb090615d0b565b600780546001600160a01b0319166001600160a01b03831690811790915560405133907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d7690600090a350565b600033610f8385828561356f565b610f8e8585856135e9565b60019150505b9392505050565b6007546001600160a01b03163314610fc55760405162461bcd60e51b8152600401610eb090615d0b565b600d546040517f19365927bf52f7e956d376b3546402dda3827c062c7a6942431a255d212947e891610ffe9160ff909116908490615d31565b60405180910390a1600d805482919060ff19166001838181111561102457611024615a32565b021790555050565b60006110366137c2565b905090565b6007546000906001600160a01b031633146110685760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff161561108c576040516337a5332d60e11b815260040160405180910390fd5b6008546001146110ae5760405162461bcd60e51b8152600401610eb090615d57565b60026008556001600160a01b0386166000908152600a602052604090205460ff166110f757604051631ec7bcd360e01b81526001600160a01b0387166004820152602401610eb0565b6000611101610b04565b9050600061110e60025490565b905061111b8988306138e9565b60006111268a613077565b905060006111338a613077565b9050806001600160a01b0316826001600160a01b0316036111545788611163565b61116382828b8b8b8b306139de565b945061116f8a86613c0d565b600061119a601754670de0b6b3a764000061118a9190615cf8565b8690670de0b6b3a7640000613d4c565b905060006111c7601754670de0b6b3a76400006111b79190615d7b565b8790670de0b6b3a7640000613d7a565b90506111d1610b04565b9550808611806111e057508186105b1561120f5760405163628cc47560e11b8152600481018790526024810183905260448101829052606401610eb0565b600254851461123f57600254604051632b40145960e21b8152600481019190915260248101869052604401610eb0565b8b6001600160a01b03168d6001600160a01b03167ffea7a9a6e25cd0bbbfa80ce0c7646e61ee5e0551b3fdaaff0642e6f6adcc72e28d8a60405161128d929190918252602082015260400190565b60405180910390a35050600160085550929998505050505050505050565b600033610e238185856112be83836128c7565b6112c89190615d7b565b613338565b6007546001600160a01b031633146112f75760405162461bcd60e51b8152600401610eb090615d0b565b6706f05b59d3b200006001600160401b038216111561132957604051632e15286d60e11b815260040160405180910390fd5b600f5460408051600160c01b9092046001600160401b039081168352831660208301527f27dd3ae8ff7f5e3d77ae68ed36dc780d2ab40a4ffdda18d805cb41eea39c2894910160405180910390a1600f80546001600160401b03909216600160c01b026001600160c01b03909216919091179055565b60145460009060ff16156113b557506000919050565b601354601254600019821480156113cd575060001981145b156113dd57506000199392505050565b60006113e7610b04565b9050600061141361140d876001600160a01b031660009081526020819052604090205490565b83613285565b905060006114218583613d99565b9050600061142f8585613d99565b905061143b8282613db3565b98975050505050505050565b600080611452610b04565b9050600061145f8261345c565b9050610e5a84610e0a8385615cf8565b6007546001600160a01b031633146114995760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff16156114bd576040516337a5332d60e11b815260040160405180910390fd5b6009546020116114e35760405163f025236d60e01b815260206004820152602401610eb0565b6001600160a01b0381166000908152600c602052604090205460ff166115275760405163699f66b160e11b81526001600160a01b0382166004820152602401610eb0565b6001600160a01b0381166000908152600a602052604090205460ff161561156c57604051630af67d9160e31b81526001600160a01b0382166004820152602401610eb0565b61157860098383613dc2565b6001600160a01b0381166000818152600a602052604090819020805460ff19166001179055517fcff5c8a08884d2fad939a9e0f0bf729a4f9af6111a573b4d1f11396c8711646d906115cd9085815260200190565b60405180910390a25050565b6007546001600160a01b031633146116035760405162461bcd60e51b8152600401610eb090615d0b565b67016345785d8a000081111561163d576040516302d2a90f60e51b81526004810182905267016345785d8a00006024820152604401610eb0565b601780549082905560408051828152602081018490527fdf4be33b2e9e3dd4d9e0e85645aea428494a0644a72c51d6a15aedae6b66a3ff91015b60405180910390a15050565b6007546001600160a01b031633146116ad5760405162461bcd60e51b8152600401610eb090615d0b565b6000600982815481106116c2576116c2615bb7565b6000918252602082200154600980546001600160a01b03909216935090859081106116ef576116ef615bb7565b9060005260206000200160009054906101000a90046001600160a01b0316905081816009868154811061172457611724615bb7565b9060005260206000200160006009878154811061174357611743615bb7565b60009182526020918290200180546001600160a01b039586166001600160a01b031990911617905582549484166101009290920a918202918402199094161790556040805187815292830186905283821692918516917f3cae4f5796f9d19fa1dcfaacae5a9811c008f6f517a3ec689d903d6f699e4955910160405180910390a350505050565b6007546001600160a01b031633146117f45760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff166118175760405163ec7165bf60e01b815260040160405180910390fd5b6014805460ff19169055604051600081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c90602001610ef5565b60006008546001146118765760405162461bcd60e51b8152600401610eb090615d57565b60026008556000611885610b04565b905061189081613f3b565b61189a8482613f78565b9150816000036118bd5760405163426f153760e11b815260040160405180910390fd5b6118c8848385613f97565b6118fd6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163330876140ca565b6119078383614135565b60408051858152602081018490526001600160a01b0385169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a3611958848385614220565b50600160085592915050565b6007546001600160a01b0316331461198e5760405162461bcd60e51b8152600401610eb090615d0b565b6001600160a01b038111156119b65760405163019b5e3160e21b815260040160405180910390fd5b60105460408051918252602082018390527f513ac19cbbaaad4e450c732ed37635178b7d83bf8e84a940ffe7e052c9c7caa2910160405180910390a1601055565b6007546001600160a01b03163314611a215760405162461bcd60e51b8152600401610eb090615d0b565b6702c68af0bb1400006001600160401b0382161115611a5357604051632e15286d60e11b815260040160405180910390fd5b600f5460408051600160801b9092046001600160401b039081168352831660208301527f44ada261ff5c9aacbf8d0687294799c8e3e0810ecc1eafd97419dfc31db5d523910160405180910390a1600f80546001600160401b03909216600160801b0267ffffffffffffffff60801b19909216919091179055565b6001600160a01b038116600090815260056020526040812054610e0f565b60606009805480602002602001604051908101604052809291908181526020018280548015610df257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611b26575050505050905090565b6007546001600160a01b03163314611b775760405162461bcd60e51b8152600401610eb090615d0b565b6001600160a01b0381166000908152600a602052604090205460ff16611bbb57604051631ec7bcd360e01b81526001600160a01b0382166004820152602401610eb0565b6000611bc682613077565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b031614611c4d5760405163298473c760e11b81526001600160a01b0380831660048301527f0000000000000000000000000000000000000000000000000000000000000000166024820152604401610eb0565b600d546040516001600160a01b0380851692610100900416907f7f835fbf43c4d05a9c4ea5cafa09fbb3b0307d12956ceedce43fd7a339e5046e90600090a350600d80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000600854600114611cd95760405162461bcd60e51b8152600401610eb090615d57565b60026008556000611ce8610b04565b9050611cf381613f3b565b611cfd8482614259565b915081600003611d2057604051639768300560e01b815260040160405180910390fd5b611d2b828585613f97565b611d606001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163330856140ca565b611d6a8385614135565b60408051838152602081018690526001600160a01b0385169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a3611958828585614220565b606060048054610d7990615cc4565b60098181548110611dda57600080fd5b6000918252602090912001546001600160a01b0316905081565b6007546001600160a01b03163314611e1e5760405162461bcd60e51b8152600401610eb090615d0b565b670de0b6b3a76400006001600160401b0382161115611e5057604051633d0203e560e01b815260040160405180910390fd5b600f54604080516001600160401b03928316815291831660208301527fc79399093f73f1ff8c2f8279aa9e8803b694c60016c344ecfc2a89fd77c004db910160405180910390a1600f805467ffffffffffffffff19166001600160401b0392909216919091179055565b6007546001600160a01b03163314611ee45760405162461bcd60e51b8152600401610eb090615d0b565b6008811080611ef45750611c2081115b15611f1257604051633a60233f60e21b815260040160405180910390fd5b601580549082905560408051828152602081018490527f227ff5c6b5ffb395236b09fd1b472bb128b36eaa17556633feefe28e94411f249101611677565b60003381611f5e82866128c7565b905083811015611fbe5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610eb0565b611fcb8286868403613338565b506001949350505050565b60095460009081816001600160401b03811115611ff557611ff5615ba1565b60405190808252806020026020018201604052801561201e578160200160208202803683370190505b5090506000826001600160401b0381111561203b5761203b615ba1565b604051908082528060200260200182016040528015612064578160200160208202803683370190505b50905060005b83811015610c405760006009828154811061208757612087615bb7565b6000918252602090912001546001600160a01b031690506120a781613077565b8483815181106120b9576120b9615bb7565b60200260200101906001600160a01b031690816001600160a01b0316815250506120e281614278565b8383815181106120f4576120f4615bb7565b6020908102919091010152508061210a81615be3565b91505061206a565b600033610e238185856135e9565b6007546001600160a01b0316331461214a5760405162461bcd60e51b8152600401610eb090615d0b565b601154604080516001600160a01b03928316815291831660208301527f51dbb5a65bb22737861a63ec12ba6ce78a98631e9404b0567a2eaf7a06fc544d910160405180910390a1601180546001600160a01b0319166001600160a01b0392909216919091179055565b6000806121be610b04565b905060006121cb8261345c565b9050610e5a846121db8385615cf8565b614259565b60006008546001146122045760405162461bcd60e51b8152600401610eb090615d57565b60026008556000808080806122176142f6565b9450945094509450945061222a85613f3b565b61223489866134c2565b955061224289878a8a614693565b61224c87876146c2565b600061225760025490565b905061226388886146dd565b604080518b8152602081018990526001600160a01b03808b1692908c169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a46000600d5460ff1660018111156122c7576122c7615a32565b146122df576122da87828b888787614837565b6122ed565b6122ed8a8a8787878761494f565b5050600160085550929695505050505050565b6007546001600160a01b0316331461232a5760405162461bcd60e51b8152600401610eb090615d0b565b670de0b6b3a76400006001600160401b038216111561235c57604051633d0203e560e01b815260040160405180910390fd5b600f5460408051600160401b9092046001600160401b039081168352831660208301527fb5cc994a260a85a42d6588668221571ae0a14f0a28f9e4817a5195262102c868910160405180910390a1600f80546001600160401b03909216600160401b026fffffffffffffffff000000000000000019909216919091179055565b60006008546001146124005760405162461bcd60e51b8152600401610eb090615d57565b60026008556000808080806124136142f6565b9450945094509450945061242685613f3b565b612430878a6146c2565b61243a8986613285565b95508560000361245d57604051639768300560e01b815260040160405180910390fd5b612469868a8a8a614693565b600061247460025490565b9050612480888b6146dd565b60408051888152602081018c90526001600160a01b03808b1692908c169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a46000600d5460ff1660018111156124e4576124e4615a32565b146124f7576122da8a828b888787614837565b6122da878a8787878761494f565b6007546001600160a01b0316331461252f5760405162461bcd60e51b8152600401610eb090615d0b565b60135460408051918252602082018390527fcfb5a454b8aa7dc04ecb5bc1410b2a57969ca1d67f66d565196f60c6f9975404910160405180910390a1601355565b6007546001600160a01b0316331461259a5760405162461bcd60e51b8152600401610eb090615d0b565b6000600982815481106125af576125af615bb7565b60009182526020822001546001600160a01b031691506125ce82613138565b9050801561260157604051638454689f60e01b81526001600160a01b038316600482015260248101829052604401610eb0565b600d546001600160a01b036101009091048116908316036126355760405163747795ff60e11b815260040160405180910390fd5b612640600984614c9e565b6001600160a01b0382166000818152600a602052604090819020805460ff19169055517f03c78e4e20a72b1f577a63b54524c684ce73d2e414970ee606bb0b7a9004aa9c906126929086815260200190565b60405180910390a2505050565b6000806126ab8361139f565b90506000198114610e0f576126bf816126c4565b610f94565b6000610e0f826126d2610b04565b613f78565b6007546001600160a01b031633146127015760405162461bcd60e51b8152600401610eb090615d0b565b600061270b610b04565b600e8190556040518181529091507f875561ddc342b12981103d85be8db6375a88982d4cf58d411e38715ae46833309060200160405180910390a150565b6000610e0f826000614db8565b834211156127a65760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610eb0565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886127d58c615001565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050600061283082615027565b9050600061284082878787615075565b9050896001600160a01b0316816001600160a01b0316146128a35760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610eb0565b6128ae8a8a8a613338565b50505050505050505050565b6000610e0f826001614db8565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6007546001600160a01b0316331461291c5760405162461bcd60e51b8152600401610eb090615d0b565b60125460408051918252602082018390527f1f21432dd7b8ead64d2e7c06a74baf13783b2d2f7153f099e2c4cabc3c5dbec6910160405180910390a1601255565b60085460011461297f5760405162461bcd60e51b8152600401610eb090615d57565b60026008556011546001600160a01b0316806129ae5760405163dc13611360e01b815260040160405180910390fd5b60006129b8610b04565b90506129c381613f3b565b30600090815260208190526040812054600f549091906129ed9083906001600160401b031661509d565b600d54909150600090612a1090600160a81b90046001600160401b031642615cf8565b600f549091506000906301e1338090670de0b6b3a764000090600160801b90046001600160401b0316612a438589615d8e565b612a4d9190615d8e565b612a579190615dad565b612a619190615dad565b90506000612a77612a728388613f78565b6150b2565b9050612a833082614135565b612a8d8186615d7b565b600f54909550612aae908290600160401b90046001600160401b031661509d565b612ab89085615d7b565b93508315612ad857612acb3088866135e9565b612ad58486615cf8565b94505b600d805467ffffffffffffffff60a81b19164263ffffffff16600160a81b021790556000612b068688613285565b90508015612c855780600e6000016000828254612b239190615cf8565b90915550612b33905030876146dd565b604051635c9fcd8560e11b8152600060048201819052907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612b9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bbf9190615bfc565b9050612bf56001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001682846150e1565b601054604051631ffbe7f960e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260248201929092526044810184905290821690631ffbe7f990606401600060405180830381600087803b158015612c6b57600080fd5b505af1158015612c7f573d6000803e3d6000fd5b50505050505b60408051878152602081018390527f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea6910160405180910390a150506001600855505050505050565b600080612cd8610b04565b90506000612ce58261345c565b9050610e5a846126d28385615cf8565b6007546001600160a01b03163314612d1f5760405162461bcd60e51b8152600401610eb090615d0b565b6001600160a01b0382166000908152600c602090815260408083208054600160ff199182168117909255600b90935292208054849391921690836002811115612d6a57612d6a615a32565b02179055506000612d7a83613077565b604051635c9fcd8560e11b8152600260048201529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612de2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e069190615bfc565b604051634f129c5360e01b81526001600160a01b0383811660048301529190911690634f129c5390602401602060405180830381865afa158015612e4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e729190615dcf565b612e9a57604051637eb56edb60e11b81526001600160a01b0382166004820152602401610eb0565b604051600181526001600160a01b038416907fd600b9348603c6deff34b4e0b28b60e1c8036c806741b9e6d90032e7f37dd27f90602001612692565b6007546001600160a01b03163314612f005760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff1615612f24576040516337a5332d60e11b815260040160405180910390fd5b600954602011612f4a5760405163f025236d60e01b815260206004820152602401610eb0565b6001600160a01b0381166000908152600c602052604090205460ff16612f8e5760405163699f66b160e11b81526001600160a01b0382166004820152602401610eb0565b6001600160a01b0381166000908152600a602052604090205460ff1615612fd357604051630af67d9160e31b81526001600160a01b0382166004820152602401610eb0565b60098054600180820183557f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af90910180546001600160a01b0319166001600160a01b0385169081179091556000818152600a60205260409020805460ff19168317905591547fcff5c8a08884d2fad939a9e0f0bf729a4f9af6111a573b4d1f11396c8711646d9161306391615cf8565b60405190815260200160405180910390a250565b6001600160a01b0381166000908152600b602052604081205460ff1660018160028111156130a7576130a7615a32565b14806130c4575060028160028111156130c2576130c2615a32565b145b1561312b57826001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613107573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f949190615bfc565b5090919050565b50919050565b6001600160a01b0381166000908152600b602052604081205460ff16600181600281111561316857613168615a32565b14806131855750600281600281111561318357613183615a32565b145b15613259576040516370a0823160e01b81523060048201526001600160a01b03841690634cdad5069082906370a0823190602401602060405180830381865afa1580156131d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131fa9190615cab565b6040518263ffffffff1660e01b815260040161321891815260200190565b602060405180830381865afa158015613235573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f949190615cab565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401613218565b60008061329160025490565b905080156132a9576132a4848483613d7a565b610e5a565b610e5a60127f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561330c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133309190615df1565b8691906151f6565b6001600160a01b03831661339a5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610eb0565b6001600160a01b0382166133fb5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610eb0565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600f54600090600160c01b90046001600160401b031680158061347d575082155b1561348b5750600092915050565b600e54808411156134bb5760006134a28286615cf8565b90506134b7816001600160401b03851661509d565b9350505b5050919050565b6000806134ce60025490565b905080156134e1576132a4848285613d4c565b610e5a7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613542573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135669190615df1565b859060126151f6565b600061357b84846128c7565b905060001981146135e357818110156135d65760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610eb0565b6135e38484848403613338565b50505050565b6001600160a01b03831661364d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610eb0565b6001600160a01b0382166136af5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610eb0565b6136ba83838361525f565b6001600160a01b038316600090815260208190526040902054818110156137325760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610eb0565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290613769908490615d7b565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516137b591815260200190565b60405180910390a36135e3565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561381b57507f000000000000000000000000000000000000000000000000000000000000000046145b1561384557507f000000000000000000000000000000000000000000000000000000000000000090565b50604080517f00000000000000000000000000000000000000000000000000000000000000006020808301919091527f0000000000000000000000000000000000000000000000000000000000000000828401527f000000000000000000000000000000000000000000000000000000000000000060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6001600160a01b0383166000908152600b602052604090205460ff16600181600281111561391957613919615a32565b14806139365750600281600281111561393457613934615a32565b145b156139ba57604051632d182be560e21b8152600481018490526001600160a01b03838116602483015230604483015285169063b460af94906064016020604051808303816000875af1158015613990573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139b49190615cab565b506135e3565b6001600160a01b03821630146135e3576135e36001600160a01b0385168385615268565b6040516370a0823160e01b8152306004820152600090819087906001600160a01b038b16906370a0823190602401602060405180830381865afa158015613a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a4d9190615cab565b613a579190615cf8565b604051635c9fcd8560e11b8152600160048201529091506000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063b93f9b0a90602401602060405180830381865afa158015613ac2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ae69190615bfc565b9050613afc6001600160a01b038b16828a6150e1565b806001600160a01b0316632dfe1690888888888f8f6040518763ffffffff1660e01b8152600401613b3296959493929190615e0e565b6020604051808303816000875af1158015613b51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b759190615cab565b6040516370a0823160e01b815230600482015290935082906001600160a01b038c16906370a0823190602401602060405180830381865afa158015613bbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613be29190615cab565b14613c0057604051630a9213b560e21b815260040160405180910390fd5b5050979650505050505050565b6001600160a01b0382166000908152600b602052604090205460ff166001816002811115613c3d57613c3d615a32565b1480613c5a57506002816002811115613c5857613c58615a32565b145b15613d4757613cd68383856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ca2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cc69190615bfc565b6001600160a01b031691906150e1565b604051636e553f6560e01b8152600481018390523060248201526001600160a01b03841690636e553f65906044016020604051808303816000875af1158015613d23573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135e39190615cab565b505050565b828202811515841585830485141716613d6457600080fd5b6001826001830304018115150290509392505050565b828202811515841585830485141716613d9257600080fd5b0492915050565b6000818311613da9576000610f94565b610f948284615cf8565b600081831061312b5781610f94565b82548015613f08578380613dd7600184615cf8565b81548110613de757613de7615bb7565b600091825260208083209091015483546001818101865594845291832090910180546001600160a01b0319166001600160a01b0390921691909117905590613e2f9083615cf8565b90505b83811115613ec15784613e46600183615cf8565b81548110613e5657613e56615bb7565b9060005260206000200160009054906101000a90046001600160a01b0316858281548110613e8657613e86615bb7565b600091825260209091200180546001600160a01b0319166001600160a01b039290921691909117905580613eb981615e6b565b915050613e32565b5081848481548110613ed557613ed5615bb7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506135e3565b83546001810185556000858152602090200180546001600160a01b0384166001600160a01b031990911617905550505050565b6000613f468261345c565b90508015613f74576000613f5d612a728385613f78565b90508015613d4757600e839055613d473082614135565b5050565b600080613f8460025490565b905080156134e1576132a4848285613d7a565b60145460ff1615613fbb576040516337a5332d60e11b815260040160405180910390fd5b336001600160a01b0382161461407257604051635551e1b560e01b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690635551e1b590602401602060405180830381865afa15801561402f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140539190615dcf565b614072576040516334871f2560e21b8152336004820152602401610eb0565b600061407d8261139f565b9050808411156140aa57604051632d21eb8760e21b81526004810185905260248101829052604401610eb0565b83600e60000160008282546140bf9190615d7b565b909155505050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526135e39085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152615298565b6001600160a01b03821661418b5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610eb0565b6141976000838361525f565b80600260008282546141a99190615d7b565b90915550506001600160a01b038216600090815260208190526040812080548392906141d6908490615d7b565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b600d5461423b9061010090046001600160a01b031684613c0d565b6001600160a01b031660009081526016602052604090204390555050565b60008061426560025490565b905080156132a9576132a4848483613d4c565b6001600160a01b0381166000908152600b602052604081205460ff1660018160028111156142a8576142a8615a32565b14806142c5575060028160028111156142c3576142c3615a32565b145b156132595760405163ce96cb7760e01b81523060048201526001600160a01b0384169063ce96cb7790602401613218565b600954600090606090819081908190806001600160401b0381111561431d5761431d615ba1565b604051908082528060200260200182016040528015614346578160200160208202803683370190505b509450806001600160401b0381111561436157614361615ba1565b60405190808252806020026020018201604052801561438a578160200160208202803683370190505b509350806001600160401b038111156143a5576143a5615ba1565b6040519080825280602002602001820160405280156143ce578160200160208202803683370190505b509250806001600160401b038111156143e9576143e9615ba1565b604051908082528060200260200182016040528015614412578160200160208202803683370190505b509250806001600160401b0381111561442d5761442d615ba1565b604051908082528060200260200182016040528015614456578160200160208202803683370190505b50915060005b818110156145675760006009828154811061447957614479615bb7565b9060005260206000200160009054906101000a90046001600160a01b03169050808783815181106144ac576144ac615bb7565b60200260200101906001600160a01b031690816001600160a01b0316815250506144d581613077565b8683815181106144e7576144e7615bb7565b60200260200101906001600160a01b031690816001600160a01b03168152505061451081613138565b85838151811061452257614522615bb7565b60200260200101818152505061453781614278565b84838151811061454957614549615bb7565b6020908102919091010152508061455f81615be3565b91505061445c565b50604051635c9fcd8560e11b8152600260048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156145d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145f49190615bfc565b60405163b333a17560e01b81529091506001600160a01b0382169063b333a1759061464790889088907f000000000000000000000000000000000000000000000000000000000000000090600401615c19565b602060405180830381865afa158015614664573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146889190615cab565b965050509091929394565b61469c8161536a565b600e548085116146b5576146b08582615cf8565b6146b8565b60005b600e555050505050565b336001600160a01b03831614613f7457613f7482338361356f565b6001600160a01b03821661473d5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610eb0565b6147498260008361525f565b6001600160a01b038216600090815260208190526040902054818110156147bd5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610eb0565b6001600160a01b03831660009081526020819052604081208383039055600280548492906147ec908490615cf8565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b60005b835181101561494657600084828151811061485757614857615bb7565b60200260200101519050600084838151811061487557614875615bb7565b602002602001015190508060000361488e575050614934565b600061489b828b8b613d7a565b90508484815181106148af576148af615bb7565b60200260200101518111156148e25760405163f2018f6f60e01b81526001600160a01b0384166004820152602401610eb0565b6148ed83828a6138e9565b826001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed828260405161492891815260200190565b60405180910390a25050505b8061493e81615be3565b91505061483a565b50505050505050565b604051635c9fcd8560e11b8152600260048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156149b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149db9190615bfc565b905060005b8551811015614c7b578381815181106149fb576149fb615bb7565b602002602001015160000315614c69576000858281518110614a1f57614a1f615bb7565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a889190615df1565b614a9390600a615f66565b90506000836001600160a01b031663baaa61be888581518110614ab857614ab8615bb7565b60200260200101517f00000000000000000000000000000000000000000000000000000000000000006040518363ffffffff1660e01b8152600401614b139291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa158015614b30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b549190615cab565b90506000614b868284888781518110614b6f57614b6f615bb7565b6020026020010151613d7a9092919063ffffffff16565b905060008b821115614ba857614b9d8c8585613d7a565b905060009b50614bd3565b868581518110614bba57614bba615bb7565b60200260200101519050818c614bd09190615cf8565b9b505b614bf78a8681518110614be857614be8615bb7565b6020026020010151828d6138e9565b898581518110614c0957614c09615bb7565b60200260200101516001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed8282604051614c4b91815260200190565b60405180910390a28b600003614c645750505050614c7b565b505050505b80614c7381615be3565b9150506149e0565b5086156149465760405163cc5ea39b60e01b815260048101889052602401610eb0565b8154808210614ce55760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b6044820152606401610eb0565b815b614cf2600183615cf8565b811015614d805783614d05826001615d7b565b81548110614d1557614d15615bb7565b9060005260206000200160009054906101000a90046001600160a01b0316848281548110614d4557614d45615bb7565b600091825260209091200180546001600160a01b0319166001600160a01b039290921691909117905580614d7881615be3565b915050614ce7565b5082805480614d9157614d91615f75565b600082815260209020810160001990810180546001600160a01b0319169055019055505050565b6001600160a01b0382166000908152601660205260408120548015614dfe57600060155482614de79190615d7b565b905043811115614dfc57600092505050610e0f565b505b6000614e08610b04565b90506000614e158261345c565b90506000614e45614e3b886001600160a01b031660009081526020819052604090205490565b610e0a8486615cf8565b90506000600d5460ff166001811115614e6057614e60615a32565b03614e89576000614e6f611fd6565b905080821115614e7f5780614e81565b815b955050614fe0565b600080614e946142f6565b945094505050506000614ea660025490565b90506000614ec98b6001600160a01b031660009081526020819052604090205490565b9050670de0b6b3a764000060005b8451811015614f9257858181518110614ef257614ef2615bb7565b602002602001015160000315614f8057848181518110614f1457614f14615bb7565b6020026020010151600003614f365760009a5050505050505050505050610e0f565b6000614f70670de0b6b3a7640000888481518110614f5657614f56615bb7565b6020026020010151888581518110614b6f57614b6f615bb7565b905082811015614f7e578092505b505b80614f8a81615be3565b915050614ed7565b506000614fa883670de0b6b3a764000086613d7a565b905081811115614fd557614fd082670de0b6b3a7640000614fc98b8d615cf8565b9190613d7a565b614fd7565b865b9a505050505050505b8515614ff757614ff4856126d28486615cf8565b94505b5050505092915050565b6001600160a01b0381166000908152600560205260409020805460018101825590613132565b6000610e0f6150346137c2565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6000806000615086878787876153c5565b91509150615093816154b2565b5095945050505050565b6000610f948383670de0b6b3a7640000613d7a565b6000806150be60025490565b9050828111156131325760006150d48483615cf8565b9050610e5a848383613d4c565b80158061515b5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015615135573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906151599190615cab565b155b6151c65760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610eb0565b6040516001600160a01b038316602482015260448101829052613d4790849063095ea7b360e01b906064016140fe565b60008160ff168360ff160361520c575082610f94565b8160ff168360ff161015615240576152248383615f8b565b61522f90600a615f66565b6152399085615d8e565b9050610f94565b61524a8284615f8b565b61525590600a615f66565b6152399085615dad565b613d478361536a565b6040516001600160a01b038316602482015260448101829052613d4790849063a9059cbb60e01b906064016140fe565b60006152ed826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661566b9092919063ffffffff16565b805190915015613d47578080602001905181019061530b9190615dcf565b613d475760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610eb0565b6001600160a01b0381166000908152601660205260409020548015613f74576000601554826153999190615d7b565b905043811115613d47576040516306f8ee3f60e21b815260048101829052436024820152604401610eb0565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156153fc57506000905060036154a9565b8460ff16601b1415801561541457508460ff16601c14155b1561542557506000905060046154a9565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015615479573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166154a2576000600192509250506154a9565b9150600090505b94509492505050565b60008160048111156154c6576154c6615a32565b036154ce5750565b60018160048111156154e2576154e2615a32565b0361552f5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610eb0565b600281600481111561554357615543615a32565b036155905760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610eb0565b60038160048111156155a4576155a4615a32565b036155fc5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610eb0565b600481600481111561561057615610615a32565b036156685760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610eb0565b50565b6060610e5a8484600085856001600160a01b0385163b6156cd5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610eb0565b600080866001600160a01b031685876040516156e99190615fa4565b60006040518083038185875af1925050503d8060008114615726576040519150601f19603f3d011682016040523d82523d6000602084013e61572b565b606091505b509150915061573b828286615746565b979650505050505050565b60608315615755575081610f94565b8251156157655782518084602001fd5b8160405162461bcd60e51b8152600401610eb091906157a3565b60005b8381101561579a578181015183820152602001615782565b50506000910152565b60208152600082518060208401526157c281604085016020870161577f565b601f01601f19169190910160400192915050565b6000602082840312156157e857600080fd5b5035919050565b6001600160a01b038116811461566857600080fd5b6000806040838503121561581757600080fd5b8235615822816157ef565b946020939093013593505050565b60006020828403121561584257600080fd5b8135610f94816157ef565b60008060006060848603121561586257600080fd5b833561586d816157ef565b9250602084013561587d816157ef565b929592945050506040919091013590565b6002811061566857600080fd5b6000602082840312156158ad57600080fd5b8135610f948161588e565b60008060008060008060a087890312156158d157600080fd5b86356158dc816157ef565b955060208701356158ec816157ef565b94506040870135935060608701356159038161588e565b925060808701356001600160401b038082111561591f57600080fd5b818901915089601f83011261593357600080fd5b81358181111561594257600080fd5b8a602082850101111561595457600080fd5b6020830194508093505050509295509295509295565b60006020828403121561597c57600080fd5b81356001600160401b0381168114610f9457600080fd5b600080604083850312156159a657600080fd5b8235915060208301356159b8816157ef565b809150509250929050565b600080604083850312156159d657600080fd5b50508035926020909101359150565b6020808252825182820181905260009190848201906040850190845b81811015615a265783516001600160a01b031683529284019291840191600101615a01565b50909695505050505050565b634e487b7160e01b600052602160045260246000fd5b6020810160038310615a5c57615a5c615a32565b91905290565b600080600060608486031215615a7757600080fd5b833592506020840135615a89816157ef565b91506040840135615a99816157ef565b809150509250925092565b60ff8116811461566857600080fd5b600080600080600080600060e0888a031215615ace57600080fd5b8735615ad9816157ef565b96506020880135615ae9816157ef565b955060408801359450606088013593506080880135615b0781615aa4565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215615b3757600080fd5b8235615b42816157ef565b915060208301356159b8816157ef565b6002811061566857615668615a32565b60208101615a5c83615b52565b60008060408385031215615b8257600080fd5b8235615b8d816157ef565b91506020830135600381106159b857600080fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201615bf557615bf5615bcd565b5060010190565b600060208284031215615c0e57600080fd5b8151610f94816157ef565b606080825284519082018190526000906020906080840190828801845b82811015615c5b5781516001600160a01b031684529284019290840190600101615c36565b5050508381038285015285518082528683019183019060005b81811015615c9057835183529284019291840191600101615c74565b50506001600160a01b03861660408601529250610e5a915050565b600060208284031215615cbd57600080fd5b5051919050565b600181811c90821680615cd857607f821691505b60208210810361313257634e487b7160e01b600052602260045260246000fd5b81810381811115610e0f57610e0f615bcd565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b60408101615d3e84615b52565b838252615d4a83615b52565b8260208301529392505050565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b80820180821115610e0f57610e0f615bcd565b6000816000190483118215151615615da857615da8615bcd565b500290565b600082615dca57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215615de157600080fd5b81518015158114610f9457600080fd5b600060208284031215615e0357600080fd5b8151610f9481615aa4565b615e1787615b52565b86815260a060208201528460a0820152848660c0830137600060c08683018101919091526001600160a01b039485166040830152928416606082015292166080830152601f909201601f1916010192915050565b600081615e7a57615e7a615bcd565b506000190190565b600181815b80851115615ebd578160001904821115615ea357615ea3615bcd565b80851615615eb057918102915b93841c9390800290615e87565b509250929050565b600082615ed457506001610e0f565b81615ee157506000610e0f565b8160018114615ef75760028114615f0157615f1d565b6001915050610e0f565b60ff841115615f1257615f12615bcd565b50506001821b610e0f565b5060208310610133831016604e8410600b8410161715615f40575081810a610e0f565b615f4a8383615e82565b8060001904821115615f5e57615f5e615bcd565b029392505050565b6000610f9460ff841683615ec5565b634e487b7160e01b600052603160045260246000fd5b60ff8281168282160390811115610e0f57610e0f615bcd565b60008251615fb681846020870161577f565b919091019291505056fea2646970667358221220eba27189ab86bbc5f387e2564b1dcc05ef67fe18030cba1e63b399e331b2806d64736f6c63430008100033000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce083000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000a9962a5bfbea6918e958dee0647e99fd7863b95a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a537465616479204254430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000095374656164794254430000000000000000000000000000000000000000000000

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106104745760003560e01c806394bf804d11610257578063c046742211610146578063dff90b5b116100c3578063ef8b30f711610087578063ef8b30f714610aa3578063f7b24e0814610ab6578063fc44459114610abe578063fc4d43be14610ade578063fdd230b914610af157600080fd5b8063dff90b5b146109d2578063e39448e0146109da578063e753e600146109f4578063ecf7085814610a8b578063eef33eca14610a9457600080fd5b8063ce96cb771161010a578063ce96cb7714610973578063d505accf14610986578063d905777e14610999578063dd62ed3e146109ac578063df05a52a146109bf57600080fd5b8063c046742214610929578063c244245a1461093c578063c63d75b614610945578063c6e6f59214610958578063c85e5e131461096b57600080fd5b8063a8144e48116101d4578063b5292a9911610198578063b5292a99146108d4578063ba087652146108e7578063bdc8144b146108fa578063bdca91651461090d578063bf86d6901461091c57600080fd5b8063a8144e4814610880578063a9059cbb14610888578063b0a75d361461089b578063b3d7f6b9146108ae578063b460af94146108c157600080fd5b80639c552ca81161021b5780639c552ca8146108095780639c5f00c21461081c5780639e35c65b146108345780639fdb11b614610864578063a457c2d71461086d57600080fd5b806394bf804d146107a557806395d89b41146107b857806396d64879146107c057806399fbab88146107e35780639b6fd18e146107f657600080fd5b8063402d267d116103735780636ff1c02a116102f05780637b3baab4116102b45780637b3baab41461073d5780637ecebe0014610757578063802758601461076a5780638b0cebf71461077f5780638da5cb5b1461079257600080fd5b80636ff1c02a146106c257806370a08231146106d157806370af7df6146106fa578063721637151461070d5780637b1039991461071657600080fd5b8063583845731161033757806358384573146106795780635a400d251461068c5780635e2c576e146106945780636e553f651461069c5780636e85f183146106af57600080fd5b8063402d267d1461060a578063472090fe1461061d5780634cdad506146106405780634eca8a8314610653578063530a37141461066657600080fd5b806318160ddd11610401578063389a7294116103c5578063389a72941461056b57806338d52e0f1461057e57806339509351146105bd5780633998a681146105d05780633cf99a46146105f757600080fd5b806318160ddd1461052057806323b872dd146105285780632f3b5a131461053b578063313ce5671461054e5780633644e5151461056357600080fd5b806307a2d13a1161044857806307a2d13a146104ba578063095ea7b3146104cd5780630a28a477146104f05780630a680e181461050357806313af40351461050d57600080fd5b806251a3b71461047957806301e1d114146104945780630402ab631461049c57806306fdde03146104a5575b600080fd5b610481600881565b6040519081526020015b60405180910390f35b610481610b04565b610481611c2081565b6104ad610d6a565b60405161048b91906157a3565b6104816104c83660046157d6565b610dfc565b6104e06104db366004615804565b610e15565b604051901515815260200161048b565b6104816104fe3660046157d6565b610e2d565b61050b610e62565b005b61050b61051b366004615830565b610eff565b600254610481565b6104e061053636600461584d565b610f75565b61050b61054936600461589b565b610f9b565b60125b60405160ff909116815260200161048b565b61048161102c565b6104816105793660046158b8565b61103b565b6105a57f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6040516001600160a01b03909116815260200161048b565b6104e06105cb366004615804565b6112ab565b6105df6702c68af0bb14000081565b6040516001600160401b03909116815260200161048b565b61050b61060536600461596a565b6112cd565b610481610618366004615830565b61139f565b6104e061062b366004615830565b600a6020526000908152604090205460ff1681565b61048161064e3660046157d6565b611447565b61050b610661366004615993565b61146f565b61050b6106743660046157d6565b6115d9565b61050b6106873660046159c3565b611683565b610481600281565b61050b6117ca565b6104816106aa366004615993565b611852565b61050b6106bd3660046157d6565b611964565b6105df67016345785d8a000081565b6104816106df366004615830565b6001600160a01b031660009081526020819052604090205490565b61050b61070836600461596a565b6119f7565b61048160125481565b6105a57f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce08381565b600d546105df90600160a81b90046001600160401b031681565b610481610765366004615830565b611ace565b610772611aec565b60405161048b91906159e5565b61050b61078d366004615830565b611b4d565b6007546105a5906001600160a01b031681565b6104816107b3366004615993565b611cb5565b6104ad611dbb565b6104e06107ce366004615830565b600c6020526000908152604090205460ff1681565b6105a56107f13660046157d6565b611dca565b61050b61080436600461596a565b611df4565b61050b6108173660046157d6565b611eba565b600d546105a59061010090046001600160a01b031681565b610857610842366004615830565b600b6020526000908152604090205460ff1681565b60405161048b9190615a48565b61048160155481565b6104e061087b366004615804565b611f50565b610481611fd6565b6104e0610896366004615804565b612112565b61050b6108a9366004615830565b612120565b6104816108bc3660046157d6565b6121b3565b6104816108cf366004615a62565b6121e0565b61050b6108e236600461596a565b612300565b6104816108f5366004615a62565b6123dc565b61050b6109083660046157d6565b612505565b6105df6706f05b59d3b2000081565b6014546104e09060ff1681565b61050b6109373660046157d6565b612570565b61048160175481565b610481610953366004615830565b61269f565b6104816109663660046157d6565b6126c4565b61050b6126d7565b610481610981366004615830565b612749565b61050b610994366004615ab3565b612756565b6104816109a7366004615830565b6128ba565b6104816109ba366004615b24565b6128c7565b61050b6109cd3660046157d6565b6128f2565b61050b61295d565b600d546109e79060ff1681565b60405161048b9190615b62565b600e54600f54601054601154610a3c93926001600160401b0380821693600160401b8304821693600160801b8404831693600160c01b9004909216916001600160a01b031687565b604080519788526001600160401b039687166020890152948616948701949094529184166060860152909216608084015260a08301919091526001600160a01b031660c082015260e00161048b565b61048160135481565b6105df670de0b6b3a764000081565b610481610ab13660046157d6565b612ccd565b610551602081565b610481610acc366004615830565b60166020526000908152604090205481565b61050b610aec366004615b6f565b612cf5565b61050b610aff366004615830565b612ed6565b60095460009081816001600160401b03811115610b2357610b23615ba1565b604051908082528060200260200182016040528015610b4c578160200160208202803683370190505b5090506000826001600160401b03811115610b6957610b69615ba1565b604051908082528060200260200182016040528015610b92578160200160208202803683370190505b50905060005b83811015610c4057600060098281548110610bb557610bb5615bb7565b6000918252602090912001546001600160a01b03169050610bd581613077565b848381518110610be757610be7615bb7565b60200260200101906001600160a01b031690816001600160a01b031681525050610c1081613138565b838381518110610c2257610c22615bb7565b60209081029190910101525080610c3881615be3565b915050610b98565b50604051635c9fcd8560e11b8152600260048201526000907f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce0836001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015610ca9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ccd9190615bfc565b60405163b333a17560e01b81529091506001600160a01b0382169063b333a17590610d2090869086907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4890600401615c19565b602060405180830381865afa158015610d3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d619190615cab565b94505050505090565b606060038054610d7990615cc4565b80601f0160208091040260200160405190810160405280929190818152602001828054610da590615cc4565b8015610df25780601f10610dc757610100808354040283529160200191610df2565b820191906000526020600020905b815481529060010190602001808311610dd557829003601f168201915b5050505050905090565b6000610e0f82610e0a610b04565b613285565b92915050565b600033610e23818585613338565b5060019392505050565b600080610e38610b04565b90506000610e458261345c565b9050610e5a84610e558385615cf8565b6134c2565b949350505050565b60145460ff1615610e86576040516337a5332d60e11b815260040160405180910390fd5b6007546001600160a01b03163314610eb95760405162461bcd60e51b8152600401610eb090615d0b565b60405180910390fd5b6014805460ff191660019081179091556040519081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c906020015b60405180910390a1565b6007546001600160a01b03163314610f295760405162461bcd60e51b8152600401610eb090615d0b565b600780546001600160a01b0319166001600160a01b03831690811790915560405133907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d7690600090a350565b600033610f8385828561356f565b610f8e8585856135e9565b60019150505b9392505050565b6007546001600160a01b03163314610fc55760405162461bcd60e51b8152600401610eb090615d0b565b600d546040517f19365927bf52f7e956d376b3546402dda3827c062c7a6942431a255d212947e891610ffe9160ff909116908490615d31565b60405180910390a1600d805482919060ff19166001838181111561102457611024615a32565b021790555050565b60006110366137c2565b905090565b6007546000906001600160a01b031633146110685760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff161561108c576040516337a5332d60e11b815260040160405180910390fd5b6008546001146110ae5760405162461bcd60e51b8152600401610eb090615d57565b60026008556001600160a01b0386166000908152600a602052604090205460ff166110f757604051631ec7bcd360e01b81526001600160a01b0387166004820152602401610eb0565b6000611101610b04565b9050600061110e60025490565b905061111b8988306138e9565b60006111268a613077565b905060006111338a613077565b9050806001600160a01b0316826001600160a01b0316036111545788611163565b61116382828b8b8b8b306139de565b945061116f8a86613c0d565b600061119a601754670de0b6b3a764000061118a9190615cf8565b8690670de0b6b3a7640000613d4c565b905060006111c7601754670de0b6b3a76400006111b79190615d7b565b8790670de0b6b3a7640000613d7a565b90506111d1610b04565b9550808611806111e057508186105b1561120f5760405163628cc47560e11b8152600481018790526024810183905260448101829052606401610eb0565b600254851461123f57600254604051632b40145960e21b8152600481019190915260248101869052604401610eb0565b8b6001600160a01b03168d6001600160a01b03167ffea7a9a6e25cd0bbbfa80ce0c7646e61ee5e0551b3fdaaff0642e6f6adcc72e28d8a60405161128d929190918252602082015260400190565b60405180910390a35050600160085550929998505050505050505050565b600033610e238185856112be83836128c7565b6112c89190615d7b565b613338565b6007546001600160a01b031633146112f75760405162461bcd60e51b8152600401610eb090615d0b565b6706f05b59d3b200006001600160401b038216111561132957604051632e15286d60e11b815260040160405180910390fd5b600f5460408051600160c01b9092046001600160401b039081168352831660208301527f27dd3ae8ff7f5e3d77ae68ed36dc780d2ab40a4ffdda18d805cb41eea39c2894910160405180910390a1600f80546001600160401b03909216600160c01b026001600160c01b03909216919091179055565b60145460009060ff16156113b557506000919050565b601354601254600019821480156113cd575060001981145b156113dd57506000199392505050565b60006113e7610b04565b9050600061141361140d876001600160a01b031660009081526020819052604090205490565b83613285565b905060006114218583613d99565b9050600061142f8585613d99565b905061143b8282613db3565b98975050505050505050565b600080611452610b04565b9050600061145f8261345c565b9050610e5a84610e0a8385615cf8565b6007546001600160a01b031633146114995760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff16156114bd576040516337a5332d60e11b815260040160405180910390fd5b6009546020116114e35760405163f025236d60e01b815260206004820152602401610eb0565b6001600160a01b0381166000908152600c602052604090205460ff166115275760405163699f66b160e11b81526001600160a01b0382166004820152602401610eb0565b6001600160a01b0381166000908152600a602052604090205460ff161561156c57604051630af67d9160e31b81526001600160a01b0382166004820152602401610eb0565b61157860098383613dc2565b6001600160a01b0381166000818152600a602052604090819020805460ff19166001179055517fcff5c8a08884d2fad939a9e0f0bf729a4f9af6111a573b4d1f11396c8711646d906115cd9085815260200190565b60405180910390a25050565b6007546001600160a01b031633146116035760405162461bcd60e51b8152600401610eb090615d0b565b67016345785d8a000081111561163d576040516302d2a90f60e51b81526004810182905267016345785d8a00006024820152604401610eb0565b601780549082905560408051828152602081018490527fdf4be33b2e9e3dd4d9e0e85645aea428494a0644a72c51d6a15aedae6b66a3ff91015b60405180910390a15050565b6007546001600160a01b031633146116ad5760405162461bcd60e51b8152600401610eb090615d0b565b6000600982815481106116c2576116c2615bb7565b6000918252602082200154600980546001600160a01b03909216935090859081106116ef576116ef615bb7565b9060005260206000200160009054906101000a90046001600160a01b0316905081816009868154811061172457611724615bb7565b9060005260206000200160006009878154811061174357611743615bb7565b60009182526020918290200180546001600160a01b039586166001600160a01b031990911617905582549484166101009290920a918202918402199094161790556040805187815292830186905283821692918516917f3cae4f5796f9d19fa1dcfaacae5a9811c008f6f517a3ec689d903d6f699e4955910160405180910390a350505050565b6007546001600160a01b031633146117f45760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff166118175760405163ec7165bf60e01b815260040160405180910390fd5b6014805460ff19169055604051600081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c90602001610ef5565b60006008546001146118765760405162461bcd60e51b8152600401610eb090615d57565b60026008556000611885610b04565b905061189081613f3b565b61189a8482613f78565b9150816000036118bd5760405163426f153760e11b815260040160405180910390fd5b6118c8848385613f97565b6118fd6001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48163330876140ca565b6119078383614135565b60408051858152602081018490526001600160a01b0385169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a3611958848385614220565b50600160085592915050565b6007546001600160a01b0316331461198e5760405162461bcd60e51b8152600401610eb090615d0b565b6001600160a01b038111156119b65760405163019b5e3160e21b815260040160405180910390fd5b60105460408051918252602082018390527f513ac19cbbaaad4e450c732ed37635178b7d83bf8e84a940ffe7e052c9c7caa2910160405180910390a1601055565b6007546001600160a01b03163314611a215760405162461bcd60e51b8152600401610eb090615d0b565b6702c68af0bb1400006001600160401b0382161115611a5357604051632e15286d60e11b815260040160405180910390fd5b600f5460408051600160801b9092046001600160401b039081168352831660208301527f44ada261ff5c9aacbf8d0687294799c8e3e0810ecc1eafd97419dfc31db5d523910160405180910390a1600f80546001600160401b03909216600160801b0267ffffffffffffffff60801b19909216919091179055565b6001600160a01b038116600090815260056020526040812054610e0f565b60606009805480602002602001604051908101604052809291908181526020018280548015610df257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611b26575050505050905090565b6007546001600160a01b03163314611b775760405162461bcd60e51b8152600401610eb090615d0b565b6001600160a01b0381166000908152600a602052604090205460ff16611bbb57604051631ec7bcd360e01b81526001600160a01b0382166004820152602401610eb0565b6000611bc682613077565b90507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316816001600160a01b031614611c4d5760405163298473c760e11b81526001600160a01b0380831660048301527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48166024820152604401610eb0565b600d546040516001600160a01b0380851692610100900416907f7f835fbf43c4d05a9c4ea5cafa09fbb3b0307d12956ceedce43fd7a339e5046e90600090a350600d80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000600854600114611cd95760405162461bcd60e51b8152600401610eb090615d57565b60026008556000611ce8610b04565b9050611cf381613f3b565b611cfd8482614259565b915081600003611d2057604051639768300560e01b815260040160405180910390fd5b611d2b828585613f97565b611d606001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48163330856140ca565b611d6a8385614135565b60408051838152602081018690526001600160a01b0385169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a3611958828585614220565b606060048054610d7990615cc4565b60098181548110611dda57600080fd5b6000918252602090912001546001600160a01b0316905081565b6007546001600160a01b03163314611e1e5760405162461bcd60e51b8152600401610eb090615d0b565b670de0b6b3a76400006001600160401b0382161115611e5057604051633d0203e560e01b815260040160405180910390fd5b600f54604080516001600160401b03928316815291831660208301527fc79399093f73f1ff8c2f8279aa9e8803b694c60016c344ecfc2a89fd77c004db910160405180910390a1600f805467ffffffffffffffff19166001600160401b0392909216919091179055565b6007546001600160a01b03163314611ee45760405162461bcd60e51b8152600401610eb090615d0b565b6008811080611ef45750611c2081115b15611f1257604051633a60233f60e21b815260040160405180910390fd5b601580549082905560408051828152602081018490527f227ff5c6b5ffb395236b09fd1b472bb128b36eaa17556633feefe28e94411f249101611677565b60003381611f5e82866128c7565b905083811015611fbe5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610eb0565b611fcb8286868403613338565b506001949350505050565b60095460009081816001600160401b03811115611ff557611ff5615ba1565b60405190808252806020026020018201604052801561201e578160200160208202803683370190505b5090506000826001600160401b0381111561203b5761203b615ba1565b604051908082528060200260200182016040528015612064578160200160208202803683370190505b50905060005b83811015610c405760006009828154811061208757612087615bb7565b6000918252602090912001546001600160a01b031690506120a781613077565b8483815181106120b9576120b9615bb7565b60200260200101906001600160a01b031690816001600160a01b0316815250506120e281614278565b8383815181106120f4576120f4615bb7565b6020908102919091010152508061210a81615be3565b91505061206a565b600033610e238185856135e9565b6007546001600160a01b0316331461214a5760405162461bcd60e51b8152600401610eb090615d0b565b601154604080516001600160a01b03928316815291831660208301527f51dbb5a65bb22737861a63ec12ba6ce78a98631e9404b0567a2eaf7a06fc544d910160405180910390a1601180546001600160a01b0319166001600160a01b0392909216919091179055565b6000806121be610b04565b905060006121cb8261345c565b9050610e5a846121db8385615cf8565b614259565b60006008546001146122045760405162461bcd60e51b8152600401610eb090615d57565b60026008556000808080806122176142f6565b9450945094509450945061222a85613f3b565b61223489866134c2565b955061224289878a8a614693565b61224c87876146c2565b600061225760025490565b905061226388886146dd565b604080518b8152602081018990526001600160a01b03808b1692908c169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a46000600d5460ff1660018111156122c7576122c7615a32565b146122df576122da87828b888787614837565b6122ed565b6122ed8a8a8787878761494f565b5050600160085550929695505050505050565b6007546001600160a01b0316331461232a5760405162461bcd60e51b8152600401610eb090615d0b565b670de0b6b3a76400006001600160401b038216111561235c57604051633d0203e560e01b815260040160405180910390fd5b600f5460408051600160401b9092046001600160401b039081168352831660208301527fb5cc994a260a85a42d6588668221571ae0a14f0a28f9e4817a5195262102c868910160405180910390a1600f80546001600160401b03909216600160401b026fffffffffffffffff000000000000000019909216919091179055565b60006008546001146124005760405162461bcd60e51b8152600401610eb090615d57565b60026008556000808080806124136142f6565b9450945094509450945061242685613f3b565b612430878a6146c2565b61243a8986613285565b95508560000361245d57604051639768300560e01b815260040160405180910390fd5b612469868a8a8a614693565b600061247460025490565b9050612480888b6146dd565b60408051888152602081018c90526001600160a01b03808b1692908c169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a46000600d5460ff1660018111156124e4576124e4615a32565b146124f7576122da8a828b888787614837565b6122da878a8787878761494f565b6007546001600160a01b0316331461252f5760405162461bcd60e51b8152600401610eb090615d0b565b60135460408051918252602082018390527fcfb5a454b8aa7dc04ecb5bc1410b2a57969ca1d67f66d565196f60c6f9975404910160405180910390a1601355565b6007546001600160a01b0316331461259a5760405162461bcd60e51b8152600401610eb090615d0b565b6000600982815481106125af576125af615bb7565b60009182526020822001546001600160a01b031691506125ce82613138565b9050801561260157604051638454689f60e01b81526001600160a01b038316600482015260248101829052604401610eb0565b600d546001600160a01b036101009091048116908316036126355760405163747795ff60e11b815260040160405180910390fd5b612640600984614c9e565b6001600160a01b0382166000818152600a602052604090819020805460ff19169055517f03c78e4e20a72b1f577a63b54524c684ce73d2e414970ee606bb0b7a9004aa9c906126929086815260200190565b60405180910390a2505050565b6000806126ab8361139f565b90506000198114610e0f576126bf816126c4565b610f94565b6000610e0f826126d2610b04565b613f78565b6007546001600160a01b031633146127015760405162461bcd60e51b8152600401610eb090615d0b565b600061270b610b04565b600e8190556040518181529091507f875561ddc342b12981103d85be8db6375a88982d4cf58d411e38715ae46833309060200160405180910390a150565b6000610e0f826000614db8565b834211156127a65760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610eb0565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886127d58c615001565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050600061283082615027565b9050600061284082878787615075565b9050896001600160a01b0316816001600160a01b0316146128a35760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610eb0565b6128ae8a8a8a613338565b50505050505050505050565b6000610e0f826001614db8565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6007546001600160a01b0316331461291c5760405162461bcd60e51b8152600401610eb090615d0b565b60125460408051918252602082018390527f1f21432dd7b8ead64d2e7c06a74baf13783b2d2f7153f099e2c4cabc3c5dbec6910160405180910390a1601255565b60085460011461297f5760405162461bcd60e51b8152600401610eb090615d57565b60026008556011546001600160a01b0316806129ae5760405163dc13611360e01b815260040160405180910390fd5b60006129b8610b04565b90506129c381613f3b565b30600090815260208190526040812054600f549091906129ed9083906001600160401b031661509d565b600d54909150600090612a1090600160a81b90046001600160401b031642615cf8565b600f549091506000906301e1338090670de0b6b3a764000090600160801b90046001600160401b0316612a438589615d8e565b612a4d9190615d8e565b612a579190615dad565b612a619190615dad565b90506000612a77612a728388613f78565b6150b2565b9050612a833082614135565b612a8d8186615d7b565b600f54909550612aae908290600160401b90046001600160401b031661509d565b612ab89085615d7b565b93508315612ad857612acb3088866135e9565b612ad58486615cf8565b94505b600d805467ffffffffffffffff60a81b19164263ffffffff16600160a81b021790556000612b068688613285565b90508015612c855780600e6000016000828254612b239190615cf8565b90915550612b33905030876146dd565b604051635c9fcd8560e11b8152600060048201819052907f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce0836001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612b9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bbf9190615bfc565b9050612bf56001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb481682846150e1565b601054604051631ffbe7f960e01b81526001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb488116600483015260248201929092526044810184905290821690631ffbe7f990606401600060405180830381600087803b158015612c6b57600080fd5b505af1158015612c7f573d6000803e3d6000fd5b50505050505b60408051878152602081018390527f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea6910160405180910390a150506001600855505050505050565b600080612cd8610b04565b90506000612ce58261345c565b9050610e5a846126d28385615cf8565b6007546001600160a01b03163314612d1f5760405162461bcd60e51b8152600401610eb090615d0b565b6001600160a01b0382166000908152600c602090815260408083208054600160ff199182168117909255600b90935292208054849391921690836002811115612d6a57612d6a615a32565b02179055506000612d7a83613077565b604051635c9fcd8560e11b8152600260048201529091507f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce0836001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612de2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e069190615bfc565b604051634f129c5360e01b81526001600160a01b0383811660048301529190911690634f129c5390602401602060405180830381865afa158015612e4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e729190615dcf565b612e9a57604051637eb56edb60e11b81526001600160a01b0382166004820152602401610eb0565b604051600181526001600160a01b038416907fd600b9348603c6deff34b4e0b28b60e1c8036c806741b9e6d90032e7f37dd27f90602001612692565b6007546001600160a01b03163314612f005760405162461bcd60e51b8152600401610eb090615d0b565b60145460ff1615612f24576040516337a5332d60e11b815260040160405180910390fd5b600954602011612f4a5760405163f025236d60e01b815260206004820152602401610eb0565b6001600160a01b0381166000908152600c602052604090205460ff16612f8e5760405163699f66b160e11b81526001600160a01b0382166004820152602401610eb0565b6001600160a01b0381166000908152600a602052604090205460ff1615612fd357604051630af67d9160e31b81526001600160a01b0382166004820152602401610eb0565b60098054600180820183557f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af90910180546001600160a01b0319166001600160a01b0385169081179091556000818152600a60205260409020805460ff19168317905591547fcff5c8a08884d2fad939a9e0f0bf729a4f9af6111a573b4d1f11396c8711646d9161306391615cf8565b60405190815260200160405180910390a250565b6001600160a01b0381166000908152600b602052604081205460ff1660018160028111156130a7576130a7615a32565b14806130c4575060028160028111156130c2576130c2615a32565b145b1561312b57826001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613107573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f949190615bfc565b5090919050565b50919050565b6001600160a01b0381166000908152600b602052604081205460ff16600181600281111561316857613168615a32565b14806131855750600281600281111561318357613183615a32565b145b15613259576040516370a0823160e01b81523060048201526001600160a01b03841690634cdad5069082906370a0823190602401602060405180830381865afa1580156131d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131fa9190615cab565b6040518263ffffffff1660e01b815260040161321891815260200190565b602060405180830381865afa158015613235573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f949190615cab565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401613218565b60008061329160025490565b905080156132a9576132a4848483613d7a565b610e5a565b610e5a60127f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561330c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133309190615df1565b8691906151f6565b6001600160a01b03831661339a5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610eb0565b6001600160a01b0382166133fb5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610eb0565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600f54600090600160c01b90046001600160401b031680158061347d575082155b1561348b5750600092915050565b600e54808411156134bb5760006134a28286615cf8565b90506134b7816001600160401b03851661509d565b9350505b5050919050565b6000806134ce60025490565b905080156134e1576132a4848285613d4c565b610e5a7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613542573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135669190615df1565b859060126151f6565b600061357b84846128c7565b905060001981146135e357818110156135d65760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610eb0565b6135e38484848403613338565b50505050565b6001600160a01b03831661364d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610eb0565b6001600160a01b0382166136af5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610eb0565b6136ba83838361525f565b6001600160a01b038316600090815260208190526040902054818110156137325760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610eb0565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290613769908490615d7b565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516137b591815260200190565b60405180910390a36135e3565b6000306001600160a01b037f0000000000000000000000004986fd36b6b16f49b43282ee2e24c5cf90ed166d1614801561381b57507f000000000000000000000000000000000000000000000000000000000000000146145b1561384557507ff1d6da46cb5d5b7856ab01cb1acfeb479f666df30b001e4398f584ecebab33ed90565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527f34979abb3767a34f75d2a5526c5011b4190fa9645574fdb9a18b61db87b9edb2828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6001600160a01b0383166000908152600b602052604090205460ff16600181600281111561391957613919615a32565b14806139365750600281600281111561393457613934615a32565b145b156139ba57604051632d182be560e21b8152600481018490526001600160a01b03838116602483015230604483015285169063b460af94906064016020604051808303816000875af1158015613990573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139b49190615cab565b506135e3565b6001600160a01b03821630146135e3576135e36001600160a01b0385168385615268565b6040516370a0823160e01b8152306004820152600090819087906001600160a01b038b16906370a0823190602401602060405180830381865afa158015613a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a4d9190615cab565b613a579190615cf8565b604051635c9fcd8560e11b8152600160048201529091506000906001600160a01b037f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce083169063b93f9b0a90602401602060405180830381865afa158015613ac2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ae69190615bfc565b9050613afc6001600160a01b038b16828a6150e1565b806001600160a01b0316632dfe1690888888888f8f6040518763ffffffff1660e01b8152600401613b3296959493929190615e0e565b6020604051808303816000875af1158015613b51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b759190615cab565b6040516370a0823160e01b815230600482015290935082906001600160a01b038c16906370a0823190602401602060405180830381865afa158015613bbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613be29190615cab565b14613c0057604051630a9213b560e21b815260040160405180910390fd5b5050979650505050505050565b6001600160a01b0382166000908152600b602052604090205460ff166001816002811115613c3d57613c3d615a32565b1480613c5a57506002816002811115613c5857613c58615a32565b145b15613d4757613cd68383856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ca2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cc69190615bfc565b6001600160a01b031691906150e1565b604051636e553f6560e01b8152600481018390523060248201526001600160a01b03841690636e553f65906044016020604051808303816000875af1158015613d23573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135e39190615cab565b505050565b828202811515841585830485141716613d6457600080fd5b6001826001830304018115150290509392505050565b828202811515841585830485141716613d9257600080fd5b0492915050565b6000818311613da9576000610f94565b610f948284615cf8565b600081831061312b5781610f94565b82548015613f08578380613dd7600184615cf8565b81548110613de757613de7615bb7565b600091825260208083209091015483546001818101865594845291832090910180546001600160a01b0319166001600160a01b0390921691909117905590613e2f9083615cf8565b90505b83811115613ec15784613e46600183615cf8565b81548110613e5657613e56615bb7565b9060005260206000200160009054906101000a90046001600160a01b0316858281548110613e8657613e86615bb7565b600091825260209091200180546001600160a01b0319166001600160a01b039290921691909117905580613eb981615e6b565b915050613e32565b5081848481548110613ed557613ed5615bb7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506135e3565b83546001810185556000858152602090200180546001600160a01b0384166001600160a01b031990911617905550505050565b6000613f468261345c565b90508015613f74576000613f5d612a728385613f78565b90508015613d4757600e839055613d473082614135565b5050565b600080613f8460025490565b905080156134e1576132a4848285613d7a565b60145460ff1615613fbb576040516337a5332d60e11b815260040160405180910390fd5b336001600160a01b0382161461407257604051635551e1b560e01b81523360048201527f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce0836001600160a01b031690635551e1b590602401602060405180830381865afa15801561402f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140539190615dcf565b614072576040516334871f2560e21b8152336004820152602401610eb0565b600061407d8261139f565b9050808411156140aa57604051632d21eb8760e21b81526004810185905260248101829052604401610eb0565b83600e60000160008282546140bf9190615d7b565b909155505050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526135e39085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152615298565b6001600160a01b03821661418b5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610eb0565b6141976000838361525f565b80600260008282546141a99190615d7b565b90915550506001600160a01b038216600090815260208190526040812080548392906141d6908490615d7b565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b600d5461423b9061010090046001600160a01b031684613c0d565b6001600160a01b031660009081526016602052604090204390555050565b60008061426560025490565b905080156132a9576132a4848483613d4c565b6001600160a01b0381166000908152600b602052604081205460ff1660018160028111156142a8576142a8615a32565b14806142c5575060028160028111156142c3576142c3615a32565b145b156132595760405163ce96cb7760e01b81523060048201526001600160a01b0384169063ce96cb7790602401613218565b600954600090606090819081908190806001600160401b0381111561431d5761431d615ba1565b604051908082528060200260200182016040528015614346578160200160208202803683370190505b509450806001600160401b0381111561436157614361615ba1565b60405190808252806020026020018201604052801561438a578160200160208202803683370190505b509350806001600160401b038111156143a5576143a5615ba1565b6040519080825280602002602001820160405280156143ce578160200160208202803683370190505b509250806001600160401b038111156143e9576143e9615ba1565b604051908082528060200260200182016040528015614412578160200160208202803683370190505b509250806001600160401b0381111561442d5761442d615ba1565b604051908082528060200260200182016040528015614456578160200160208202803683370190505b50915060005b818110156145675760006009828154811061447957614479615bb7565b9060005260206000200160009054906101000a90046001600160a01b03169050808783815181106144ac576144ac615bb7565b60200260200101906001600160a01b031690816001600160a01b0316815250506144d581613077565b8683815181106144e7576144e7615bb7565b60200260200101906001600160a01b031690816001600160a01b03168152505061451081613138565b85838151811061452257614522615bb7565b60200260200101818152505061453781614278565b84838151811061454957614549615bb7565b6020908102919091010152508061455f81615be3565b91505061445c565b50604051635c9fcd8560e11b8152600260048201526000907f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce0836001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156145d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145f49190615bfc565b60405163b333a17560e01b81529091506001600160a01b0382169063b333a1759061464790889088907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4890600401615c19565b602060405180830381865afa158015614664573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146889190615cab565b965050509091929394565b61469c8161536a565b600e548085116146b5576146b08582615cf8565b6146b8565b60005b600e555050505050565b336001600160a01b03831614613f7457613f7482338361356f565b6001600160a01b03821661473d5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610eb0565b6147498260008361525f565b6001600160a01b038216600090815260208190526040902054818110156147bd5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610eb0565b6001600160a01b03831660009081526020819052604081208383039055600280548492906147ec908490615cf8565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b60005b835181101561494657600084828151811061485757614857615bb7565b60200260200101519050600084838151811061487557614875615bb7565b602002602001015190508060000361488e575050614934565b600061489b828b8b613d7a565b90508484815181106148af576148af615bb7565b60200260200101518111156148e25760405163f2018f6f60e01b81526001600160a01b0384166004820152602401610eb0565b6148ed83828a6138e9565b826001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed828260405161492891815260200190565b60405180910390a25050505b8061493e81615be3565b91505061483a565b50505050505050565b604051635c9fcd8560e11b8152600260048201526000907f000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce0836001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156149b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149db9190615bfc565b905060005b8551811015614c7b578381815181106149fb576149fb615bb7565b602002602001015160000315614c69576000858281518110614a1f57614a1f615bb7565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a889190615df1565b614a9390600a615f66565b90506000836001600160a01b031663baaa61be888581518110614ab857614ab8615bb7565b60200260200101517f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486040518363ffffffff1660e01b8152600401614b139291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa158015614b30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b549190615cab565b90506000614b868284888781518110614b6f57614b6f615bb7565b6020026020010151613d7a9092919063ffffffff16565b905060008b821115614ba857614b9d8c8585613d7a565b905060009b50614bd3565b868581518110614bba57614bba615bb7565b60200260200101519050818c614bd09190615cf8565b9b505b614bf78a8681518110614be857614be8615bb7565b6020026020010151828d6138e9565b898581518110614c0957614c09615bb7565b60200260200101516001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed8282604051614c4b91815260200190565b60405180910390a28b600003614c645750505050614c7b565b505050505b80614c7381615be3565b9150506149e0565b5086156149465760405163cc5ea39b60e01b815260048101889052602401610eb0565b8154808210614ce55760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b6044820152606401610eb0565b815b614cf2600183615cf8565b811015614d805783614d05826001615d7b565b81548110614d1557614d15615bb7565b9060005260206000200160009054906101000a90046001600160a01b0316848281548110614d4557614d45615bb7565b600091825260209091200180546001600160a01b0319166001600160a01b039290921691909117905580614d7881615be3565b915050614ce7565b5082805480614d9157614d91615f75565b600082815260209020810160001990810180546001600160a01b0319169055019055505050565b6001600160a01b0382166000908152601660205260408120548015614dfe57600060155482614de79190615d7b565b905043811115614dfc57600092505050610e0f565b505b6000614e08610b04565b90506000614e158261345c565b90506000614e45614e3b886001600160a01b031660009081526020819052604090205490565b610e0a8486615cf8565b90506000600d5460ff166001811115614e6057614e60615a32565b03614e89576000614e6f611fd6565b905080821115614e7f5780614e81565b815b955050614fe0565b600080614e946142f6565b945094505050506000614ea660025490565b90506000614ec98b6001600160a01b031660009081526020819052604090205490565b9050670de0b6b3a764000060005b8451811015614f9257858181518110614ef257614ef2615bb7565b602002602001015160000315614f8057848181518110614f1457614f14615bb7565b6020026020010151600003614f365760009a5050505050505050505050610e0f565b6000614f70670de0b6b3a7640000888481518110614f5657614f56615bb7565b6020026020010151888581518110614b6f57614b6f615bb7565b905082811015614f7e578092505b505b80614f8a81615be3565b915050614ed7565b506000614fa883670de0b6b3a764000086613d7a565b905081811115614fd557614fd082670de0b6b3a7640000614fc98b8d615cf8565b9190613d7a565b614fd7565b865b9a505050505050505b8515614ff757614ff4856126d28486615cf8565b94505b5050505092915050565b6001600160a01b0381166000908152600560205260409020805460018101825590613132565b6000610e0f6150346137c2565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6000806000615086878787876153c5565b91509150615093816154b2565b5095945050505050565b6000610f948383670de0b6b3a7640000613d7a565b6000806150be60025490565b9050828111156131325760006150d48483615cf8565b9050610e5a848383613d4c565b80158061515b5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015615135573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906151599190615cab565b155b6151c65760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610eb0565b6040516001600160a01b038316602482015260448101829052613d4790849063095ea7b360e01b906064016140fe565b60008160ff168360ff160361520c575082610f94565b8160ff168360ff161015615240576152248383615f8b565b61522f90600a615f66565b6152399085615d8e565b9050610f94565b61524a8284615f8b565b61525590600a615f66565b6152399085615dad565b613d478361536a565b6040516001600160a01b038316602482015260448101829052613d4790849063a9059cbb60e01b906064016140fe565b60006152ed826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661566b9092919063ffffffff16565b805190915015613d47578080602001905181019061530b9190615dcf565b613d475760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610eb0565b6001600160a01b0381166000908152601660205260409020548015613f74576000601554826153999190615d7b565b905043811115613d47576040516306f8ee3f60e21b815260048101829052436024820152604401610eb0565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156153fc57506000905060036154a9565b8460ff16601b1415801561541457508460ff16601c14155b1561542557506000905060046154a9565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015615479573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166154a2576000600192509250506154a9565b9150600090505b94509492505050565b60008160048111156154c6576154c6615a32565b036154ce5750565b60018160048111156154e2576154e2615a32565b0361552f5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610eb0565b600281600481111561554357615543615a32565b036155905760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610eb0565b60038160048111156155a4576155a4615a32565b036155fc5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610eb0565b600481600481111561561057615610615a32565b036156685760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610eb0565b50565b6060610e5a8484600085856001600160a01b0385163b6156cd5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610eb0565b600080866001600160a01b031685876040516156e99190615fa4565b60006040518083038185875af1925050503d8060008114615726576040519150601f19603f3d011682016040523d82523d6000602084013e61572b565b606091505b509150915061573b828286615746565b979650505050505050565b60608315615755575081610f94565b8251156157655782518084602001fd5b8160405162461bcd60e51b8152600401610eb091906157a3565b60005b8381101561579a578181015183820152602001615782565b50506000910152565b60208152600082518060208401526157c281604085016020870161577f565b601f01601f19169190910160400192915050565b6000602082840312156157e857600080fd5b5035919050565b6001600160a01b038116811461566857600080fd5b6000806040838503121561581757600080fd5b8235615822816157ef565b946020939093013593505050565b60006020828403121561584257600080fd5b8135610f94816157ef565b60008060006060848603121561586257600080fd5b833561586d816157ef565b9250602084013561587d816157ef565b929592945050506040919091013590565b6002811061566857600080fd5b6000602082840312156158ad57600080fd5b8135610f948161588e565b60008060008060008060a087890312156158d157600080fd5b86356158dc816157ef565b955060208701356158ec816157ef565b94506040870135935060608701356159038161588e565b925060808701356001600160401b038082111561591f57600080fd5b818901915089601f83011261593357600080fd5b81358181111561594257600080fd5b8a602082850101111561595457600080fd5b6020830194508093505050509295509295509295565b60006020828403121561597c57600080fd5b81356001600160401b0381168114610f9457600080fd5b600080604083850312156159a657600080fd5b8235915060208301356159b8816157ef565b809150509250929050565b600080604083850312156159d657600080fd5b50508035926020909101359150565b6020808252825182820181905260009190848201906040850190845b81811015615a265783516001600160a01b031683529284019291840191600101615a01565b50909695505050505050565b634e487b7160e01b600052602160045260246000fd5b6020810160038310615a5c57615a5c615a32565b91905290565b600080600060608486031215615a7757600080fd5b833592506020840135615a89816157ef565b91506040840135615a99816157ef565b809150509250925092565b60ff8116811461566857600080fd5b600080600080600080600060e0888a031215615ace57600080fd5b8735615ad9816157ef565b96506020880135615ae9816157ef565b955060408801359450606088013593506080880135615b0781615aa4565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215615b3757600080fd5b8235615b42816157ef565b915060208301356159b8816157ef565b6002811061566857615668615a32565b60208101615a5c83615b52565b60008060408385031215615b8257600080fd5b8235615b8d816157ef565b91506020830135600381106159b857600080fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201615bf557615bf5615bcd565b5060010190565b600060208284031215615c0e57600080fd5b8151610f94816157ef565b606080825284519082018190526000906020906080840190828801845b82811015615c5b5781516001600160a01b031684529284019290840190600101615c36565b5050508381038285015285518082528683019183019060005b81811015615c9057835183529284019291840191600101615c74565b50506001600160a01b03861660408601529250610e5a915050565b600060208284031215615cbd57600080fd5b5051919050565b600181811c90821680615cd857607f821691505b60208210810361313257634e487b7160e01b600052602260045260246000fd5b81810381811115610e0f57610e0f615bcd565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b60408101615d3e84615b52565b838252615d4a83615b52565b8260208301529392505050565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b80820180821115610e0f57610e0f615bcd565b6000816000190483118215151615615da857615da8615bcd565b500290565b600082615dca57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215615de157600080fd5b81518015158114610f9457600080fd5b600060208284031215615e0357600080fd5b8151610f9481615aa4565b615e1787615b52565b86815260a060208201528460a0820152848660c0830137600060c08683018101919091526001600160a01b039485166040830152928416606082015292166080830152601f909201601f1916010192915050565b600081615e7a57615e7a615bcd565b506000190190565b600181815b80851115615ebd578160001904821115615ea357615ea3615bcd565b80851615615eb057918102915b93841c9390800290615e87565b509250929050565b600082615ed457506001610e0f565b81615ee157506000610e0f565b8160018114615ef75760028114615f0157615f1d565b6001915050610e0f565b60ff841115615f1257615f12615bcd565b50506001821b610e0f565b5060208310610133831016604e8410600b8410161715615f40575081810a610e0f565b615f4a8383615e82565b8060001904821115615f5e57615f5e615bcd565b029392505050565b6000610f9460ff841683615ec5565b634e487b7160e01b600052603160045260246000fd5b60ff8281168282160390811115610e0f57610e0f615bcd565b60008251615fb681846020870161577f565b919091019291505056fea2646970667358221220eba27189ab86bbc5f387e2564b1dcc05ef67fe18030cba1e63b399e331b2806d64736f6c63430008100033

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

000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce083000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000a9962a5bfbea6918e958dee0647e99fd7863b95a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a537465616479204254430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000095374656164794254430000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _registry (address): 0xDffa1443a72Fd3f4e935b93d0C3BFf8FE80cE083
Arg [1] : _asset (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [2] : _positions (address[]): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
Arg [3] : _positionTypes (uint8[]): 0,0
Arg [4] : _holdingPosition (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [5] : _withdrawType (uint8): 1
Arg [6] : _name (string): Steady BTC
Arg [7] : _symbol (string): SteadyBTC
Arg [8] : _strategistPayout (address): 0xA9962a5BfBea6918E958DeE0647E99fD7863b95A

-----Encoded View---------------
19 Constructor Arguments found :
Arg [0] : 000000000000000000000000dffa1443a72fd3f4e935b93d0c3bff8fe80ce083
Arg [1] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000120
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000180
Arg [4] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [6] : 00000000000000000000000000000000000000000000000000000000000001e0
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000220
Arg [8] : 000000000000000000000000a9962a5bfbea6918e958dee0647e99fd7863b95a
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [10] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [11] : 0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [14] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [15] : 000000000000000000000000000000000000000000000000000000000000000a
Arg [16] : 5374656164792042544300000000000000000000000000000000000000000000
Arg [17] : 0000000000000000000000000000000000000000000000000000000000000009
Arg [18] : 5374656164794254430000000000000000000000000000000000000000000000


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.