ETH Price: $2,379.48 (-11.11%)

Contract

0x9400d0E43EAcfbDb11197cA92D32e7aeE03c1508

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Token Holdings

More Info

Private Name Tags

TokenTracker

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Withdraw Lender2716375822024-11-06 12:56:11451 days ago1730897771IN
0x9400d0E4...eE03c1508
0 ETH0.000003150.01
Withdraw Lender2715054382024-11-06 3:41:18451 days ago1730864478IN
0x9400d0E4...eE03c1508
0 ETH0.000024920.141272
Withdraw Borrowe...2715018992024-11-06 3:26:21451 days ago1730863581IN
0x9400d0E4...eE03c1508
0 ETH0.000102730.485326
Withdraw Lender2686677372024-10-28 21:38:58459 days ago1730151538IN
0x9400d0E4...eE03c1508
0 ETH0.000002430.010376
Withdraw Lender2686632562024-10-28 21:20:16459 days ago1730150416IN
0x9400d0E4...eE03c1508
0 ETH0.000002430.01
Withdraw Lender2673910022024-10-25 4:28:01463 days ago1729830481IN
0x9400d0E4...eE03c1508
0 ETH0.000002520.012826
Withdraw Lender2673900452024-10-25 4:24:03463 days ago1729830243IN
0x9400d0E4...eE03c1508
0 ETH0.00000280.017907
Withdraw Lender2673847002024-10-25 4:01:39463 days ago1729828899IN
0x9400d0E4...eE03c1508
0 ETH0.00000180.01
Withdraw Lender2673824562024-10-25 3:52:18463 days ago1729828338IN
0x9400d0E4...eE03c1508
0 ETH0.000001840.01
Withdraw Lender2669217582024-10-23 19:45:04465 days ago1729712704IN
0x9400d0E4...eE03c1508
0 ETH0.000002290.01
Withdraw Lender2669182032024-10-23 19:30:12465 days ago1729711812IN
0x9400d0E4...eE03c1508
0 ETH0.000002380.01
Withdraw Lender2625310252024-10-11 1:13:05477 days ago1728609185IN
0x9400d0E4...eE03c1508
0 ETH0.000002130.01
Withdraw Lender2578777092024-09-27 11:35:52491 days ago1727436952IN
0x9400d0E4...eE03c1508
0 ETH0.000002410.01
Withdraw Lender2578758312024-09-27 11:27:56491 days ago1727436476IN
0x9400d0E4...eE03c1508
0 ETH0.00000230.01
Withdraw Lender2578241902024-09-27 7:52:04491 days ago1727423524IN
0x9400d0E4...eE03c1508
0 ETH0.000002470.01
Withdraw Lender2571897752024-09-25 11:35:10493 days ago1727264110IN
0x9400d0E4...eE03c1508
0 ETH0.000002780.01
Withdraw Lender2571853372024-09-25 11:16:39493 days ago1727262999IN
0x9400d0E4...eE03c1508
0 ETH0.000003130.01
Deposit Lender2543919052024-09-17 8:01:30501 days ago1726560090IN
0x9400d0E4...eE03c1508
0 ETH0.000003220.01
Deposit Lender2543643352024-09-17 6:05:51501 days ago1726553151IN
0x9400d0E4...eE03c1508
0 ETH0.000003140.01
Withdraw Lender2542771832024-09-17 0:00:21501 days ago1726531221IN
0x9400d0E4...eE03c1508
0 ETH0.0000020.01
Withdraw Lender2524465782024-09-11 15:47:50507 days ago1726069670IN
0x9400d0E4...eE03c1508
0 ETH0.000005230.023214
Withdraw Lender2508666292024-09-07 1:23:08511 days ago1725672188IN
0x9400d0E4...eE03c1508
0 ETH0.000002080.01
Deposit Lender2483844872024-08-30 19:48:34519 days ago1725047314IN
0x9400d0E4...eE03c1508
0 ETH0.000003260.01
Deposit Lender2483134182024-08-30 14:50:06519 days ago1725029406IN
0x9400d0E4...eE03c1508
0 ETH0.000008430.026898
Withdraw Lender2430610632024-08-15 8:17:36534 days ago1723709856IN
0x9400d0E4...eE03c1508
0 ETH0.000002880.014938
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CurveTwoCryptoOptimizedLiquidityWarehouse

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 125 runs

Other Settings:
paris EvmVersion
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {LiquidityWarehouse} from "./LiquidityWarehouse.sol";
import {CurveTwoCryptoOptimizedHelperLibrary} from "./CurveTwoCryptoOptimizedHelperLibrary.sol";

contract CurveTwoCryptoOptimizedLiquidityWarehouse is LiquidityWarehouse {
    /// @notice Price deviation threshold
    CurveTwoCryptoOptimizedHelperLibrary.CurveLWVariables internal variables;

    /// @notice Withdraw asset list
    mapping(address curvePool => address withdrawAsset) internal s_withdrawAsset;

    /// @notice Map for asset configuration
    mapping(address asset => CurveTwoCryptoOptimizedHelperLibrary.AssetConfig config) internal s_assetConfigs;

    constructor(
        LiquidityWarehouse.ConstructorParams memory params,
        CurveTwoCryptoOptimizedHelperLibrary.AssetConfigParams[] memory assetConfigs,
        CurveTwoCryptoOptimizedHelperLibrary.WithdrawAssetConfig[] memory withdrawAsset,
        uint256 maxDeviation,
        uint256 extraMargin
    ) LiquidityWarehouse(params) {
        CurveTwoCryptoOptimizedHelperLibrary.setAssetConfigs(assetConfigs, s_assetConfigs);
        CurveTwoCryptoOptimizedHelperLibrary.setWithdrawAsset(withdrawAsset, s_withdrawAsset);
        CurveTwoCryptoOptimizedHelperLibrary.setMaxDeviation(maxDeviation, variables);
        CurveTwoCryptoOptimizedHelperLibrary.setExtraMargin(extraMargin, variables);
    }

    /// @notice Sets asset configurations
    /// @param withdrawAssetConfig Array of struct of curvePool with their withdraw asset
    function setWithdrawAsset(CurveTwoCryptoOptimizedHelperLibrary.WithdrawAssetConfig[] calldata withdrawAssetConfig)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        CurveTwoCryptoOptimizedHelperLibrary.setWithdrawAsset(withdrawAssetConfig, s_withdrawAsset);
    }

    /// @notice Sets asset configurations
    /// @param assetConfigs Array of assets with their configuration

    function setAssetConfigs(CurveTwoCryptoOptimizedHelperLibrary.AssetConfigParams[] calldata assetConfigs)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        CurveTwoCryptoOptimizedHelperLibrary.setAssetConfigs(assetConfigs, s_assetConfigs);
    }

    /// @notice Function to set maxDeviation
    /// @param maxDeviation value of max deviation
    function setMaxDeviation(uint256 maxDeviation) external onlyRole(DEFAULT_ADMIN_ROLE) {
        CurveTwoCryptoOptimizedHelperLibrary.setMaxDeviation(maxDeviation, variables);
    }

    /// @notice Function to set maxDeviation
    /// @param extraMargin value of extra margin
    function setExtraMargin(uint256 extraMargin) external onlyRole(DEFAULT_ADMIN_ROLE) {
        CurveTwoCryptoOptimizedHelperLibrary.setExtraMargin(extraMargin, variables);
    }

    /// @inheritdoc LiquidityWarehouse
    function _withdrawFromTarget(uint256 withdrawAmount, address withdrawTarget, bytes memory)
        internal
        override
        returns (bool)
    {
        return CurveTwoCryptoOptimizedHelperLibrary.withdrawAndSwap(
            CurveTwoCryptoOptimizedHelperLibrary.WithdrawAndSwapParams({
                maxDeviation: variables.maxDeviation,
                withdrawAmount: withdrawAmount,
                extraMargin: variables.extraMargin,
                withdrawTarget: withdrawTarget,
                baseAsset: address(s_terms.asset)
            }),
            s_withdrawAsset,
            s_assetConfigs
        );
    }

    /// @inheritdoc LiquidityWarehouse
    function _getDeployedAssetValue(address withdrawTarget) internal view override returns (uint256) {
        return CurveTwoCryptoOptimizedHelperLibrary.convertToBaseAsset(
            withdrawTarget,
            s_withdrawAsset[withdrawTarget],
            address(s_terms.asset),
            variables.maxDeviation,
            s_assetConfigs
        );
    }

    /// @inheritdoc LiquidityWarehouse
    function _afterExecute(bytes memory data) internal override {}
}

File 2 of 36 : LiquidityWarehouse.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {ILiquidityWarehouse} from "./interfaces/ILiquidityWarehouse.sol";
import {ERC1155Supply} from "openzeppelin/token/ERC1155/extensions/ERC1155Supply.sol";
import {ERC1155} from "openzeppelin/token/ERC1155/ERC1155.sol";
import {EnumerableSet} from "openzeppelin/utils/structs/EnumerableSet.sol";
import {SafeCast} from "openzeppelin/utils/math/SafeCast.sol";
import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
import {LiquidityWarehouseAccessControl} from "./utils/LiquidityWarehouseAccessControl.sol";
import {ReentrancyGuard} from "openzeppelin/security/ReentrancyGuard.sol";
import {Pausable} from "openzeppelin/security/Pausable.sol";
import {MathUtils} from "aave-v3-core/contracts/protocol/libraries/math/MathUtils.sol";
import {WadRayMath} from "aave-v3-core/contracts/protocol/libraries/math/WadRayMath.sol";
import {Math} from "openzeppelin/utils/math/Math.sol";
import {IEmergencyPausable} from "./interfaces/IEmergencyPausable.sol";
import {AccessControlDefaultAdminRules} from "openzeppelin/access/AccessControlDefaultAdminRules.sol";
import {IWETH} from "./vendor/IWETH.sol";

abstract contract LiquidityWarehouse is
    ILiquidityWarehouse,
    IEmergencyPausable,
    ERC1155Supply,
    LiquidityWarehouseAccessControl,
    ReentrancyGuard,
    Pausable,
    AccessControlDefaultAdminRules
{
    using SafeERC20 for IERC20;
    using SafeCast for uint256;
    using EnumerableSet for EnumerableSet.AddressSet;
    using WadRayMath for uint256;

    /// @notice The role required to emergency pause or emergency
    /// unpause the contract
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

    /// @notice The role required to make an initial borrower deposit
    bytes32 public constant PRIMARY_BORROWER_ROLE = keccak256("PRIMARY_BORROWER_ROLE");

    uint256 public constant LENDER_LP_TOKEN_ID = 0;
    uint256 public constant BORROWER_LP_TOKEN_ID = 1;

    /// @notice Struct containing the list of constructor params
    /// to initialize the liquidity warehouse
    struct ConstructorParams {
        /// @notice The liquidity threshold to 18dp
        uint256 liquidationThreshold;
        /// @notice The capacity threshold to 18dp
        uint256 capacityThreshold;
        /// @notice The interest rate to 18dp
        uint256 interestRate;
        /// @notice The interest fee percentage to 18dp
        uint256 interestFee;
        /// @notice The withdrawal fee percentage to 18dp
        uint256 withdrawalFee;
        /// @notice The initial amount of seconds before the default admin role can
        /// be transferred
        uint48 initialDelay;
        /// @notice The address of the asset the loans in the liquidity warehouse
        /// will be denominated in
        address asset;
        /// @notice The address that will receive fees
        address feeRecipient;
        /// @notice The address of the admin
        address initialAdmin;
        /// @notice The address of the wrapped native token
        address wrappedNativeToken;
        /// @notice The uri for the LP tokens
        string uri;
    }

    //###########################//
    //     Storage Variables     //
    //###########################//

    /// @notice The wrapped native token
    IWETH internal immutable i_wrappedNativeToken;

    /// @notice The liquidity warehouse terms
    Terms internal s_terms;

    /// @notice The asset data
    Asset internal s_assetData;

    /// @notice The assets in the liquidity warehouse
    EnumerableSet.AddressSet internal s_assets;

    /// @notice True if the liquidity warehouse is active
    bool internal s_isActive;

    constructor(ConstructorParams memory params)
        ERC1155(params.uri)
        AccessControlDefaultAdminRules(params.initialDelay, params.initialAdmin)
    {
        if (params.asset == address(0)) revert InvalidAsset();
        if (params.wrappedNativeToken == address(0)) revert InvalidWrappedNativeToken();
        i_wrappedNativeToken = IWETH(params.wrappedNativeToken);

        s_terms.asset = IERC20(params.asset);
        _setCapacityThreshold(params.capacityThreshold);
        _setLiquidationThreshold(params.liquidationThreshold);
        _setInterestFee(params.interestFee);
        _setWithdrawalFee(params.withdrawalFee);
        _setFeeRecipient(params.feeRecipient);
        _setInterestRate(params.interestRate);
    }

    /// @inheritdoc ERC1155
    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override(AccessControlDefaultAdminRules, ERC1155)
        returns (bool)
    {
        return AccessControlDefaultAdminRules.supportsInterface(interfaceId) || ERC1155.supportsInterface(interfaceId);
    }

    /// @notice Receive function to allow liquidity warehouse to receive native tokens
    receive() external payable {
        // Automatically wrap native tokens
        i_wrappedNativeToken.deposit{value: msg.value}();
    }

    //############################//
    //    Deposits/Withdrawals    //
    //############################//

    /// @inheritdoc ILiquidityWarehouse
    function deactivate(address[] calldata withdrawTargets, bytes calldata data) external {
        if (!s_isActive) revert Inactive();
        if (_isLiquidationThresholdFulfilled()) revert LiquidationThresholdNotBreached();
        _compoundInterest();
        s_isActive = false;
        _withdrawAllFromTargets(withdrawTargets, data);
        emit Deactivated();
    }

    /// @inheritdoc ILiquidityWarehouse
    function activate() external {
        if (s_isActive) revert Active();
        if (!_isLiquidationThresholdFulfilled()) revert LiquidationThresholdBreached();

        // Set interestLastUpdatedAt to current time to prevent
        // interest from accruing from the last time the
        // liquidity warehouse was deactivated
        s_assetData.interestLastUpdatedAt = block.timestamp.toUint40();
        _activate();
    }

    /// @inheritdoc ILiquidityWarehouse
    function liquidate(address[] calldata withdrawTargets, bytes calldata data) external {
        if (s_isActive) revert Active();
        _withdrawAllFromTargets(withdrawTargets, data);
    }

    /// @inheritdoc ILiquidityWarehouse
    function depositLender(uint256 depositAmount) external whenNotPaused nonReentrant {
        if (getBorrowerNetAssetValue() == 0) revert CapacityThresholdBreached();
        _compoundInterest();

        uint256 shareAmt = _convertToShares(totalSupply(LENDER_LP_TOKEN_ID), getLenderNetAssetValue(), depositAmount);
        if (shareAmt == 0) revert ZeroShareAmt();
        s_assetData.lenderBalance += depositAmount.toUint216();

        s_terms.asset.safeTransferFrom(msg.sender, address(this), depositAmount);
        _mint(msg.sender, LENDER_LP_TOKEN_ID, shareAmt, bytes(""));

        if (!_isCapacityThresholdFulfilled()) {
            revert CapacityThresholdBreached();
        }
        emit AssetDeposited(depositAmount, false);
    }

    /// @inheritdoc ILiquidityWarehouse
    function depositBorrower(uint256 depositAmount) external whenNotPaused nonReentrant {
        _compoundInterest();

        uint256 shareAmt =
            _convertToShares(totalSupply(BORROWER_LP_TOKEN_ID), getBorrowerNetAssetValue(), depositAmount);

        if (shareAmt == 0) revert ZeroShareAmt();
        if (totalSupply(BORROWER_LP_TOKEN_ID) == 0 && !hasRole(PRIMARY_BORROWER_ROLE, msg.sender)) {
            revert AccessForbidden();
        }

        s_terms.asset.safeTransferFrom(msg.sender, address(this), depositAmount);
        _mint(msg.sender, BORROWER_LP_TOKEN_ID, shareAmt, bytes(""));

        if (_isLiquidationThresholdFulfilled()) {
            _activate();
        }
        emit AssetDeposited(depositAmount, true);
    }

    /// @inheritdoc ILiquidityWarehouse
    function withdrawLender(uint256 shareAmount, bytes calldata data) external nonReentrant {
        if (msg.sender == s_terms.feeRecipient) revert AccessForbidden();
        _compoundInterest();

        if (shareAmount > balanceOf(msg.sender, LENDER_LP_TOKEN_ID)) revert InsufficientBalance();
        uint256 withdrawableAmount =
            _convertToAssets(totalSupply(LENDER_LP_TOKEN_ID), getLenderNetAssetValue(), shareAmount);

        uint256 actualWithdrawableAmount = withdrawableAmount - _withdrawFromTargets(withdrawableAmount, data);

        uint256 feeAmount = uint256(s_terms.withdrawalFee).wadMul(actualWithdrawableAmount);

        /// Subtract by the full withdrawableAmount to account for any losses from withdrawing
        /// from any target contracts on the borrower's protocol.  The fee amount should still
        /// be calculated based on the actual amount withdrawn from the borrower protocol.
        s_assetData.lenderBalance -= (withdrawableAmount - feeAmount).toUint216();

        uint256 feeShares = feeAmount * shareAmount / withdrawableAmount;

        _safeTransferFrom(msg.sender, s_terms.feeRecipient, LENDER_LP_TOKEN_ID, feeShares, bytes(""));
        _burn(msg.sender, LENDER_LP_TOKEN_ID, shareAmount - feeShares);

        s_terms.asset.safeTransfer(msg.sender, actualWithdrawableAmount - feeAmount);
        emit AssetWithdrawn(actualWithdrawableAmount - feeAmount, false);
    }

    /// @inheritdoc ILiquidityWarehouse
    function withdrawLenderFees(bytes calldata data) external nonReentrant onlyFeeRecipient {
        _compoundInterest();

        uint256 shareAmount = balanceOf(s_terms.feeRecipient, LENDER_LP_TOKEN_ID);
        uint256 withdrawableAmount =
            _convertToAssets(totalSupply(LENDER_LP_TOKEN_ID), getLenderNetAssetValue(), shareAmount);

        s_assetData.lenderBalance -= withdrawableAmount.toUint216();
        withdrawableAmount -= _withdrawFromTargets(withdrawableAmount, data);

        _burn(msg.sender, LENDER_LP_TOKEN_ID, shareAmount);
        s_terms.asset.safeTransfer(msg.sender, withdrawableAmount);
        emit AssetWithdrawn(withdrawableAmount, false);
    }

    /// @inheritdoc ILiquidityWarehouse
    function withdrawBorrower(uint256 shareAmount, bytes calldata data) external nonReentrant {
        if (msg.sender == s_terms.feeRecipient) revert AccessForbidden();
        _compoundInterest();

        if (shareAmount > balanceOf(msg.sender, BORROWER_LP_TOKEN_ID)) revert InsufficientBalance();

        uint256 withdrawableAmount =
            _convertToAssets(totalSupply(BORROWER_LP_TOKEN_ID), getBorrowerNetAssetValue(), shareAmount);

        withdrawableAmount -= _withdrawFromTargets(withdrawableAmount, data);

        uint256 withdrawalFee = uint256(s_terms.withdrawalFee);
        uint256 feeAmount = withdrawalFee.wadMul(withdrawableAmount);
        uint256 withdrawableAmountAfterFee = withdrawableAmount - feeAmount;

        _safeTransferFrom(
            msg.sender, s_terms.feeRecipient, BORROWER_LP_TOKEN_ID, withdrawalFee.wadMul(shareAmount), bytes("")
        );
        _burn(msg.sender, BORROWER_LP_TOKEN_ID, shareAmount - withdrawalFee.wadMul(shareAmount));
        s_terms.asset.safeTransfer(msg.sender, withdrawableAmountAfterFee);

        if (s_isActive && !_isCapacityThresholdFulfilled()) {
            revert CapacityThresholdBreached();
        }

        emit AssetWithdrawn(withdrawableAmountAfterFee, true);
    }

    /// @inheritdoc ILiquidityWarehouse
    function withdrawBorrowerFees(bytes calldata data) external nonReentrant onlyFeeRecipient {
        _compoundInterest();

        uint256 shareAmount = balanceOf(s_terms.feeRecipient, BORROWER_LP_TOKEN_ID);
        uint256 withdrawableAmount =
            _convertToAssets(totalSupply(BORROWER_LP_TOKEN_ID), getBorrowerNetAssetValue(), shareAmount);

        withdrawableAmount -= _withdrawFromTargets(withdrawableAmount, data);
        _burn(msg.sender, BORROWER_LP_TOKEN_ID, shareAmount);
        s_terms.asset.safeTransfer(msg.sender, withdrawableAmount);
        emit AssetWithdrawn(withdrawableAmount, true);
    }

    //####################################//
    // Liquidity Warehouse Access Control //
    //####################################//

    /// @inheritdoc ILiquidityWarehouse
    function toggleWhitelist(LiquidityWarehouseAccessControl.Action[] calldata actions)
        external
        override
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        _toggleWhitelist(actions);
    }

    /// @inheritdoc ILiquidityWarehouse
    function execute(LiquidityWarehouseAccessControl.ExecuteAction[] calldata executeActions, bytes calldata data)
        external
        payable
        override
        nonReentrant
    {
        _execute(executeActions, msg.sender == owner());
        _afterExecute(data);
    }

    /// @inheritdoc ILiquidityWarehouse
    function isWhitelisted(address target, address caller, bytes4 fnSelector) external view override returns (bool) {
        return _isWhitelisted(target, caller, fnSelector);
    }

    //################//
    //    Set Terms   //
    //################//

    /// @inheritdoc ILiquidityWarehouse
    function setLiquidationThreshold(uint256 liquidationThreshold) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _setLiquidationThreshold(liquidationThreshold);
    }

    /// @inheritdoc ILiquidityWarehouse
    function setCapacityThreshold(uint256 capacityThreshold) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _setCapacityThreshold(capacityThreshold);
    }

    /// @inheritdoc ILiquidityWarehouse
    function setInterestFee(uint256 fee) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _compoundInterest();
        _setInterestFee(fee);
    }

    /// @inheritdoc ILiquidityWarehouse
    function setWithdrawalFee(uint256 fee) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _setWithdrawalFee(fee);
    }

    /// @inheritdoc ILiquidityWarehouse
    function setFeeRecipient(address feeRecipient) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _compoundInterest();
        _setFeeRecipient(feeRecipient);
    }

    /// @inheritdoc ILiquidityWarehouse
    function setInterestRate(uint256 interestRate) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _compoundInterest();
        _setInterestRate(interestRate);
    }

    //################//
    //    Pausable    //
    //################//

    /// @inheritdoc IEmergencyPausable
    function emergencyPause() external onlyRole(PAUSER_ROLE) whenNotPaused {
        _pause();
    }

    /// @inheritdoc IEmergencyPausable
    function emergencyUnpause() external onlyRole(PAUSER_ROLE) whenPaused {
        _unpause();
    }

    //############//
    //    View    //
    //############//

    /// @inheritdoc ILiquidityWarehouse
    function isPaused() external view returns (bool) {
        return paused();
    }

    /// @inheritdoc ILiquidityWarehouse
    function convertToAssets(bool isBorrower, uint256 shareAmount) external view returns (uint256) {
        uint256 lpTokenId = isBorrower ? BORROWER_LP_TOKEN_ID : LENDER_LP_TOKEN_ID;
        uint256 totalAssetAmount = isBorrower ? getBorrowerNetAssetValue() : getLenderNetAssetValue();
        return _convertToAssets(totalSupply(lpTokenId), totalAssetAmount, shareAmount);
    }

    /// @inheritdoc ILiquidityWarehouse
    function convertToShares(bool isBorrower, uint256 assetAmount) external view returns (uint256) {
        uint256 lpTokenId = isBorrower ? BORROWER_LP_TOKEN_ID : LENDER_LP_TOKEN_ID;
        uint256 totalAssetAmount = isBorrower ? getBorrowerNetAssetValue() : getLenderNetAssetValue();
        return _convertToShares(totalSupply(lpTokenId), totalAssetAmount, assetAmount);
    }

    /// @inheritdoc ILiquidityWarehouse
    function getLenderBalance() public view returns (uint256) {
        uint256 lenderBalance = s_assetData.lenderBalance;
        if (!s_isActive) return lenderBalance;
        uint256 compoundedInterest = MathUtils.calculateCompoundedInterest(
            uint256(s_terms.interestRate).wadToRay(), s_assetData.interestLastUpdatedAt, block.timestamp
        ).rayToWad();
        return lenderBalance.wadMul(compoundedInterest);
    }

    /// @inheritdoc ILiquidityWarehouse
    function getTerms() external view returns (Terms memory) {
        return s_terms;
    }

    /// @inheritdoc ILiquidityWarehouse
    function getNetAssetValue() public view returns (uint256) {
        address[] memory withdrawTargets = _getWithdrawableTargets();

        uint256 nav;
        /// We acknowledge that this may be gas intensive but we do not foresee there being
        /// a high number of withdraw targets
        for (uint256 i; i < withdrawTargets.length; ++i) {
            nav += _getDeployedAssetValue(withdrawTargets[i]);
        }

        return s_terms.asset.balanceOf(address(this)) + nav;
    }

    /// @inheritdoc ILiquidityWarehouse
    function getLenderNetAssetValue() public view returns (uint256) {
        return Math.min(getNetAssetValue(), getLenderBalance());
    }

    /// @inheritdoc ILiquidityWarehouse
    function getBorrowerNetAssetValue() public view returns (uint256) {
        return getNetAssetValue() - getLenderNetAssetValue();
    }

    /// @inheritdoc ILiquidityWarehouse
    function isLiquidationThresholdFulfilled() external view returns (bool) {
        return _isLiquidationThresholdFulfilled();
    }

    /// @inheritdoc ILiquidityWarehouse
    function isCapacityThresholdFulfilled() external view returns (bool) {
        return _isCapacityThresholdFulfilled();
    }

    /// @inheritdoc ILiquidityWarehouse
    function getWithdrawTargets() external view returns (address[] memory) {
        return s_withdrawTargets.values();
    }

    /// @inheritdoc ILiquidityWarehouse
    function isActive() external view returns (bool) {
        return s_isActive;
    }

    //################//
    //    Internal    //
    //################//

    /// @notice Hook to run before withdrawals are processed
    /// @param withdrawAmount The amount to withdraw from the target
    /// @param withdrawTarget The target address to withdraw from
    /// @param data Arbitrary data that can be used by the underlying implementation
    /// @return bool Returns true if should stop withdrawing from the next withdraw target
    function _withdrawFromTarget(uint256 withdrawAmount, address withdrawTarget, bytes memory data)
        internal
        virtual
        returns (bool);

    /// @notice Converts assets to share value
    /// @param totalShareAmount The total amount of minted shares
    /// @param totalAssetAmount The total amount of owed assets
    /// @param assetAmount The amount of assets to convert to shares
    /// @return uint256 The number of shares
    function _convertToShares(uint256 totalShareAmount, uint256 totalAssetAmount, uint256 assetAmount)
        internal
        pure
        returns (uint256)
    {
        if (totalShareAmount == 0) return assetAmount; // Handle case when no shares have been minted yet
        return assetAmount * totalShareAmount / totalAssetAmount;
    }

    /// @notice Converts shares to the asset value
    /// @param totalShareAmount The total amount of minted shares
    /// @param totalAssetAmount The total amount of owed assets
    /// @param shareAmount The amount of shares to convert to assets
    /// @return uint256 The number of assets
    function _convertToAssets(uint256 totalShareAmount, uint256 totalAssetAmount, uint256 shareAmount)
        internal
        pure
        returns (uint256)
    {
        if (totalShareAmount == 0) return 0;
        return shareAmount * totalAssetAmount / totalShareAmount;
    }

    /// @notice Updates the lender's balance with the interest owed
    function _compoundInterest() internal {
        uint256 lenderBalanceBefore = uint256(s_assetData.lenderBalance);
        uint40 interestLastUpdatedAt = s_assetData.interestLastUpdatedAt;
        s_assetData.interestLastUpdatedAt = block.timestamp.toUint40();

        if (lenderBalanceBefore > 0 && s_isActive && block.timestamp > interestLastUpdatedAt) {
            uint256 compoundedInterest = MathUtils.calculateCompoundedInterest(
                uint256(s_terms.interestRate).wadToRay(), interestLastUpdatedAt, block.timestamp
            ).rayToWad();
            s_assetData.lenderBalance = lenderBalanceBefore.wadMul(compoundedInterest).toUint216();
            uint256 earnedFeeAmount =
                uint256(s_terms.interestFee).wadMul(s_assetData.lenderBalance - lenderBalanceBefore);

            // There is an edge case for when the net asset value of the liquidity warehouse is less
            // than the lender's owed balance.  In this case the interest will continue to compound and a portion
            // of the fees will be minted to the fee recipient address even though the lender's net asset value is
            // capped at the liquidity warehouse's net asset value.  We expect this to be fine as in such cases
            // the liquidity warehouse will most likely be deactivated and interest will stop accruing so the
            // losses will be minimal.
            uint256 feeShareAmount =
                earnedFeeAmount * totalSupply(LENDER_LP_TOKEN_ID) / (s_assetData.lenderBalance - earnedFeeAmount);

            _mint(s_terms.feeRecipient, LENDER_LP_TOKEN_ID, feeShareAmount, bytes(""));
        }
    }

    /// @notice Updates the interest rate
    /// @param interestRate The new interest rate
    function _setInterestRate(uint256 interestRate) internal {
        uint256 oldInterestRate = s_terms.interestRate;
        s_terms.interestRate = interestRate.toUint64();
        emit InterestRateSet(oldInterestRate, interestRate);
    }

    /// @notice Updates the liquidation threshold
    /// @param liquidationThreshold The new liquidation threshold
    function _setLiquidationThreshold(uint256 liquidationThreshold) internal {
        uint256 oldLiquidationThreshold = s_terms.liquidationThreshold;
        s_terms.liquidationThreshold = liquidationThreshold.toUint64();
        emit LiquidationThresholdSet(oldLiquidationThreshold, liquidationThreshold);
    }

    /// @notice Updates the capacity threshold
    /// @param capacityThreshold The new capacity threshold
    function _setCapacityThreshold(uint256 capacityThreshold) internal {
        if (capacityThreshold < s_terms.liquidationThreshold) {
            revert InvalidCapacityThreshold();
        }
        uint256 oldCapacityThreshold = s_terms.capacityThreshold;
        s_terms.capacityThreshold = capacityThreshold.toUint64();
        emit CapacityThresholdSet(oldCapacityThreshold, capacityThreshold);
    }

    /// @notice Updates the interest fee
    /// @param fee The new interest fee
    function _setInterestFee(uint256 fee) internal {
        uint256 oldFee = s_terms.interestFee;
        s_terms.interestFee = fee.toUint64();
        emit InterestFeeSet(oldFee, fee);
    }

    /// @notice Updates the fee taken from withdrawals
    /// @param fee The new withdrawal fee
    function _setWithdrawalFee(uint256 fee) internal {
        uint256 oldFee = s_terms.withdrawalFee;
        s_terms.withdrawalFee = fee.toUint64();
        emit WithdrawalFeeSet(oldFee, fee);
    }

    /// @notice Updates the fee recipient
    /// @param feeRecipient The new fee recipient
    function _setFeeRecipient(address feeRecipient) internal {
        if (feeRecipient == address(0)) revert InvalidFeeRecipient();
        address oldFeeRecipient = s_terms.feeRecipient;
        s_terms.feeRecipient = feeRecipient;
        emit FeeRecipientSet(oldFeeRecipient, feeRecipient);
    }

    /// @notice Determines if the capacity threshold is fulfilled
    /// @return bool True if the capacity threshold is fulfilled
    function _isCapacityThresholdFulfilled() internal view returns (bool) {
        uint256 totalNetAssetValue = getNetAssetValue();
        uint256 borrowerNetAssetValue = getBorrowerNetAssetValue();
        return totalNetAssetValue > 0 && borrowerNetAssetValue.wadDiv(totalNetAssetValue) > s_terms.capacityThreshold;
    }

    /// @notice Determines if the liquidation threshold is fulfilled
    /// @return bool True if the liquidation threshold is fulfilled
    function _isLiquidationThresholdFulfilled() internal view returns (bool) {
        uint256 totalNetAssetValue = getNetAssetValue();
        uint256 borrowerNetAssetValue = getBorrowerNetAssetValue();
        return totalNetAssetValue > 0 && borrowerNetAssetValue.wadDiv(totalNetAssetValue) > s_terms.liquidationThreshold;
    }

    /// @notice Withdraws from all whitelisted pools
    /// @param withdrawTargets The target addresses to try withdraw from
    /// @param data Arbitrary data that can be used by the underlying implementation
    function _withdrawAllFromTargets(address[] memory withdrawTargets, bytes memory data) internal {
        uint256 numWithdrawTargets = withdrawTargets.length;
        for (uint256 i; i < numWithdrawTargets; ++i) {
            address withdrawTarget = withdrawTargets[i];
            if (!s_withdrawTargets.contains(withdrawTarget)) revert InvalidWithdrawTarget(withdrawTarget);
            _withdrawFromTarget(type(uint256).max, withdrawTarget, data);
        }
    }

    /// @notice Withdraws from a list of withdraw target addresses
    /// @param withdrawAmount The amount to withdraw
    /// @param data Arbitrary data that can be used by the underlying implementation
    /// @return uint256 The amount of missing dust
    function _withdrawFromTargets(uint256 withdrawAmount, bytes memory data) internal returns (uint256) {
        uint256 currentAssetBalance = s_terms.asset.balanceOf(address(this));
        if (currentAssetBalance > withdrawAmount) return 0;

        uint256 missingWithdrawableAmount = withdrawAmount - currentAssetBalance;

        uint256 idx;
        bool shouldStopWithdrawing;
        while (!shouldStopWithdrawing && idx < s_withdrawTargets.values().length) {
            shouldStopWithdrawing = _withdrawFromTarget(missingWithdrawableAmount, s_withdrawTargets.at(idx), data);
            currentAssetBalance = s_terms.asset.balanceOf(address(this));
            missingWithdrawableAmount = currentAssetBalance > withdrawAmount ? 0 : withdrawAmount - currentAssetBalance;
            ++idx;
        }

        (uint256 maxLossAmount) = abi.decode(data, (uint256));
        if (missingWithdrawableAmount > maxLossAmount) revert InsufficientLiquidity(missingWithdrawableAmount);
        return missingWithdrawableAmount;
    }

    /// @notice Activate the liquidity warehouse
    function _activate() internal {
        s_isActive = true;
        emit Activated();
    }

    /// @notice Fetches the net asset value for the assets deployed
    /// @param withdrawTarget The address to read the deployed asset value from
    /// @return uint256 The asset's net asset value
    function _getDeployedAssetValue(address withdrawTarget) internal view virtual returns (uint256);

    /// @notice Hook to run after execute
    function _afterExecute(bytes memory data) internal virtual;

    //################//
    //    Modifiers   //
    //################//

    modifier onlyFeeRecipient() {
        if (msg.sender != s_terms.feeRecipient) revert AccessForbidden();
        _;
    }
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {ICurveTwocryptoOptimized} from "./vendor/curve/ICurveTwocryptoOptimized.sol";
import {ICurveStableSwapNG} from "./vendor/curve/ICurveStableSwapNG.sol";
import {IERC20Metadata} from "openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";

library CurveTwoCryptoOptimizedHelperLibrary {
    /// @notice This error is thrown when asset is not found in curve pool's index
    error AssetNotFound(address asset);

    /// @notice This error is thrown when asset config argument is invalid
    error InvalidAssetConfig();

    /// @notice This error is thrown when price deviation surpass max deviation threshold
    error PriceDeviationTooHigh();

    /// @notice Asset configuration params
    struct AssetConfigParams {
        /// @notice Asset contract address
        address asset;
        /// @notice Asset configuration
        AssetConfig assetConfig;
    }

    /// @notice Asset configuration
    struct AssetConfig {
        /// @notice Swap pool id
        /// @dev 0 for StableSwapNg
        /// @dev 1 for TwoCryptoOptimized
        uint8 id;
        /// @notice Asset path fee
        uint24 fee;
        /// @notice Asset swap slippage
        uint128 slippage;
        /// @notice Curve Swap Pool
        address curveSwapPool;
    }

    /// @notice Asset withdraw configuration
    struct WithdrawAssetConfig {
        /// @notice withdraw asset curve pool
        address curvePool;
        /// @notice withdraw asset address
        address withdrawAsset;
    }

    /// @notice WithdrawAndSwap parameters
    struct WithdrawAndSwapParams {
        /// @notice Max deviation threshold
        uint256 maxDeviation;
        /// @notice Withdraw amount in base asset decimals
        uint256 withdrawAmount;
        /// @notice Extra margin to counter slippage
        uint256 extraMargin;
        /// @notice Withdraw target address
        address withdrawTarget;
        /// @notice Base asset address
        address baseAsset;
    }

    /// @notice SwapToBaseAsset parameters
    struct SwapToBaseAssetParams {
        /// @notice Initial asset address
        address asset;
        /// @notice Base asset address
        address baseAsset;
        /// @notice Max deviation threshold
        uint256 maxDeviation;
    }

    /// @notice Curve Pool paramater to get expected exchange amount
    struct CurvePoolExpectationParams {
        /// @notice Curve pool address
        address poolAddress;
        /// @notice assetIn Address that want to be swap
        address assetIn;
        /// @notice assetOut Address of received asset
        address assetOut;
        /// @notice Amount of received asset
        uint256 amount;
        /// @notice Max deviation threshold
        uint256 maxDeviation;
    }

    /// @notice Curve LW variables
    struct CurveLWVariables {
        /// @notice Max deviation threshold
        uint256 maxDeviation;
        /// @notice Withdraw extra margin
        uint256 extraMargin;
    }

    /// @notice This event emitted when max deviation is changed
    /// @param maxDeviation new maxDeviation value
    event MaxDeviationSet(uint256 maxDeviation);

    /// @notice This event emitted when max deviation is changed
    /// @param extraMargin new maxDeviation value
    event ExtraMarginSet(uint256 extraMargin);

    /// @notice Sets assets with their configuration
    /// @param assetConfigs Array of assets with config
    /// @param s_assetConfigs Mapping asset to its config
    function setAssetConfigs(
        AssetConfigParams[] memory assetConfigs,
        mapping(address asset => AssetConfig config) storage s_assetConfigs
    ) public {
        for (uint256 i; i < assetConfigs.length; ++i) {
            AssetConfigParams memory assetConfigParams = assetConfigs[i];
            if (assetConfigParams.asset == address(0)) {
                revert InvalidAssetConfig();
            }
            s_assetConfigs[assetConfigParams.asset] = assetConfigParams.assetConfig;
        }
    }

    /// @notice Sets asset configurations
    /// @param withdrawAssetConfig Array of struct of curvePool with their withdraw asset
    /// @param s_withdrawAsset Mapping for curvePool to their desired withdraw asset
    function setWithdrawAsset(
        WithdrawAssetConfig[] memory withdrawAssetConfig,
        mapping(address curvePool => address withdrawAsset) storage s_withdrawAsset
    ) public {
        for (uint256 i; i < withdrawAssetConfig.length; ++i) {
            s_withdrawAsset[withdrawAssetConfig[i].curvePool] = withdrawAssetConfig[i].withdrawAsset;
        }
    }

    /// @notice Function to set maxDeviation
    /// @param maxDeviation New max deviation value
    /// @param variables Struct for all LWs variable
    function setMaxDeviation(uint256 maxDeviation, CurveLWVariables storage variables) public {
        variables.maxDeviation = maxDeviation;

        emit MaxDeviationSet(maxDeviation);
    }

    /// @notice Function to set maxDeviation
    /// @param extraMargin New max deviation value
    /// @param variables Struct for all LWs variable
    function setExtraMargin(uint256 extraMargin, CurveLWVariables storage variables) public {
        variables.extraMargin = extraMargin;

        emit ExtraMarginSet(extraMargin);
    }

    /// @notice Function to withdraw curve lp token and swap it to desired asset
    /// @param params Struct for WithdrawAndSwap base parameters
    /// @param s_withdrawAsset Mapping for curvePool to their desired withdraw asset
    /// @param s_assetConfigs Mapping asset to its config
    function withdrawAndSwap(
        WithdrawAndSwapParams memory params,
        mapping(address curvePool => address withdrawAsset) storage s_withdrawAsset,
        mapping(address asset => AssetConfig config) storage s_assetConfigs
    ) public returns (bool) {
        ICurveTwocryptoOptimized curveStableSwapPool = ICurveTwocryptoOptimized(params.withdrawTarget);
        /// check if the price has been manipulated
        _checkPriceTwoCryptoSwapPoolDeviation(curveStableSwapPool, params.maxDeviation);
        address withdrawAsset = s_withdrawAsset[address(curveStableSwapPool)];
        uint256 curvePoolCoinIdx = _getAssetIdxInCurveTwoCryptoSwapPool(curveStableSwapPool, withdrawAsset);
        uint256 withdrawTargetDecimals = IERC20Metadata(params.withdrawTarget).decimals();
        uint256 withdrawAssetDecimals = IERC20Metadata(withdrawAsset).decimals();

        /// @dev Withdraw asset must have Curve Pool with the baseAsset
        if (withdrawAsset != params.baseAsset && params.withdrawAmount != type(uint256).max) {
            if (s_assetConfigs[withdrawAsset].id == 0) {
                params.withdrawAmount = _getCurvePoolExpectedAmountIn(
                    CurvePoolExpectationParams({
                        poolAddress: s_assetConfigs[withdrawAsset].curveSwapPool,
                        assetIn: withdrawAsset,
                        assetOut: params.baseAsset,
                        amount: params.withdrawAmount,
                        maxDeviation: params.maxDeviation
                    })
                );
            }

            if (s_assetConfigs[withdrawAsset].id == 1) {
                params.withdrawAmount = _getCurveSwapPoolExpectedAmountIn(
                    CurvePoolExpectationParams({
                        poolAddress: s_assetConfigs[withdrawAsset].curveSwapPool,
                        assetIn: withdrawAsset,
                        assetOut: params.baseAsset,
                        amount: params.withdrawAmount,
                        maxDeviation: params.maxDeviation
                    })
                );
            }
        }

        uint256 sharePrice =
            curveStableSwapPool.calc_withdraw_one_coin(10 ** (withdrawTargetDecimals), curvePoolCoinIdx);

        uint256 burnAmt = params.withdrawAmount == type(uint256).max
            ? IERC20Metadata(params.withdrawTarget).balanceOf(address(this))
            : (params.withdrawAmount * 10 ** (withdrawTargetDecimals) / sharePrice) * params.extraMargin / 1 ether;

        if (burnAmt > ICurveTwocryptoOptimized(params.withdrawTarget).balanceOf(address(this))) {
            burnAmt = ICurveTwocryptoOptimized(params.withdrawTarget).balanceOf(address(this));
        }

        uint256 minReceivedShares = withdrawTargetDecimals > withdrawAssetDecimals
            ? burnAmt / 10 ** (withdrawTargetDecimals - withdrawAssetDecimals) * s_assetConfigs[withdrawAsset].slippage
                / 1 ether
            : burnAmt * 10 ** (withdrawAssetDecimals - withdrawTargetDecimals) * s_assetConfigs[withdrawAsset].slippage
                / 1 ether;

        uint256 receivedAmount;

        receivedAmount = curveStableSwapPool.remove_liquidity_one_coin(
            burnAmt, curvePoolCoinIdx, curveStableSwapPool.calc_withdraw_one_coin(minReceivedShares, curvePoolCoinIdx)
        );

        if (withdrawAsset != address(params.baseAsset)) {
            receivedAmount = _swapToBaseAsset(
                SwapToBaseAssetParams({
                    asset: withdrawAsset,
                    baseAsset: address(params.baseAsset),
                    maxDeviation: params.maxDeviation
                }),
                s_assetConfigs
            );
        }

        return params.withdrawAmount <= receivedAmount;
    }

    /// @notice Function to convert lp token to base asset token value
    /// @param withdrawTarget Withdraw target address
    /// @param withdrawAsset Withdraw asset address
    /// @param baseAsset Base asset address
    /// @param maxDeviation Max deviation threshold
    /// @param s_assetConfigs Mapping asset to its config
    /// @return uint256 Withdraw asset in base asset value
    function convertToBaseAsset(
        address withdrawTarget,
        address withdrawAsset,
        address baseAsset,
        uint256 maxDeviation,
        mapping(address asset => AssetConfig config) storage s_assetConfigs
    ) public view returns (uint256) {
        ICurveTwocryptoOptimized curveSwapPool = ICurveTwocryptoOptimized(withdrawTarget);
        /// check if the price has been manipulated
        _checkPriceTwoCryptoSwapPoolDeviation(curveSwapPool, maxDeviation);

        if (ICurveTwocryptoOptimized(withdrawTarget).balanceOf(address(this)) == 0) {
            return 0;
        }

        if (withdrawAsset != baseAsset) {
            if (s_assetConfigs[withdrawAsset].id == 0) {
                return _getCurveStableSwapPoolExpectedAmountOut(
                    CurvePoolExpectationParams({
                        poolAddress: s_assetConfigs[withdrawAsset].curveSwapPool,
                        assetIn: withdrawAsset,
                        assetOut: address(baseAsset),
                        amount: curveSwapPool.calc_withdraw_one_coin(
                            ICurveTwocryptoOptimized(withdrawTarget).balanceOf(address(this)),
                            _getAssetIdxInCurveTwoCryptoSwapPool(curveSwapPool, withdrawAsset)
                        ),
                        maxDeviation: maxDeviation
                    })
                );
            }

            if (s_assetConfigs[withdrawAsset].id == 1) {
                return _getCurveTwoCryptoSwapPoolExpectedAmountOut(
                    CurvePoolExpectationParams({
                        poolAddress: s_assetConfigs[withdrawAsset].curveSwapPool,
                        assetIn: withdrawAsset,
                        assetOut: address(baseAsset),
                        amount: curveSwapPool.calc_withdraw_one_coin(
                            ICurveTwocryptoOptimized(withdrawTarget).balanceOf(address(this)),
                            _getAssetIdxInCurveTwoCryptoSwapPool(curveSwapPool, withdrawAsset)
                        ),
                        maxDeviation: maxDeviation
                    })
                );
            }
        }

        return curveSwapPool.calc_withdraw_one_coin(
            ICurveTwocryptoOptimized(withdrawTarget).balanceOf(address(this)),
            _getAssetIdxInCurveTwoCryptoSwapPool(curveSwapPool, address(baseAsset))
        );
    }

    /// @notice Function to swap asset to base asset
    /// @param params Struct for functions base parameters
    /// @param s_assetConfigs Mapping asset to its config
    function _swapToBaseAsset(
        SwapToBaseAssetParams memory params,
        mapping(address asset => AssetConfig config) storage s_assetConfigs
    ) internal returns (uint256) {
        uint256 assetBalance = IERC20Metadata(params.asset).balanceOf(address(this));

        if (assetBalance > 0) {
            uint256 slippage = s_assetConfigs[params.asset].slippage;

            if (s_assetConfigs[params.asset].id == 0) {
                uint256 assetOutExpected = _getCurveStableSwapPoolExpectedAmountOut(
                    CurvePoolExpectationParams({
                        poolAddress: s_assetConfigs[params.asset].curveSwapPool,
                        assetIn: params.asset,
                        assetOut: params.baseAsset,
                        amount: assetBalance,
                        maxDeviation: params.maxDeviation
                    })
                );

                ICurveStableSwapNG curvePool = ICurveStableSwapNG(s_assetConfigs[params.asset].curveSwapPool);

                return curvePool.exchange(
                    int128(uint128(_getAssetIdxInCurveStableSwapPool(curvePool, params.asset))),
                    int128(uint128(_getAssetIdxInCurveStableSwapPool(curvePool, params.baseAsset))),
                    assetBalance,
                    assetOutExpected * slippage / 1 ether - (assetOutExpected * s_assetConfigs[params.asset].fee / 1e10)
                );
            }

            if (s_assetConfigs[params.asset].id == 1) {
                uint256 assetOutExpected = _getCurveTwoCryptoSwapPoolExpectedAmountOut(
                    CurvePoolExpectationParams({
                        poolAddress: s_assetConfigs[params.asset].curveSwapPool,
                        assetIn: params.asset,
                        assetOut: params.baseAsset,
                        amount: assetBalance,
                        maxDeviation: params.maxDeviation
                    })
                );

                ICurveTwocryptoOptimized curvePool =
                    ICurveTwocryptoOptimized(s_assetConfigs[params.asset].curveSwapPool);

                return curvePool.exchange(
                    _getAssetIdxInCurveTwoCryptoSwapPool(curvePool, params.asset),
                    _getAssetIdxInCurveTwoCryptoSwapPool(curvePool, params.baseAsset),
                    assetBalance,
                    assetOutExpected * slippage / 1 ether - (assetOutExpected * s_assetConfigs[params.asset].fee / 1e10)
                );
            }
        }

        return 0;
    }

    /// @notice Fetches the index of the asset inside the curve stable pool
    /// @param curveStableSwapPool The curve stable swap pool
    /// @param asset The asset to query
    /// @return uint256 The index of the asset
    function _getAssetIdxInCurveStableSwapPool(ICurveStableSwapNG curveStableSwapPool, address asset)
        internal
        view
        returns (uint256)
    {
        uint256 numCoins = curveStableSwapPool.N_COINS();
        for (uint256 i; i < numCoins; ++i) {
            address assetAtIdx = curveStableSwapPool.coins(i);
            if (assetAtIdx == asset) return i;
        }
        revert AssetNotFound(asset);
    }

    /// @notice Fetches the index of the asset inside the curve stable pool
    /// @param curveStableSwapPool The curve stable swap pool
    /// @param asset The asset to query
    /// @return uint256 The index of the asset
    function _getAssetIdxInCurveTwoCryptoSwapPool(ICurveTwocryptoOptimized curveStableSwapPool, address asset)
        internal
        view
        returns (uint256)
    {
        for (uint256 i; i < 2; ++i) {
            address assetAtIdx = curveStableSwapPool.coins(i);
            if (assetAtIdx == asset) return i;
        }
        revert AssetNotFound(asset);
    }

    /// @notice Function to check price deviation between curve pool last_price and price_oracle.
    /// @notice This function prevent sudden price action which can lead to LP token price manipulation
    /// @param curvePool curve pool interface
    /// @param maxDeviation Max deviation threshold
    function _checkStableSwapPoolPriceDeviation(ICurveStableSwapNG curvePool, uint256 maxDeviation) internal view {
        uint256 lastPrice = curvePool.last_price(0);
        uint256 oraclePrice = curvePool.price_oracle(0);

        uint256 deviation = lastPrice > oraclePrice ? lastPrice - oraclePrice : oraclePrice - lastPrice;
        /// revert when deviation between lastPrice and oraclePrice is > than 1%
        if ((deviation * 1 ether / oraclePrice) > maxDeviation) {
            revert PriceDeviationTooHigh();
        }
    }

    /// @notice Function to check price deviation between curve pool last_price and price_oracle.
    /// @notice This function prevent sudden price action which can lead to LP token price manipulation
    /// @param curvePool Curve pool interface
    /// @param maxDeviation Max deviation threshold
    function _checkPriceTwoCryptoSwapPoolDeviation(ICurveTwocryptoOptimized curvePool, uint256 maxDeviation)
        internal
        view
    {
        uint256 lastPrice = curvePool.last_prices();
        uint256 oraclePrice = curvePool.price_oracle();

        uint256 deviation = lastPrice > oraclePrice ? lastPrice - oraclePrice : oraclePrice - lastPrice;
        /// revert when deviation between lastPrice and oraclePrice is > than 1%
        if ((deviation * 1 ether / oraclePrice) > maxDeviation) {
            revert PriceDeviationTooHigh();
        }
    }

    /// @notice Function to get expected amount in for the swap
    /// @param params Struct for functions base parameter
    /// @return uint256 Expected amount in for doing exchange on the curve pool
    function _getCurvePoolExpectedAmountIn(CurvePoolExpectationParams memory params) internal view returns (uint256) {
        ICurveStableSwapNG curvePool = ICurveStableSwapNG(params.poolAddress);
        _checkStableSwapPoolPriceDeviation(curvePool, params.maxDeviation);

        return curvePool.get_dx(
            int128(uint128(_getAssetIdxInCurveStableSwapPool(curvePool, params.assetIn))),
            int128(uint128(_getAssetIdxInCurveStableSwapPool(curvePool, params.assetOut))),
            params.amount
        );
    }

    /// @notice Function to get expected amount in for the swap
    /// @param params Struct for functions base parameter
    /// @return uint256 Expected amount in for doing exchange on the curve pool
    function _getCurveSwapPoolExpectedAmountIn(CurvePoolExpectationParams memory params)
        internal
        view
        returns (uint256)
    {
        ICurveTwocryptoOptimized curvePool = ICurveTwocryptoOptimized(params.poolAddress);
        _checkPriceTwoCryptoSwapPoolDeviation(curvePool, params.maxDeviation);

        return curvePool.get_dx(
            _getAssetIdxInCurveTwoCryptoSwapPool(curvePool, params.assetIn),
            _getAssetIdxInCurveTwoCryptoSwapPool(curvePool, params.assetOut),
            params.amount
        );
    }

    /// @notice Function to get expected amount out after doing a swap
    /// @param params Struct for functions base parameter
    /// @return uint256 Expected amount out for doing exchange on the curve pool
    function _getCurveStableSwapPoolExpectedAmountOut(CurvePoolExpectationParams memory params)
        internal
        view
        returns (uint256)
    {
        ICurveStableSwapNG curvePool = ICurveStableSwapNG(params.poolAddress);

        _checkStableSwapPoolPriceDeviation(curvePool, params.maxDeviation);

        return curvePool.get_dy(
            int128(uint128(_getAssetIdxInCurveStableSwapPool(curvePool, params.assetIn))),
            int128(uint128(_getAssetIdxInCurveStableSwapPool(curvePool, params.assetOut))),
            params.amount
        );
    }

    /// @notice Function to get expected amount in for the swap
    /// @param params Struct for functions base parameter
    /// @return uint256 Expected amount in for doing exchange on the curve pool
    function _getCurveTwoCryptoSwapPoolExpectedAmountOut(CurvePoolExpectationParams memory params)
        internal
        view
        returns (uint256)
    {
        ICurveTwocryptoOptimized curvePool = ICurveTwocryptoOptimized(params.poolAddress);
        _checkPriceTwoCryptoSwapPoolDeviation(curvePool, params.maxDeviation);

        return curvePool.get_dy(
            _getAssetIdxInCurveTwoCryptoSwapPool(curvePool, params.assetIn),
            _getAssetIdxInCurveTwoCryptoSwapPool(curvePool, params.assetOut),
            params.amount
        );
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {LiquidityWarehouseAccessControl} from "../utils/LiquidityWarehouseAccessControl.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";

interface ILiquidityWarehouse {
    /// @notice The data for an asset
    struct Asset {
        /// @notice The lender's total balance
        uint216 lenderBalance;
        /// @notice The last time the asset's lender balance was updated with interest
        uint40 interestLastUpdatedAt;
    }

    /// @notice The terms of the liquidity warehouse
    struct Terms {
        /// @notice The asset the loans in the liquidity
        /// warehouse is denominated in
        IERC20 asset;
        /// @notice The address that will receive fees
        address feeRecipient;
        /// @notice The liquidation threshold of the liquidity warehouse
        uint64 liquidationThreshold;
        /// @notice The capacity threshold of the liquidity warehouse
        uint64 capacityThreshold;
        /// @notice The interest rate of the liquidity warehouse
        uint64 interestRate;
        /// @notice The fee taken from compounded interest of the liquidity warehouse
        uint64 interestFee;
        /// @notice The fee taken from withdrawals
        uint64 withdrawalFee;
    }

    //################//
    //     Errors     //
    //################//

    /// @notice This error is thrown when an address attempts to execute
    /// a transaction that it does not have permissions for
    error AccessForbidden();

    /// @notice This error is thrown when the liquidity warehouse is active
    error Active();

    /// @notice This error is thrown whenever the amount of shares minted
    /// from a deposit is zero
    error ZeroShareAmt();

    /// @notice This error is thrown when the liquidity warehouse is inactive
    error Inactive();

    /// @notice This error is thrown when there is insufficient liquidity in all
    /// whitelisted targets to cover a withdrawal
    /// @param missingAmount The missing amount of liquidity
    error InsufficientLiquidity(uint256 missingAmount);

    /// @notice This error is thrown when the zero address
    /// is passed in as the asset's address
    error InvalidAsset();

    /// @notice This error is thrown when the wrapped native token
    /// address is zero
    error InvalidWrappedNativeToken();

    /// @notice This error is thrown when there is an insufficient
    /// amount of assets that can be withdrawn
    error InsufficientBalance();

    /// @notice This error is thrown when the liquidation threshold
    /// is set to 0
    error InvalidLiquidationThreshold();

    /// @notice This error is thrown when the capacity threshold
    /// is set to 0
    error InvalidCapacityThreshold();

    /// @notice This error is thrown when the fee recipient is set
    /// to the zero address
    error InvalidFeeRecipient();

    /// @notice This error is thrown when the capacity threshold is
    /// breached
    error CapacityThresholdBreached();

    /// @notice This error is thrown when the liquidation threshold
    /// is  breached
    error LiquidationThresholdBreached();

    /// @notice This error is thrown when the liquidation threshold
    /// is not breached
    error LiquidationThresholdNotBreached();

    //################//
    //     Events     //
    //################//

    /// @notice This event is emitted when the is active flag is
    /// set
    /// @param isActive True if the liquidity warehouse has been
    /// set to active
    event IsActiveSet(bool isActive);

    /// @notice This event is emitted when an asset is deposited
    /// @param depositAmount The amount of assets that was deposited
    /// @param isBorrower True if deposited into the borrower pool
    event AssetDeposited(uint256 depositAmount, bool isBorrower);

    /// @notice This event is emitted when an asset is withdrawn
    /// @param withdrawAmount The amount of assets that was withdrawn
    /// @param isBorrower True if withdrawn into the borrower pool
    event AssetWithdrawn(uint256 withdrawAmount, bool isBorrower);

    /// @notice This event is emitted when the liquidation threshold is set
    /// @param oldLiquidationThreshold The old liquidation threshold
    /// @param newLiquidationThreshold The new liquidation threshold
    event LiquidationThresholdSet(uint256 oldLiquidationThreshold, uint256 newLiquidationThreshold);

    /// @notice This event is emitted when the capacity threshold is set
    /// @param oldCapacityThreshold The old capacity threshold
    /// @param newCapacityThreshold The new capacity threshold
    event CapacityThresholdSet(uint256 oldCapacityThreshold, uint256 newCapacityThreshold);

    /// @notice This event is emitted when the interest rate is set
    /// @param oldInterestRate The old interest rate
    /// @param newInterestRate The new interest rate
    event InterestRateSet(uint256 oldInterestRate, uint256 newInterestRate);

    /// @notice This event is emitted when the interest fee is set
    /// @param oldFee The old interest fee
    /// @param newFee The new interest fee
    event InterestFeeSet(uint256 oldFee, uint256 newFee);

    /// @notice This event is emitted when the withdrawal fee is set
    /// @param oldFee The old withdrawal fee
    /// @param newFee The new withdrawal fee
    event WithdrawalFeeSet(uint256 oldFee, uint256 newFee);

    /// @notice This event is emitted when the fee recipient is set
    /// @param oldFeeRecipient The old fee recipient
    /// @param newFeeRecipient The new fee recipient
    event FeeRecipientSet(address indexed oldFeeRecipient, address indexed newFeeRecipient);

    /// @notice This event is emitted when the liquidity warehouse is activated
    event Activated();

    /// @notice This event is emitted when the liquidity warehouse is deactivated
    event Deactivated();

    //################//
    //     Write      //
    //################//

    /// @notice Deactivates pool
    /// @param withdrawTargets The list of targets to withdraw liquidity from
    /// @param data Arbitrary data that can be used when withdrawing
    function deactivate(address[] calldata withdrawTargets, bytes calldata data) external;

    /// @notice Activates pool
    function activate() external;

    /// @notice Withdraws from all whitelisted pools
    /// @param withdrawTargets The list of targets to withdraw liquidity from
    /// @param data Arbitrary data that can be used when withdrawing
    function liquidate(address[] calldata withdrawTargets, bytes calldata data) external;

    /// @notice Deposits ERC20 tokens as a lender
    /// @param depositedAmount The amount of assets to deposit
    function depositLender(uint256 depositedAmount) external;

    /// @notice Deposits ERC20 tokens as a borrower
    /// @param depositedAmount The amount of assets to deposit
    function depositBorrower(uint256 depositedAmount) external;

    /// @notice Withdraws ERC20 tokens as a lender
    /// @param shareAmount The amount of shares to burn
    /// @param data Arbitrary data that can be used by the underlying implementation
    function withdrawLender(uint256 shareAmount, bytes calldata data) external;

    /// @notice Withdraws lender fees
    /// there is insufficient liquidity in the warehouse
    /// @param data Arbitrary data that can be used by the underlying implementation
    function withdrawLenderFees(bytes calldata data) external;

    /// @notice Withdraws ERC20 tokens as a borrower
    /// @param shareAmount The amount of shares to burn
    /// @param data Arbitrary data that can be used by the underlying implementation
    function withdrawBorrower(uint256 shareAmount, bytes calldata data) external;

    /// @notice Withdraws lender fees
    /// @param data Arbitrary data that can be used by the underlying implementation
    function withdrawBorrowerFees(bytes calldata data) external;

    /// @notice Updates the liquidation threshold
    /// @param liquidationThreshold The new liquidation threshold
    function setLiquidationThreshold(uint256 liquidationThreshold) external;

    /// @notice Updates the capacity threshold
    /// @param capacityThreshold The new capacity threshold
    function setCapacityThreshold(uint256 capacityThreshold) external;

    /// @notice Updates the fees taken from interest
    /// @param fee The new fee taken from interest
    function setInterestFee(uint256 fee) external;

    /// @notice Updates the fee taken from withdrawals
    /// @param fee The new withdrawal fee
    function setWithdrawalFee(uint256 fee) external;

    /// @notice Updates the fee recipient
    /// @param feeRecipient The new fee recipient
    function setFeeRecipient(address feeRecipient) external;

    /// @notice Updates the interest rate
    /// @param interestRate The new interest rate
    function setInterestRate(uint256 interestRate) external;

    /// @notice Toggles a set of actions to either whitelist or unwhitelist them
    /// @param actions The set of actions to toggle whitelisting for
    function toggleWhitelist(LiquidityWarehouseAccessControl.Action[] calldata actions) external;

    /// @notice Executes a set of actions as the liquidity warehouse
    /// @param executeActions The set of actions to execute
    /// @param data Arbitrary data to be used in the execute transaction
    function execute(LiquidityWarehouseAccessControl.ExecuteAction[] calldata executeActions, bytes calldata data)
        external
        payable;

    //#############//
    //     Read     //
    //##############//

    /// @notice Returns true if an action is callable by a caller at a target
    /// @param target The target being called
    /// @param caller The caller calling the action on the target
    /// @param fnSelector The action's function selector
    /// @return bool True if the caller is able to call the function at the target
    function isWhitelisted(address target, address caller, bytes4 fnSelector) external view returns (bool);

    /// @notice Converts an asset amount to shares
    /// @param isBorrower True if converting borrower assets
    /// @param assetAmount The amount of assets to convert
    /// @return uint256 The amount of shares
    function convertToShares(bool isBorrower, uint256 assetAmount) external view returns (uint256);

    /// @notice Converts a share amount to asset amount
    /// @param isBorrower True if converting borrower shares
    /// @param shareAmount The amount of shares to convert
    /// @return uint256 The amount of assets
    function convertToAssets(bool isBorrower, uint256 shareAmount) external view returns (uint256);

    /// @notice Fetches the lender balance for an asset
    /// @return uint256 The lender balance
    function getLenderBalance() external view returns (uint256);

    /// @notice Fetches the lender withdrawable amount
    /// @return uint256 The lender withdrawable amount
    function getLenderNetAssetValue() external view returns (uint256);

    /// @notice Fetches the borrower withdrawable amount
    /// @return uint256 The borrower withdrawable amount
    function getBorrowerNetAssetValue() external view returns (uint256);

    /// @notice The current terms for the liquidity warehouse
    /// @return Terms The current liquidity warehouse terms
    function getTerms() external view returns (Terms memory);

    /// @notice Fetches the current net asset value of an asset
    /// @return uint256 The net asset value of the asset
    function getNetAssetValue() external view returns (uint256);

    /// @notice Determines if the liquidation threshold is fulfilled
    /// @return bool True if the liquidation threshold is fulfilled
    function isLiquidationThresholdFulfilled() external view returns (bool);

    /// @notice Determines if the capacity threshold is fulfilled
    /// @return bool True if the capacity threshold is fulfilled
    function isCapacityThresholdFulfilled() external view returns (bool);

    /// @notice Retrieves the list of addresses that the warehouse can withdraw from
    /// @return address[] The list of addresses that the warehouse can withdraw from
    function getWithdrawTargets() external view returns (address[] memory);

    /// @notice Returns whether or not the liquidity warehouse is paused
    /// @return bool True if the liquidity warehouse is paused
    function isPaused() external view returns (bool);

    /// @notice Returns whether or not the liquidity warehouse is active
    /// @return bool True if the liquidity warehouse is active
    function isActive() external view returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155Supply.sol)

pragma solidity ^0.8.0;

import "../ERC1155.sol";

/**
 * @dev Extension of ERC1155 that adds tracking of total supply per id.
 *
 * Useful for scenarios where Fungible and Non-fungible tokens have to be
 * clearly identified. Note: While a totalSupply of 1 might mean the
 * corresponding is an NFT, there is no guarantees that no other token with the
 * same id are not going to be minted.
 */
abstract contract ERC1155Supply is ERC1155 {
    mapping(uint256 => uint256) private _totalSupply;

    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) public view virtual returns (uint256) {
        return _totalSupply[id];
    }

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) public view virtual returns (bool) {
        return ERC1155Supply.totalSupply(id) > 0;
    }

    /**
     * @dev See {ERC1155-_beforeTokenTransfer}.
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

        if (from == address(0)) {
            for (uint256 i = 0; i < ids.length; ++i) {
                _totalSupply[ids[i]] += amounts[i];
            }
        }

        if (to == address(0)) {
            for (uint256 i = 0; i < ids.length; ++i) {
                uint256 id = ids[i];
                uint256 amount = amounts[i];
                uint256 supply = _totalSupply[id];
                require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
                unchecked {
                    _totalSupply[id] = supply - amount;
                }
            }
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/ERC1155.sol)

pragma solidity ^0.8.0;

import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 *
 * _Available since v3.1._
 */
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
    using Address for address;

    // Mapping from token ID to account balances
    mapping(uint256 => mapping(address => uint256)) private _balances;

    // Mapping from account to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
    string private _uri;

    /**
     * @dev See {_setURI}.
     */
    constructor(string memory uri_) {
        _setURI(uri_);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC1155).interfaceId ||
            interfaceId == type(IERC1155MetadataURI).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC1155MetadataURI-uri}.
     *
     * This implementation returns the same URI for *all* token types. It relies
     * on the token type ID substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * Clients calling this function must replace the `\{id\}` substring with the
     * actual token type ID.
     */
    function uri(uint256) public view virtual override returns (string memory) {
        return _uri;
    }

    /**
     * @dev See {IERC1155-balanceOf}.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
        require(account != address(0), "ERC1155: address zero is not a valid owner");
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] memory accounts,
        uint256[] memory ids
    ) public view virtual override returns (uint256[] memory) {
        require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts[i], ids[i]);
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC1155-isApprovedForAll}.
     */
    function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[account][operator];
    }

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeTransferFrom(from, to, id, amount, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeBatchTransferFrom(from, to, ids, amounts, data);
    }

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

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

        emit TransferSingle(operator, from, to, id, amount);

        _afterTokenTransfer(operator, from, to, ids, amounts, data);

        _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

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

        emit TransferBatch(operator, from, to, ids, amounts);

        _afterTokenTransfer(operator, from, to, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
    }

    /**
     * @dev Sets a new URI for all token types, by relying on the token type ID
     * substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * By this mechanism, any occurrence of the `\{id\}` substring in either the
     * URI or any of the amounts in the JSON file at said URI will be replaced by
     * clients with the token type ID.
     *
     * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
     * interpreted by clients as
     * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
     * for token type ID 0x4cce0.
     *
     * See {uri}.
     *
     * Because these URIs cannot be meaningfully represented by the {URI} event,
     * this function emits no events.
     */
    function _setURI(string memory newuri) internal virtual {
        _uri = newuri;
    }

    /**
     * @dev Creates `amount` tokens of token type `id`, and assigns them to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(address to, uint256 id, uint256 amount, bytes memory data) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        _balances[id][to] += amount;
        emit TransferSingle(operator, address(0), to, id, amount);

        _afterTokenTransfer(operator, address(0), to, ids, amounts, data);

        _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; i++) {
            _balances[ids[i]][to] += amounts[i];
        }

        emit TransferBatch(operator, address(0), to, ids, amounts);

        _afterTokenTransfer(operator, address(0), to, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
    }

    /**
     * @dev Destroys `amount` tokens of token type `id` from `from`
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `from` must have at least `amount` tokens of token type `id`.
     */
    function _burn(address from, uint256 id, uint256 amount) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }

        emit TransferSingle(operator, from, address(0), id, amount);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     */
    function _burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        for (uint256 i = 0; i < ids.length; i++) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
        }

        emit TransferBatch(operator, from, address(0), ids, amounts);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        require(owner != operator, "ERC1155: setting approval status for self");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `ids` and `amounts` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}

    /**
     * @dev Hook that is called after any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}

    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
                if (response != IERC1155Receiver.onERC1155Received.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non-ERC1155Receiver implementer");
            }
        }
    }

    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
                bytes4 response
            ) {
                if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non-ERC1155Receiver implementer");
            }
        }
    }

    function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
        uint256[] memory array = new uint256[](1);
        array[0] = element;

        return array;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 9 of 36 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

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 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.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;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    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));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {EnumerableSet} from "openzeppelin/utils/structs/EnumerableSet.sol";

abstract contract LiquidityWarehouseAccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    /// @notice Parameters for an action that
    /// requires access control
    struct Action {
        /// @notice The caller of the action
        address caller;
        /// @notice The target of the action
        address target;
        /// @notice The function that the action
        /// will call
        bytes4 fnSelector;
        /// @notice True if the action is whitelisted
        bool isWhitelisted;
        /// @notice True if this is the withdraw function
        bool isWithdraw;
    }

    /// @notice Parameters for executing an action
    struct ExecuteAction {
        /// @notice The target address the action will call
        address target;
        /// @notice The action's calldata
        bytes data;
        /// @notice The amount of wei to send when executing
        /// the action
        uint256 value;
    }

    //################//
    //     Errors     //
    //################//

    /// @notice This error is thrown whenever an invalid withdraw target is called
    /// @param withdrawTarget The invalid withdraw target address
    error InvalidWithdrawTarget(address withdrawTarget);

    /// @notice This error is thrown whenever a caller tries to execute an action
    /// that they do not have authorization to do
    /// @param target The target address the action is calling
    /// @param caller The address trying to execute the action
    /// @param fnSelector The function the action is trying to execute
    error AccessToCallForbidden(address target, address caller, bytes4 fnSelector);

    /// @notice This error is thrown whenever the action being executed fails
    /// @param target The target address the action is calling
    /// @param caller The address trying to execute the action
    /// @param fnSelector The function the action is trying to execute
    error ExecutionFailed(address target, address caller, bytes4 fnSelector);

    //################//
    //     Events     //
    //################//

    /// @notice This event is emitted whenever an action is whitelisted or unwhitelisted
    /// @param target The target address the action is calling
    /// @param caller The address trying to execute the action
    /// @param fnSelector The function the action is trying to execute
    /// @param isWhitelisted True if the action is whitelisted
    event WhitelistedActionChanged(
        address indexed target, address indexed caller, bytes4 fnSelector, bool isWhitelisted
    );

    //###########################//
    //     Storage Variables     //
    //###########################//

    /// @notice Tracks the list of whitelisted function calls
    mapping(bytes32 => bool) internal s_isWhitelisted;

    /// @notice Tracks the list of whitelisted addresses that have a withdraw function
    EnumerableSet.AddressSet internal s_withdrawTargets;

    //################//
    //    Internal    //
    //################//

    /// @notice Toggles a set of actions to either whitelist or unwhitelist them
    /// @param actions The set of actions to toggle whitelisting for
    function _toggleWhitelist(Action[] calldata actions) internal {
        for (uint256 i; i < actions.length; ++i) {
            Action memory action = actions[i];
            bytes32 actionId = _generateActionId(action.target, action.caller, action.fnSelector);
            s_isWhitelisted[actionId] = action.isWhitelisted;

            if (action.isWithdraw && action.isWhitelisted) {
                s_withdrawTargets.add(action.target);
            } else if (action.isWithdraw && !action.isWhitelisted) {
                s_withdrawTargets.remove(action.target);
            }

            emit WhitelistedActionChanged(action.target, action.caller, action.fnSelector, action.isWhitelisted);
        }
    }

    /// @notice Executes a set of actions as the liquidity warehouse
    /// @param executeActions The set of actions to execute
    /// @param isOwner True if the caller is the liquidity warehouse's owner
    function _execute(ExecuteAction[] calldata executeActions, bool isOwner) internal {
        for (uint256 i; i < executeActions.length; ++i) {
            ExecuteAction memory executeAction = executeActions[i];
            bytes4 fnSelector = bytes4(executeAction.data);
            bytes32 actionId = _generateActionId(executeAction.target, msg.sender, fnSelector);
            if (!isOwner && !s_isWhitelisted[actionId]) {
                revert AccessToCallForbidden(executeAction.target, msg.sender, fnSelector);
            }
            (bool success,) = executeAction.target.call{value: executeAction.value}(executeAction.data);
            if (!success) revert ExecutionFailed(executeAction.target, msg.sender, fnSelector);
        }
    }

    /// @notice Returns true if an action is callable by a caller at a target
    /// @param target The target being called
    /// @param caller The caller calling the action on the target
    /// @param fnSelector The action's function selector
    /// @return bool True if the caller is able to call the function at the target
    function _isWhitelisted(address target, address caller, bytes4 fnSelector) internal view returns (bool) {
        return s_isWhitelisted[_generateActionId(target, caller, fnSelector)];
    }

    /// @notice Generates an action ID for an action given it's parameters
    /// @param target The target being called
    /// @param caller The caller calling the action on the target
    /// @param fnSelector The action's function selector
    /// @return bytes32 The keccak256 hash of the action's parameters
    function _generateActionId(address target, address caller, bytes4 fnSelector) internal pure returns (bytes32) {
        return keccak256(abi.encode(target, caller, fnSelector));
    }

    /// @notice Returns the list of target addresses that are withdrawable
    /// @return address[] The list of withdrawable targets
    function _getWithdrawableTargets() internal view returns (address[] memory) {
        return s_withdrawTargets.values();
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {WadRayMath} from './WadRayMath.sol';

/**
 * @title MathUtils library
 * @author Aave
 * @notice Provides functions to perform linear and compounded interest calculations
 */
library MathUtils {
  using WadRayMath for uint256;

  /// @dev Ignoring leap years
  uint256 internal constant SECONDS_PER_YEAR = 365 days;

  /**
   * @dev Function to calculate the interest accumulated using a linear interest rate formula
   * @param rate The interest rate, in ray
   * @param lastUpdateTimestamp The timestamp of the last update of the interest
   * @return The interest rate linearly accumulated during the timeDelta, in ray
   */
  function calculateLinearInterest(
    uint256 rate,
    uint40 lastUpdateTimestamp
  ) internal view returns (uint256) {
    //solium-disable-next-line
    uint256 result = rate * (block.timestamp - uint256(lastUpdateTimestamp));
    unchecked {
      result = result / SECONDS_PER_YEAR;
    }

    return WadRayMath.RAY + result;
  }

  /**
   * @dev Function to calculate the interest using a compounded interest rate formula
   * To avoid expensive exponentiation, the calculation is performed using a binomial approximation:
   *
   *  (1+x)^n = 1+n*x+[n/2*(n-1)]*x^2+[n/6*(n-1)*(n-2)*x^3...
   *
   * The approximation slightly underpays liquidity providers and undercharges borrowers, with the advantage of great
   * gas cost reductions. The whitepaper contains reference to the approximation and a table showing the margin of
   * error per different time periods
   *
   * @param rate The interest rate, in ray
   * @param lastUpdateTimestamp The timestamp of the last update of the interest
   * @return The interest rate compounded during the timeDelta, in ray
   */
  function calculateCompoundedInterest(
    uint256 rate,
    uint40 lastUpdateTimestamp,
    uint256 currentTimestamp
  ) internal pure returns (uint256) {
    //solium-disable-next-line
    uint256 exp = currentTimestamp - uint256(lastUpdateTimestamp);

    if (exp == 0) {
      return WadRayMath.RAY;
    }

    uint256 expMinusOne;
    uint256 expMinusTwo;
    uint256 basePowerTwo;
    uint256 basePowerThree;
    unchecked {
      expMinusOne = exp - 1;

      expMinusTwo = exp > 2 ? exp - 2 : 0;

      basePowerTwo = rate.rayMul(rate) / (SECONDS_PER_YEAR * SECONDS_PER_YEAR);
      basePowerThree = basePowerTwo.rayMul(rate) / SECONDS_PER_YEAR;
    }

    uint256 secondTerm = exp * expMinusOne * basePowerTwo;
    unchecked {
      secondTerm /= 2;
    }
    uint256 thirdTerm = exp * expMinusOne * expMinusTwo * basePowerThree;
    unchecked {
      thirdTerm /= 6;
    }

    return WadRayMath.RAY + (rate * exp) / SECONDS_PER_YEAR + secondTerm + thirdTerm;
  }

  /**
   * @dev Calculates the compounded interest between the timestamp of the last update and the current block timestamp
   * @param rate The interest rate (in ray)
   * @param lastUpdateTimestamp The timestamp from which the interest accumulation needs to be calculated
   * @return The interest rate compounded between lastUpdateTimestamp and current block timestamp, in ray
   */
  function calculateCompoundedInterest(
    uint256 rate,
    uint40 lastUpdateTimestamp
  ) internal view returns (uint256) {
    return calculateCompoundedInterest(rate, lastUpdateTimestamp, block.timestamp);
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

/**
 * @title WadRayMath library
 * @author Aave
 * @notice Provides functions to perform calculations with Wad and Ray units
 * @dev Provides mul and div function for wads (decimal numbers with 18 digits of precision) and rays (decimal numbers
 * with 27 digits of precision)
 * @dev Operations are rounded. If a value is >=.5, will be rounded up, otherwise rounded down.
 */
library WadRayMath {
  // HALF_WAD and HALF_RAY expressed with extended notation as constant with operations are not supported in Yul assembly
  uint256 internal constant WAD = 1e18;
  uint256 internal constant HALF_WAD = 0.5e18;

  uint256 internal constant RAY = 1e27;
  uint256 internal constant HALF_RAY = 0.5e27;

  uint256 internal constant WAD_RAY_RATIO = 1e9;

  /**
   * @dev Multiplies two wad, rounding half up to the nearest wad
   * @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
   * @param a Wad
   * @param b Wad
   * @return c = a*b, in wad
   */
  function wadMul(uint256 a, uint256 b) internal pure returns (uint256 c) {
    // to avoid overflow, a <= (type(uint256).max - HALF_WAD) / b
    assembly {
      if iszero(or(iszero(b), iszero(gt(a, div(sub(not(0), HALF_WAD), b))))) {
        revert(0, 0)
      }

      c := div(add(mul(a, b), HALF_WAD), WAD)
    }
  }

  /**
   * @dev Divides two wad, rounding half up to the nearest wad
   * @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
   * @param a Wad
   * @param b Wad
   * @return c = a/b, in wad
   */
  function wadDiv(uint256 a, uint256 b) internal pure returns (uint256 c) {
    // to avoid overflow, a <= (type(uint256).max - halfB) / WAD
    assembly {
      if or(iszero(b), iszero(iszero(gt(a, div(sub(not(0), div(b, 2)), WAD))))) {
        revert(0, 0)
      }

      c := div(add(mul(a, WAD), div(b, 2)), b)
    }
  }

  /**
   * @notice Multiplies two ray, rounding half up to the nearest ray
   * @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
   * @param a Ray
   * @param b Ray
   * @return c = a raymul b
   */
  function rayMul(uint256 a, uint256 b) internal pure returns (uint256 c) {
    // to avoid overflow, a <= (type(uint256).max - HALF_RAY) / b
    assembly {
      if iszero(or(iszero(b), iszero(gt(a, div(sub(not(0), HALF_RAY), b))))) {
        revert(0, 0)
      }

      c := div(add(mul(a, b), HALF_RAY), RAY)
    }
  }

  /**
   * @notice Divides two ray, rounding half up to the nearest ray
   * @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
   * @param a Ray
   * @param b Ray
   * @return c = a raydiv b
   */
  function rayDiv(uint256 a, uint256 b) internal pure returns (uint256 c) {
    // to avoid overflow, a <= (type(uint256).max - halfB) / RAY
    assembly {
      if or(iszero(b), iszero(iszero(gt(a, div(sub(not(0), div(b, 2)), RAY))))) {
        revert(0, 0)
      }

      c := div(add(mul(a, RAY), div(b, 2)), b)
    }
  }

  /**
   * @dev Casts ray down to wad
   * @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
   * @param a Ray
   * @return b = a converted to wad, rounded half up to the nearest wad
   */
  function rayToWad(uint256 a) internal pure returns (uint256 b) {
    assembly {
      b := div(a, WAD_RAY_RATIO)
      let remainder := mod(a, WAD_RAY_RATIO)
      if iszero(lt(remainder, div(WAD_RAY_RATIO, 2))) {
        b := add(b, 1)
      }
    }
  }

  /**
   * @dev Converts wad up to ray
   * @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
   * @param a Wad
   * @return b = a converted in ray
   */
  function wadToRay(uint256 a) internal pure returns (uint256 b) {
    // to avoid overflow, b/WAD_RAY_RATIO == a
    assembly {
      b := mul(a, WAD_RAY_RATIO)

      if iszero(eq(div(b, WAD_RAY_RATIO), a)) {
        revert(0, 0)
      }
    }
  }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

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

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

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

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

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

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

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

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

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

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

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

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

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

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

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

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

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

interface IEmergencyPausable {
    /// @notice Pauses the contract
    function emergencyPause() external;

    /// @notice Unpauses the contract
    function emergencyUnpause() external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControlDefaultAdminRules.sol)

pragma solidity ^0.8.0;

import "./AccessControl.sol";
import "./IAccessControlDefaultAdminRules.sol";
import "../utils/math/SafeCast.sol";
import "../interfaces/IERC5313.sol";

/**
 * @dev Extension of {AccessControl} that allows specifying special rules to manage
 * the `DEFAULT_ADMIN_ROLE` holder, which is a sensitive role with special permissions
 * over other roles that may potentially have privileged rights in the system.
 *
 * If a specific role doesn't have an admin role assigned, the holder of the
 * `DEFAULT_ADMIN_ROLE` will have the ability to grant it and revoke it.
 *
 * This contract implements the following risk mitigations on top of {AccessControl}:
 *
 * * Only one account holds the `DEFAULT_ADMIN_ROLE` since deployment until it's potentially renounced.
 * * Enforces a 2-step process to transfer the `DEFAULT_ADMIN_ROLE` to another account.
 * * Enforces a configurable delay between the two steps, with the ability to cancel before the transfer is accepted.
 * * The delay can be changed by scheduling, see {changeDefaultAdminDelay}.
 * * It is not possible to use another role to manage the `DEFAULT_ADMIN_ROLE`.
 *
 * Example usage:
 *
 * ```solidity
 * contract MyToken is AccessControlDefaultAdminRules {
 *   constructor() AccessControlDefaultAdminRules(
 *     3 days,
 *     msg.sender // Explicit initial `DEFAULT_ADMIN_ROLE` holder
 *    ) {}
 * }
 * ```
 *
 * _Available since v4.9._
 */
abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRules, IERC5313, AccessControl {
    // pending admin pair read/written together frequently
    address private _pendingDefaultAdmin;
    uint48 private _pendingDefaultAdminSchedule; // 0 == unset

    uint48 private _currentDelay;
    address private _currentDefaultAdmin;

    // pending delay pair read/written together frequently
    uint48 private _pendingDelay;
    uint48 private _pendingDelaySchedule; // 0 == unset

    /**
     * @dev Sets the initial values for {defaultAdminDelay} and {defaultAdmin} address.
     */
    constructor(uint48 initialDelay, address initialDefaultAdmin) {
        require(initialDefaultAdmin != address(0), "AccessControl: 0 default admin");
        _currentDelay = initialDelay;
        _grantRole(DEFAULT_ADMIN_ROLE, initialDefaultAdmin);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlDefaultAdminRules).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC5313-owner}.
     */
    function owner() public view virtual returns (address) {
        return defaultAdmin();
    }

    ///
    /// Override AccessControl role management
    ///

    /**
     * @dev See {AccessControl-grantRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function grantRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
        require(role != DEFAULT_ADMIN_ROLE, "AccessControl: can't directly grant default admin role");
        super.grantRole(role, account);
    }

    /**
     * @dev See {AccessControl-revokeRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function revokeRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
        require(role != DEFAULT_ADMIN_ROLE, "AccessControl: can't directly revoke default admin role");
        super.revokeRole(role, account);
    }

    /**
     * @dev See {AccessControl-renounceRole}.
     *
     * For the `DEFAULT_ADMIN_ROLE`, it only allows renouncing in two steps by first calling
     * {beginDefaultAdminTransfer} to the `address(0)`, so it's required that the {pendingDefaultAdmin} schedule
     * has also passed when calling this function.
     *
     * After its execution, it will not be possible to call `onlyRole(DEFAULT_ADMIN_ROLE)` functions.
     *
     * NOTE: Renouncing `DEFAULT_ADMIN_ROLE` will leave the contract without a {defaultAdmin},
     * thereby disabling any functionality that is only available for it, and the possibility of reassigning a
     * non-administrated role.
     */
    function renounceRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
        if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
            (address newDefaultAdmin, uint48 schedule) = pendingDefaultAdmin();
            require(
                newDefaultAdmin == address(0) && _isScheduleSet(schedule) && _hasSchedulePassed(schedule),
                "AccessControl: only can renounce in two delayed steps"
            );
            delete _pendingDefaultAdminSchedule;
        }
        super.renounceRole(role, account);
    }

    /**
     * @dev See {AccessControl-_grantRole}.
     *
     * For `DEFAULT_ADMIN_ROLE`, it only allows granting if there isn't already a {defaultAdmin} or if the
     * role has been previously renounced.
     *
     * NOTE: Exposing this function through another mechanism may make the `DEFAULT_ADMIN_ROLE`
     * assignable again. Make sure to guarantee this is the expected behavior in your implementation.
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        if (role == DEFAULT_ADMIN_ROLE) {
            require(defaultAdmin() == address(0), "AccessControl: default admin already granted");
            _currentDefaultAdmin = account;
        }
        super._grantRole(role, account);
    }

    /**
     * @dev See {AccessControl-_revokeRole}.
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
            delete _currentDefaultAdmin;
        }
        super._revokeRole(role, account);
    }

    /**
     * @dev See {AccessControl-_setRoleAdmin}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual override {
        require(role != DEFAULT_ADMIN_ROLE, "AccessControl: can't violate default admin rules");
        super._setRoleAdmin(role, adminRole);
    }

    ///
    /// AccessControlDefaultAdminRules accessors
    ///

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function defaultAdmin() public view virtual returns (address) {
        return _currentDefaultAdmin;
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function pendingDefaultAdmin() public view virtual returns (address newAdmin, uint48 schedule) {
        return (_pendingDefaultAdmin, _pendingDefaultAdminSchedule);
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function defaultAdminDelay() public view virtual returns (uint48) {
        uint48 schedule = _pendingDelaySchedule;
        return (_isScheduleSet(schedule) && _hasSchedulePassed(schedule)) ? _pendingDelay : _currentDelay;
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function pendingDefaultAdminDelay() public view virtual returns (uint48 newDelay, uint48 schedule) {
        schedule = _pendingDelaySchedule;
        return (_isScheduleSet(schedule) && !_hasSchedulePassed(schedule)) ? (_pendingDelay, schedule) : (0, 0);
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function defaultAdminDelayIncreaseWait() public view virtual returns (uint48) {
        return 5 days;
    }

    ///
    /// AccessControlDefaultAdminRules public and internal setters for defaultAdmin/pendingDefaultAdmin
    ///

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function beginDefaultAdminTransfer(address newAdmin) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
        _beginDefaultAdminTransfer(newAdmin);
    }

    /**
     * @dev See {beginDefaultAdminTransfer}.
     *
     * Internal function without access restriction.
     */
    function _beginDefaultAdminTransfer(address newAdmin) internal virtual {
        uint48 newSchedule = SafeCast.toUint48(block.timestamp) + defaultAdminDelay();
        _setPendingDefaultAdmin(newAdmin, newSchedule);
        emit DefaultAdminTransferScheduled(newAdmin, newSchedule);
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function cancelDefaultAdminTransfer() public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
        _cancelDefaultAdminTransfer();
    }

    /**
     * @dev See {cancelDefaultAdminTransfer}.
     *
     * Internal function without access restriction.
     */
    function _cancelDefaultAdminTransfer() internal virtual {
        _setPendingDefaultAdmin(address(0), 0);
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function acceptDefaultAdminTransfer() public virtual {
        (address newDefaultAdmin, ) = pendingDefaultAdmin();
        require(_msgSender() == newDefaultAdmin, "AccessControl: pending admin must accept");
        _acceptDefaultAdminTransfer();
    }

    /**
     * @dev See {acceptDefaultAdminTransfer}.
     *
     * Internal function without access restriction.
     */
    function _acceptDefaultAdminTransfer() internal virtual {
        (address newAdmin, uint48 schedule) = pendingDefaultAdmin();
        require(_isScheduleSet(schedule) && _hasSchedulePassed(schedule), "AccessControl: transfer delay not passed");
        _revokeRole(DEFAULT_ADMIN_ROLE, defaultAdmin());
        _grantRole(DEFAULT_ADMIN_ROLE, newAdmin);
        delete _pendingDefaultAdmin;
        delete _pendingDefaultAdminSchedule;
    }

    ///
    /// AccessControlDefaultAdminRules public and internal setters for defaultAdminDelay/pendingDefaultAdminDelay
    ///

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function changeDefaultAdminDelay(uint48 newDelay) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
        _changeDefaultAdminDelay(newDelay);
    }

    /**
     * @dev See {changeDefaultAdminDelay}.
     *
     * Internal function without access restriction.
     */
    function _changeDefaultAdminDelay(uint48 newDelay) internal virtual {
        uint48 newSchedule = SafeCast.toUint48(block.timestamp) + _delayChangeWait(newDelay);
        _setPendingDelay(newDelay, newSchedule);
        emit DefaultAdminDelayChangeScheduled(newDelay, newSchedule);
    }

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function rollbackDefaultAdminDelay() public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
        _rollbackDefaultAdminDelay();
    }

    /**
     * @dev See {rollbackDefaultAdminDelay}.
     *
     * Internal function without access restriction.
     */
    function _rollbackDefaultAdminDelay() internal virtual {
        _setPendingDelay(0, 0);
    }

    /**
     * @dev Returns the amount of seconds to wait after the `newDelay` will
     * become the new {defaultAdminDelay}.
     *
     * The value returned guarantees that if the delay is reduced, it will go into effect
     * after a wait that honors the previously set delay.
     *
     * See {defaultAdminDelayIncreaseWait}.
     */
    function _delayChangeWait(uint48 newDelay) internal view virtual returns (uint48) {
        uint48 currentDelay = defaultAdminDelay();

        // When increasing the delay, we schedule the delay change to occur after a period of "new delay" has passed, up
        // to a maximum given by defaultAdminDelayIncreaseWait, by default 5 days. For example, if increasing from 1 day
        // to 3 days, the new delay will come into effect after 3 days. If increasing from 1 day to 10 days, the new
        // delay will come into effect after 5 days. The 5 day wait period is intended to be able to fix an error like
        // using milliseconds instead of seconds.
        //
        // When decreasing the delay, we wait the difference between "current delay" and "new delay". This guarantees
        // that an admin transfer cannot be made faster than "current delay" at the time the delay change is scheduled.
        // For example, if decreasing from 10 days to 3 days, the new delay will come into effect after 7 days.
        return
            newDelay > currentDelay
                ? uint48(Math.min(newDelay, defaultAdminDelayIncreaseWait())) // no need to safecast, both inputs are uint48
                : currentDelay - newDelay;
    }

    ///
    /// Private setters
    ///

    /**
     * @dev Setter of the tuple for pending admin and its schedule.
     *
     * May emit a DefaultAdminTransferCanceled event.
     */
    function _setPendingDefaultAdmin(address newAdmin, uint48 newSchedule) private {
        (, uint48 oldSchedule) = pendingDefaultAdmin();

        _pendingDefaultAdmin = newAdmin;
        _pendingDefaultAdminSchedule = newSchedule;

        // An `oldSchedule` from `pendingDefaultAdmin()` is only set if it hasn't been accepted.
        if (_isScheduleSet(oldSchedule)) {
            // Emit for implicit cancellations when another default admin was scheduled.
            emit DefaultAdminTransferCanceled();
        }
    }

    /**
     * @dev Setter of the tuple for pending delay and its schedule.
     *
     * May emit a DefaultAdminDelayChangeCanceled event.
     */
    function _setPendingDelay(uint48 newDelay, uint48 newSchedule) private {
        uint48 oldSchedule = _pendingDelaySchedule;

        if (_isScheduleSet(oldSchedule)) {
            if (_hasSchedulePassed(oldSchedule)) {
                // Materialize a virtual delay
                _currentDelay = _pendingDelay;
            } else {
                // Emit for implicit cancellations when another delay was scheduled.
                emit DefaultAdminDelayChangeCanceled();
            }
        }

        _pendingDelay = newDelay;
        _pendingDelaySchedule = newSchedule;
    }

    ///
    /// Private helpers
    ///

    /**
     * @dev Defines if an `schedule` is considered set. For consistency purposes.
     */
    function _isScheduleSet(uint48 schedule) private pure returns (bool) {
        return schedule != 0;
    }

    /**
     * @dev Defines if an `schedule` is considered passed. For consistency purposes.
     */
    function _hasSchedulePassed(uint48 schedule) private view returns (bool) {
        return schedule < block.timestamp;
    }
}

File 19 of 36 : IWETH.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

interface IWETH {
    function deposit() external payable;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

interface ICurveTwocryptoOptimized {
    function calc_withdraw_one_coin(uint256 _burn_amount, uint256 i) external view returns (uint256);

    function add_liquidity(uint256[2] memory _amounts, uint256 _min_mint_amount) external returns (uint256);

    function remove_liquidity_one_coin(uint256 _burn_amount, uint256 i, uint256 _min_received)
        external
        returns (uint256);

    function coins(uint256 idx) external view returns (address);

    function last_prices() external view returns (uint256);

    function price_oracle() external view returns (uint256);

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

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

    function get_dx(uint256 i, uint256 j, uint256 dy) external view returns (uint256);

    function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256);

    function exchange(uint256 i, uint256 j, uint256 _dx, uint256 _min_dy) external returns (uint256);
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

interface ICurveStableSwapNG {
    function coins(uint256 idx) external view returns (address);

    function N_COINS() external view returns (uint256);

    function remove_liquidity_one_coin(uint256 _burn_amount, int128 i, uint256 _min_received)
        external
        returns (uint256);

    function exchange(int128 i, int128 j, uint256 _dx, uint256 _min_dy) external returns (uint256);

    function get_dx(int128 i, int128 j, uint256 dy) external view returns (uint256);

    function get_dy(int128 i, int128 j, uint256 dx) external view returns (uint256);

    function calc_withdraw_one_coin(uint256 _burn_amount, int128 i) external view returns (uint256);

    function add_liquidity(uint256[] memory _amounts, uint256 _min_mint_amount) external returns (uint256);

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

    function last_price(uint256 i) external view returns (uint256);

    function price_oracle(uint256 i) external view returns (uint256);
}

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev _Available since v3.1._
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)

pragma solidity ^0.8.0;

import "../IERC1155.sol";

/**
 * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
 * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155MetadataURI is IERC1155 {
    /**
     * @dev Returns the URI for token type `id`.
     *
     * If the `\{id\}` substring is present in the URI, it must be replaced by
     * clients with the actual token type ID.
     */
    function uri(uint256 id) external view returns (string memory);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [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://consensys.net/diligence/blog/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.8.0/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 functionCallWithValue(target, data, 0, "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");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or 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 {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // 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);
        }
    }
}

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

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

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

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/IAccessControlDefaultAdminRules.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";

/**
 * @dev External interface of AccessControlDefaultAdminRules declared to support ERC165 detection.
 *
 * _Available since v4.9._
 */
interface IAccessControlDefaultAdminRules is IAccessControl {
    /**
     * @dev Emitted when a {defaultAdmin} transfer is started, setting `newAdmin` as the next
     * address to become the {defaultAdmin} by calling {acceptDefaultAdminTransfer} only after `acceptSchedule`
     * passes.
     */
    event DefaultAdminTransferScheduled(address indexed newAdmin, uint48 acceptSchedule);

    /**
     * @dev Emitted when a {pendingDefaultAdmin} is reset if it was never accepted, regardless of its schedule.
     */
    event DefaultAdminTransferCanceled();

    /**
     * @dev Emitted when a {defaultAdminDelay} change is started, setting `newDelay` as the next
     * delay to be applied between default admin transfer after `effectSchedule` has passed.
     */
    event DefaultAdminDelayChangeScheduled(uint48 newDelay, uint48 effectSchedule);

    /**
     * @dev Emitted when a {pendingDefaultAdminDelay} is reset if its schedule didn't pass.
     */
    event DefaultAdminDelayChangeCanceled();

    /**
     * @dev Returns the address of the current `DEFAULT_ADMIN_ROLE` holder.
     */
    function defaultAdmin() external view returns (address);

    /**
     * @dev Returns a tuple of a `newAdmin` and an accept schedule.
     *
     * After the `schedule` passes, the `newAdmin` will be able to accept the {defaultAdmin} role
     * by calling {acceptDefaultAdminTransfer}, completing the role transfer.
     *
     * A zero value only in `acceptSchedule` indicates no pending admin transfer.
     *
     * NOTE: A zero address `newAdmin` means that {defaultAdmin} is being renounced.
     */
    function pendingDefaultAdmin() external view returns (address newAdmin, uint48 acceptSchedule);

    /**
     * @dev Returns the delay required to schedule the acceptance of a {defaultAdmin} transfer started.
     *
     * This delay will be added to the current timestamp when calling {beginDefaultAdminTransfer} to set
     * the acceptance schedule.
     *
     * NOTE: If a delay change has been scheduled, it will take effect as soon as the schedule passes, making this
     * function returns the new delay. See {changeDefaultAdminDelay}.
     */
    function defaultAdminDelay() external view returns (uint48);

    /**
     * @dev Returns a tuple of `newDelay` and an effect schedule.
     *
     * After the `schedule` passes, the `newDelay` will get into effect immediately for every
     * new {defaultAdmin} transfer started with {beginDefaultAdminTransfer}.
     *
     * A zero value only in `effectSchedule` indicates no pending delay change.
     *
     * NOTE: A zero value only for `newDelay` means that the next {defaultAdminDelay}
     * will be zero after the effect schedule.
     */
    function pendingDefaultAdminDelay() external view returns (uint48 newDelay, uint48 effectSchedule);

    /**
     * @dev Starts a {defaultAdmin} transfer by setting a {pendingDefaultAdmin} scheduled for acceptance
     * after the current timestamp plus a {defaultAdminDelay}.
     *
     * Requirements:
     *
     * - Only can be called by the current {defaultAdmin}.
     *
     * Emits a DefaultAdminRoleChangeStarted event.
     */
    function beginDefaultAdminTransfer(address newAdmin) external;

    /**
     * @dev Cancels a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}.
     *
     * A {pendingDefaultAdmin} not yet accepted can also be cancelled with this function.
     *
     * Requirements:
     *
     * - Only can be called by the current {defaultAdmin}.
     *
     * May emit a DefaultAdminTransferCanceled event.
     */
    function cancelDefaultAdminTransfer() external;

    /**
     * @dev Completes a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}.
     *
     * After calling the function:
     *
     * - `DEFAULT_ADMIN_ROLE` should be granted to the caller.
     * - `DEFAULT_ADMIN_ROLE` should be revoked from the previous holder.
     * - {pendingDefaultAdmin} should be reset to zero values.
     *
     * Requirements:
     *
     * - Only can be called by the {pendingDefaultAdmin}'s `newAdmin`.
     * - The {pendingDefaultAdmin}'s `acceptSchedule` should've passed.
     */
    function acceptDefaultAdminTransfer() external;

    /**
     * @dev Initiates a {defaultAdminDelay} update by setting a {pendingDefaultAdminDelay} scheduled for getting
     * into effect after the current timestamp plus a {defaultAdminDelay}.
     *
     * This function guarantees that any call to {beginDefaultAdminTransfer} done between the timestamp this
     * method is called and the {pendingDefaultAdminDelay} effect schedule will use the current {defaultAdminDelay}
     * set before calling.
     *
     * The {pendingDefaultAdminDelay}'s effect schedule is defined in a way that waiting until the schedule and then
     * calling {beginDefaultAdminTransfer} with the new delay will take at least the same as another {defaultAdmin}
     * complete transfer (including acceptance).
     *
     * The schedule is designed for two scenarios:
     *
     * - When the delay is changed for a larger one the schedule is `block.timestamp + newDelay` capped by
     * {defaultAdminDelayIncreaseWait}.
     * - When the delay is changed for a shorter one, the schedule is `block.timestamp + (current delay - new delay)`.
     *
     * A {pendingDefaultAdminDelay} that never got into effect will be canceled in favor of a new scheduled change.
     *
     * Requirements:
     *
     * - Only can be called by the current {defaultAdmin}.
     *
     * Emits a DefaultAdminDelayChangeScheduled event and may emit a DefaultAdminDelayChangeCanceled event.
     */
    function changeDefaultAdminDelay(uint48 newDelay) external;

    /**
     * @dev Cancels a scheduled {defaultAdminDelay} change.
     *
     * Requirements:
     *
     * - Only can be called by the current {defaultAdmin}.
     *
     * May emit a DefaultAdminDelayChangeCanceled event.
     */
    function rollbackDefaultAdminDelay() external;

    /**
     * @dev Maximum time in seconds for an increase to {defaultAdminDelay} (that is scheduled using {changeDefaultAdminDelay})
     * to take effect. Default to 5 days.
     *
     * When the {defaultAdminDelay} is scheduled to be increased, it goes into effect after the new delay has passed with
     * the purpose of giving enough time for reverting any accidental change (i.e. using milliseconds instead of seconds)
     * that may lock the contract. However, to avoid excessive schedules, the wait is capped by this function and it can
     * be overrode for a custom {defaultAdminDelay} increase scheduling.
     *
     * IMPORTANT: Make sure to add a reasonable amount of time while overriding this value, otherwise,
     * there's a risk of setting a high new delay that goes into effect almost immediately without the
     * possibility of human intervention in the case of an input error (eg. set milliseconds instead of seconds).
     */
    function defaultAdminDelayIncreaseWait() external view returns (uint48);
}

File 32 of 36 : IERC5313.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5313.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface for the Light Contract Ownership Standard.
 *
 * A standardized minimal interface required to identify an account that controls a contract
 *
 * _Available since v4.9._
 */
interface IERC5313 {
    /**
     * @dev Gets the address of the owner.
     */
    function owner() external view returns (address);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _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) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

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

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

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

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

Settings
{
  "remappings": [
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@uniswap/v3-core/=lib/v3-core/",
    "gamma/v1/=lib/v1-core/",
    "chainlink/=lib/chainlink/contracts/",
    "KTX-core/=lib/KTX-core/contracts/",
    "TeaVaultV3Pair/=lib/TeaVaultV3Pair/contracts/",
    "aave-v3-core/=lib/aave-v3-core/",
    "ds-test/=lib/v1-core/lib/forge-std/lib/ds-test/src/",
    "v1-core/=lib/v1-core/contracts/",
    "v3-core/=lib/v3-core/",
    "v3-periphery/=lib/v3-periphery/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 125
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": false,
  "libraries": {
    "src/CurveTwoCryptoOptimizedHelperLibrary.sol": {
      "CurveTwoCryptoOptimizedHelperLibrary": "0x09C9fF9D9982b4D49aE2Eb1C5a9e243F726c9B56"
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"components":[{"internalType":"uint256","name":"liquidationThreshold","type":"uint256"},{"internalType":"uint256","name":"capacityThreshold","type":"uint256"},{"internalType":"uint256","name":"interestRate","type":"uint256"},{"internalType":"uint256","name":"interestFee","type":"uint256"},{"internalType":"uint256","name":"withdrawalFee","type":"uint256"},{"internalType":"uint48","name":"initialDelay","type":"uint48"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"address","name":"initialAdmin","type":"address"},{"internalType":"address","name":"wrappedNativeToken","type":"address"},{"internalType":"string","name":"uri","type":"string"}],"internalType":"struct LiquidityWarehouse.ConstructorParams","name":"params","type":"tuple"},{"components":[{"internalType":"address","name":"asset","type":"address"},{"components":[{"internalType":"uint8","name":"id","type":"uint8"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint128","name":"slippage","type":"uint128"},{"internalType":"address","name":"curveSwapPool","type":"address"}],"internalType":"struct CurveTwoCryptoOptimizedHelperLibrary.AssetConfig","name":"assetConfig","type":"tuple"}],"internalType":"struct CurveTwoCryptoOptimizedHelperLibrary.AssetConfigParams[]","name":"assetConfigs","type":"tuple[]"},{"components":[{"internalType":"address","name":"curvePool","type":"address"},{"internalType":"address","name":"withdrawAsset","type":"address"}],"internalType":"struct CurveTwoCryptoOptimizedHelperLibrary.WithdrawAssetConfig[]","name":"withdrawAsset","type":"tuple[]"},{"internalType":"uint256","name":"maxDeviation","type":"uint256"},{"internalType":"uint256","name":"extraMargin","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessForbidden","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes4","name":"fnSelector","type":"bytes4"}],"name":"AccessToCallForbidden","type":"error"},{"inputs":[],"name":"Active","type":"error"},{"inputs":[],"name":"CapacityThresholdBreached","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes4","name":"fnSelector","type":"bytes4"}],"name":"ExecutionFailed","type":"error"},{"inputs":[],"name":"Inactive","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[{"internalType":"uint256","name":"missingAmount","type":"uint256"}],"name":"InsufficientLiquidity","type":"error"},{"inputs":[],"name":"InvalidAsset","type":"error"},{"inputs":[],"name":"InvalidCapacityThreshold","type":"error"},{"inputs":[],"name":"InvalidFeeRecipient","type":"error"},{"inputs":[],"name":"InvalidLiquidationThreshold","type":"error"},{"inputs":[{"internalType":"address","name":"withdrawTarget","type":"address"}],"name":"InvalidWithdrawTarget","type":"error"},{"inputs":[],"name":"InvalidWrappedNativeToken","type":"error"},{"inputs":[],"name":"LiquidationThresholdBreached","type":"error"},{"inputs":[],"name":"LiquidationThresholdNotBreached","type":"error"},{"inputs":[],"name":"ZeroShareAmt","type":"error"},{"anonymous":false,"inputs":[],"name":"Activated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"depositAmount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isBorrower","type":"bool"}],"name":"AssetDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"withdrawAmount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isBorrower","type":"bool"}],"name":"AssetWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldCapacityThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCapacityThreshold","type":"uint256"}],"name":"CapacityThresholdSet","type":"event"},{"anonymous":false,"inputs":[],"name":"Deactivated","type":"event"},{"anonymous":false,"inputs":[],"name":"DefaultAdminDelayChangeCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"newDelay","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"effectSchedule","type":"uint48"}],"name":"DefaultAdminDelayChangeScheduled","type":"event"},{"anonymous":false,"inputs":[],"name":"DefaultAdminTransferCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"},{"indexed":false,"internalType":"uint48","name":"acceptSchedule","type":"uint48"}],"name":"DefaultAdminTransferScheduled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldFeeRecipient","type":"address"},{"indexed":true,"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"FeeRecipientSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"InterestFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldInterestRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newInterestRate","type":"uint256"}],"name":"InterestRateSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isActive","type":"bool"}],"name":"IsActiveSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLiquidationThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLiquidationThreshold","type":"uint256"}],"name":"LiquidationThresholdSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"bytes4","name":"fnSelector","type":"bytes4"},{"indexed":false,"internalType":"bool","name":"isWhitelisted","type":"bool"}],"name":"WhitelistedActionChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"WithdrawalFeeSet","type":"event"},{"inputs":[],"name":"BORROWER_LP_TOKEN_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LENDER_LP_TOKEN_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRIMARY_BORROWER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"activate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"beginDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"}],"name":"changeDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"isBorrower","type":"bool"},{"internalType":"uint256","name":"shareAmount","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"isBorrower","type":"bool"},{"internalType":"uint256","name":"assetAmount","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"withdrawTargets","type":"address[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"deactivate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelay","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelayIncreaseWait","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositAmount","type":"uint256"}],"name":"depositBorrower","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositAmount","type":"uint256"}],"name":"depositLender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyUnpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct LiquidityWarehouseAccessControl.ExecuteAction[]","name":"executeActions","type":"tuple[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBorrowerNetAssetValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLenderBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLenderNetAssetValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNetAssetValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTerms","outputs":[{"components":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint64","name":"liquidationThreshold","type":"uint64"},{"internalType":"uint64","name":"capacityThreshold","type":"uint64"},{"internalType":"uint64","name":"interestRate","type":"uint64"},{"internalType":"uint64","name":"interestFee","type":"uint64"},{"internalType":"uint64","name":"withdrawalFee","type":"uint64"}],"internalType":"struct ILiquidityWarehouse.Terms","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWithdrawTargets","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isCapacityThresholdFulfilled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isLiquidationThresholdFulfilled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes4","name":"fnSelector","type":"bytes4"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"withdrawTargets","type":"address[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdmin","outputs":[{"internalType":"address","name":"newAdmin","type":"address"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdminDelay","outputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rollbackDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"asset","type":"address"},{"components":[{"internalType":"uint8","name":"id","type":"uint8"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint128","name":"slippage","type":"uint128"},{"internalType":"address","name":"curveSwapPool","type":"address"}],"internalType":"struct CurveTwoCryptoOptimizedHelperLibrary.AssetConfig","name":"assetConfig","type":"tuple"}],"internalType":"struct CurveTwoCryptoOptimizedHelperLibrary.AssetConfigParams[]","name":"assetConfigs","type":"tuple[]"}],"name":"setAssetConfigs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"capacityThreshold","type":"uint256"}],"name":"setCapacityThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"extraMargin","type":"uint256"}],"name":"setExtraMargin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"feeRecipient","type":"address"}],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"setInterestFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"interestRate","type":"uint256"}],"name":"setInterestRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"liquidationThreshold","type":"uint256"}],"name":"setLiquidationThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxDeviation","type":"uint256"}],"name":"setMaxDeviation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"curvePool","type":"address"},{"internalType":"address","name":"withdrawAsset","type":"address"}],"internalType":"struct CurveTwoCryptoOptimizedHelperLibrary.WithdrawAssetConfig[]","name":"withdrawAssetConfig","type":"tuple[]"}],"name":"setWithdrawAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"setWithdrawalFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes4","name":"fnSelector","type":"bytes4"},{"internalType":"bool","name":"isWhitelisted","type":"bool"},{"internalType":"bool","name":"isWithdraw","type":"bool"}],"internalType":"struct LiquidityWarehouseAccessControl.Action[]","name":"actions","type":"tuple[]"}],"name":"toggleWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareAmount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"withdrawBorrower","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"withdrawBorrowerFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareAmount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"withdrawLender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"withdrawLenderFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a06040523480156200001157600080fd5b5060405162006f8e38038062006f8e833981016040819052620000349162000c0a565b848060a0015181610100015182610140015162000057816200039560201b60201c565b5060016007556008805460ff191690556001600160a01b038116620000c35760405162461bcd60e51b815260206004820152601e60248201527f416363657373436f6e74726f6c3a20302064656661756c742061646d696e000060448201526064015b60405180910390fd5b600a80546001600160d01b0316600160d01b65ffffffffffff851602179055620000ef600082620003a7565b505060c08101516001600160a01b03166200011d57604051636448d6e960e11b815260040160405180910390fd5b6101208101516001600160a01b03166200014a5760405163a894782b60e01b815260040160405180910390fd5b6101208101516001600160a01b0390811660805260c0820151600c80546001600160a01b031916919092161790556020810151620001889062000457565b8051620001959062000500565b6060810151620001a59062000580565b6080810151620001b59062000600565b60e0810151620001c5906200067c565b6040810151620001d590620006f6565b5060405163307699d960e21b81527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063c1da6764906200021290879060169060040162000d78565b60006040518083038186803b1580156200022b57600080fd5b505af415801562000240573d6000803e3d6000fd5b50506040516372c1823360e11b81527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b56925063e583046691506200028090869060159060040162000e0c565b60006040518083038186803b1580156200029957600080fd5b505af4158015620002ae573d6000803e3d6000fd5b5050604051633672a1c960e01b815260048101859052601360248201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569250633672a1c9915060440160006040518083038186803b1580156200030557600080fd5b505af41580156200031a573d6000803e3d6000fd5b5050604051630812a5d760e11b815260048101849052601360248201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b5692506310254bae915060440160006040518083038186803b1580156200037157600080fd5b505af415801562000386573d6000803e3d6000fd5b50505050505050505062000fc9565b6002620003a3828262000efd565b5050565b816200044b576000620003c2600b546001600160a01b031690565b6001600160a01b0316146200042f5760405162461bcd60e51b815260206004820152602c60248201527f416363657373436f6e74726f6c3a2064656661756c742061646d696e20616c7260448201526b1958591e4819dc985b9d195960a21b6064820152608401620000ba565b600b80546001600160a01b0319166001600160a01b0383161790555b620003a3828262000780565b600d54600160a01b90046001600160401b03168110156200048b576040516345d159c560e01b815260040160405180910390fd5b600e546001600160401b0316620004a28262000824565b600e80546001600160401b0319166001600160401b039290921691909117905560408051828152602081018490527f7e57e00064db7a4aa08be9f74eeec9d12a0f489eb1192e1b9d1331f0df0dfa4b91015b60405180910390a15050565b600d54600160a01b90046001600160401b03166200051e8262000824565b600d80546001600160401b0392909216600160a01b02600160a01b600160e01b031990921691909117905560408051828152602081018490527f8210259c071b6dceddd5c4a87c89c7dca3f3f4473b065e4a474c2f0ae36519d09101620004f4565b600e54600160801b90046001600160401b03166200059e8262000824565b600e80546001600160401b0392909216600160801b02600160801b600160c01b031990921691909117905560408051828152602081018490527fa05d41f2b51cd36a25a89c13f924265e866e4cba73f94309d1762d2be3571e8f9101620004f4565b600e54600160c01b90046001600160401b03166200061e8262000824565b600e80546001600160401b0392909216600160c01b026001600160c01b0390921691909117905560408051828152602081018490527f28a572c8c759d40c2d26dcdaaefd9650e9e37ff11ee147ce0f645cd7664048cb9101620004f4565b6001600160a01b038116620006a457604051630ed1b8b360e31b815260040160405180910390fd5b600d80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f15d80a013f22151bc7246e3bc132e12828cde19de98870475e3fa7084015272190600090a35050565b600e546801000000000000000090046001600160401b0316620007198262000824565b600e80546001600160401b03929092166801000000000000000002600160401b600160801b031990921691909117905560408051828152602081018490527f1291737bc1f130247bdde7cb11d5ed967988c2052a47a007b5a2a862ef6048e89101620004f4565b60008281526009602090815260408083206001600160a01b038516845290915290205460ff16620003a35760008281526009602090815260408083206001600160a01b03851684529091529020805460ff19166001179055620007e03390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60006001600160401b038211156200088e5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401620000ba565b5090565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715620008cd57620008cd62000892565b60405290565b604051608081016001600160401b0381118282101715620008cd57620008cd62000892565b60405161016081016001600160401b0381118282101715620008cd57620008cd62000892565b604051601f8201601f191681016001600160401b038111828210171562000949576200094962000892565b604052919050565b805165ffffffffffff811681146200096857600080fd5b919050565b80516001600160a01b03811681146200096857600080fd5b600082601f8301126200099757600080fd5b81516001600160401b03811115620009b357620009b362000892565b6020620009c9601f8301601f191682016200091e565b8281528582848701011115620009de57600080fd5b60005b83811015620009fe578581018301518282018401528201620009e1565b506000928101909101919091529392505050565b60006001600160401b0382111562000a2e5762000a2e62000892565b5060051b60200190565b600082601f83011262000a4a57600080fd5b8151602062000a6362000a5d8362000a12565b6200091e565b82815260a0928302850182019282820191908785111562000a8357600080fd5b8387015b8581101562000b57578089038281121562000aa25760008081fd5b62000aac620008a8565b62000ab7836200096d565b8152608080601f198401121562000ace5760008081fd5b62000ad8620008d3565b92508784015160ff8116811462000aef5760008081fd5b835260408481015162ffffff8116811462000b0a5760008081fd5b848a01526060858101516001600160801b038116811462000b2b5760008081fd5b8583015262000b3c8684016200096d565b90850152505080870191909152845292840192810162000a87565b5090979650505050505050565b600082601f83011262000b7657600080fd5b8151602062000b8962000a5d8362000a12565b82815260069290921b8401810191818101908684111562000ba957600080fd5b8286015b8481101562000bff576040818903121562000bc85760008081fd5b62000bd2620008a8565b62000bdd826200096d565b815262000bec8583016200096d565b8186015283529183019160400162000bad565b509695505050505050565b600080600080600060a0868803121562000c2357600080fd5b85516001600160401b038082111562000c3b57600080fd5b90870190610160828a03121562000c5157600080fd5b62000c5b620008f8565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015262000c9560a0840162000951565b60a082015262000ca860c084016200096d565b60c082015262000cbb60e084016200096d565b60e082015261010062000cd08185016200096d565b9082015261012062000ce48482016200096d565b90820152610140838101518381111562000cfd57600080fd5b62000d0b8c82870162000985565b82840152505080975050602088015191508082111562000d2a57600080fd5b62000d3889838a0162000a38565b9550604088015191508082111562000d4f57600080fd5b5062000d5e8882890162000b64565b606088015160809098015196999598509695949350505050565b6040808252835182820181905260009190606090818501906020808901865b8381101562000df857815180516001600160a01b03908116875290840151805160ff16858801528085015162ffffff1689880152888101516001600160801b03168888015287015116608086015260a0909401939082019060010162000d97565b505095909501959095525092949350505050565b60408082528351828201819052600091906020906060850190828801855b8281101562000e5e57815180516001600160a01b039081168652908601511685850152928501929084019060010162000e2a565b5050509301939093525092915050565b600181811c9082168062000e8357607f821691505b60208210810362000ea457634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111562000ef857600081815260208120601f850160051c8101602086101562000ed35750805b601f850160051c820191505b8181101562000ef45782815560010162000edf565b5050505b505050565b81516001600160401b0381111562000f195762000f1962000892565b62000f318162000f2a845462000e6e565b8462000eaa565b602080601f83116001811462000f69576000841562000f505750858301515b600019600386901b1c1916600185901b17855562000ef4565b600085815260208120601f198616915b8281101562000f9a5788860151825594840194600190910190840162000f79565b508582101562000fb95787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b608051615fa962000fe560003960006103b90152615fa96000f3fe6080604052600436106103b25760003560e01c80637f596208116101e8578063bb9b092911610108578063d602b9fd116100ab578063e74b981b1161007a578063e74b981b14610cf3578063e9204f8d14610d13578063e985e9c514610d33578063eda273cd14610d7c578063f242432a14610d9157600080fd5b8063d602b9fd14610c68578063dd33307314610c7d578063dddbc04914610cb1578063e63ab1e914610cd157600080fd5b8063bb9b092914610b76578063bc31487714610a97578063bd85b03914610b96578063cc8463c814610bc3578063cefc142914610bd8578063cf6eefb714610bed578063d0b0c81614610c28578063d547741f14610c4857600080fd5b8063a1eda53c1161018b578063ac45ba831161015a578063ac45ba8314610aec578063ae4c12bb14610b0c578063b1498b5714610b2c578063b187bd2614610b41578063b6749e2314610b5657600080fd5b8063a1eda53c14610a63578063a217fddf14610a97578063a22cb46514610aac578063ac1e502514610acc57600080fd5b80637f5962081461097257806381b241341461098757806384ef8ffc146109a757806386679448146109ce5780638b262fca146109ee5780638da5cb5b14610a0e57806391d1485414610a2357806393e0ec0e14610a4357600080fd5b80634173b417116102d35780635b56d6f511610276578063634e93da11610245578063634e93da146108f5578063649a5ec71461091557806365765558146109355780636639a81d14610948578063669e305c1461095d57600080fd5b80635b56d6f51461087d5780635c975abb1461089d5780635f84f302146108b557806360d6140d146108d557600080fd5b80634173b4171461066f5780634673cf5e146107a25780634a4e3bd5146107c25780634e1273f4146107d75780634f558e7914610804578063501c136f1461083357806351858e2714610848578063538932f51461085d57600080fd5b8063145f4864116103565780632eb2c2d6116103255780632eb2c2d6146105d85780632f2ff15d146105f857806336568abe146106185780633d21070e146106385780633f85d9841461065a57600080fd5b8063145f4864146105505780631f93eed21461057057806322f3e2d414610590578063248a9ca3146105a857600080fd5b8062fdd58e1461042d57806301ffc9a714610460578063022d63fb146104905780630aa6220b146104b95780630c3f2f21146104ce5780630e89341c146104ee5780630f15f4c01461051b57806311fae93a1461053057600080fd5b36610428577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561041257600080fd5b505af1158015610426573d6000803e3d6000fd5b005b600080fd5b34801561043957600080fd5b5061044d610448366004614ea7565b610db1565b6040519081526020015b60405180910390f35b34801561046c57600080fd5b5061048061047b366004614ee7565b610e4a565b6040519015158152602001610457565b34801561049c57600080fd5b50620697805b60405165ffffffffffff9091168152602001610457565b3480156104c557600080fd5b50610426610e64565b3480156104da57600080fd5b506104266104e9366004614f4c565b610e7a565b3480156104fa57600080fd5b5061050e610509366004614f97565b611090565b6040516104579190615000565b34801561052757600080fd5b50610426611124565b34801561053c57600080fd5b5061042661054b366004615013565b6111a5565b34801561055c57600080fd5b5061042661056b366004614f4c565b6112d5565b34801561057c57600080fd5b5061042661058b366004615013565b61149f565b34801561059c57600080fd5b5060125460ff16610480565b3480156105b457600080fd5b5061044d6105c3366004614f97565b60009081526009602052604090206001015490565b3480156105e457600080fd5b506104266105f336600461519d565b6115fa565b34801561060457600080fd5b50610426610613366004615246565b611646565b34801561062457600080fd5b50610426610633366004615246565b6116bc565b34801561064457600080fd5b5061064d6117a6565b6040516104579190615272565b34801561066657600080fd5b5061044d6117b7565b34801561067b57600080fd5b506107306040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152506040805160e081018252600c546001600160a01b039081168252600d5490811660208301526001600160401b03600160a01b909104811692820192909252600e548083166060830152600160401b810483166080830152600160801b8104831660a0830152600160c01b900490911660c082015290565b6040805182516001600160a01b03908116825260208085015190911690820152828201516001600160401b039081169282019290925260608084015183169082015260808084015183169082015260a08084015183169082015260c0928301519091169181019190915260e001610457565b3480156107ae57600080fd5b506104266107bd366004615303565b6117d1565b3480156107ce57600080fd5b506104266117e6565b3480156107e357600080fd5b506107f76107f2366004615338565b61180e565b604051610457919061543d565b34801561081057600080fd5b5061048061081f366004614f97565b600090815260036020526040902054151590565b34801561083f57600080fd5b50610480611937565b34801561085457600080fd5b50610426611941565b34801561086957600080fd5b50610426610878366004614f97565b611969565b34801561088957600080fd5b50610426610898366004614f97565b611acc565b3480156108a957600080fd5b5060085460ff16610480565b3480156108c157600080fd5b506104266108d0366004614f97565b611ae8565b3480156108e157600080fd5b506104266108f0366004615494565b611b04565b34801561090157600080fd5b506104266109103660046154ff565b611bfb565b34801561092157600080fd5b5061042661093036600461551a565b611c0f565b610426610943366004615494565b611c23565b34801561095457600080fd5b5061044d611ca0565b34801561096957600080fd5b50610480611d7b565b34801561097e57600080fd5b5061044d611d85565b34801561099357600080fd5b506104266109a2366004615303565b611df3565b3480156109b357600080fd5b50600b546001600160a01b03165b6040516104579190615542565b3480156109da57600080fd5b506104266109e9366004615556565b611e6f565b3480156109fa57600080fd5b50610426610a09366004614f97565b611eb6565b348015610a1a57600080fd5b506109c1611f30565b348015610a2f57600080fd5b50610480610a3e366004615246565b611f44565b348015610a4f57600080fd5b5061044d610a5e3660046155d8565b611f6f565b348015610a6f57600080fd5b50610a78611fca565b6040805165ffffffffffff938416815292909116602083015201610457565b348015610aa357600080fd5b5061044d600081565b348015610ab857600080fd5b50610426610ac73660046155f6565b61201e565b348015610ad857600080fd5b50610426610ae7366004614f97565b612029565b348015610af857600080fd5b50610426610b07366004614f97565b61203d565b348015610b1857600080fd5b50610426610b27366004614f97565b612051565b348015610b3857600080fd5b5061044d600181565b348015610b4d57600080fd5b506104806121b0565b348015610b6257600080fd5b50610480610b7136600461562d565b6121be565b348015610b8257600080fd5b50610426610b91366004615494565b6121d5565b348015610ba257600080fd5b5061044d610bb1366004614f97565b60009081526003602052604090205490565b348015610bcf57600080fd5b506104a2612269565b348015610be457600080fd5b506104266122c8565b348015610bf957600080fd5b50610c02612346565b604080516001600160a01b03909316835265ffffffffffff909116602083015201610457565b348015610c3457600080fd5b50610426610c43366004614f97565b612367565b348015610c5457600080fd5b50610426610c63366004615246565b61237b565b348015610c7457600080fd5b506104266123f2565b348015610c8957600080fd5b5061044d7fabb48c761a18ce43ed26bd5540e567e00be7db5806f6336e9e6e7119fe69dba581565b348015610cbd57600080fd5b50610426610ccc366004614f97565b612405565b348015610cdd57600080fd5b5061044d600080516020615f1483398151915281565b348015610cff57600080fd5b50610426610d0e3660046154ff565b61244f565b348015610d1f57600080fd5b5061044d610d2e3660046155d8565b61246b565b348015610d3f57600080fd5b50610480610d4e366004615674565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b348015610d8857600080fd5b5061044d6124bd565b348015610d9d57600080fd5b50610426610dac36600461569e565b6124d9565b60006001600160a01b038316610e215760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b60648201526084015b60405180910390fd5b506000818152602081815260408083206001600160a01b03861684529091529020545b92915050565b6000610e558261251e565b80610e445750610e4482612543565b6000610e6f81612593565b610e7761259d565b50565b610e826125a8565b600d546001600160a01b03163303610ead57604051631decfebb60e31b815260040160405180910390fd5b610eb5612601565b610ec0336000610db1565b831115610ee057604051631e9acf1760e31b815260040160405180910390fd5b60008080526003602052600080516020615f3483398151915254610f0c90610f066117b7565b86612772565b90506000610f508285858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b610f5a9083615718565b600e54909150600090610f7d90600160c01b90046001600160401b03168361294d565b9050610f91610f8c8285615718565b612985565b600f8054600090610fac9084906001600160d81b031661572b565b92506101000a8154816001600160d81b0302191690836001600160d81b031602179055506000838783610fdf919061574b565b610fe99190615778565b600d54604080516020810190915260008082529293506110169233926001600160a01b03169185906129f2565b61102b336000611026848b615718565b612b18565b61104c336110398486615718565b600c546001600160a01b03169190612c96565b600080516020615f548339815191526110658385615718565b6040805191825260006020830152015b60405180910390a15050505061108b6001600755565b505050565b60606002805461109f9061579a565b80601f01602080910402602001604051908101604052809291908181526020018280546110cb9061579a565b80156111185780601f106110ed57610100808354040283529160200191611118565b820191906000526020600020905b8154815290600101906020018083116110fb57829003601f168201915b50505050509050919050565b60125460ff16156111485760405163c9b0a2a760e01b815260040160405180910390fd5b611150612cf9565b61116d5760405163188c1c4b60e01b815260040160405180910390fd5b61117642612d42565b600f805464ffffffffff92909216600160d81b026001600160d81b039092169190911790556111a3612da8565b565b6111ad6125a8565b600d546001600160a01b031633146111d857604051631decfebb60e31b815260040160405180910390fd5b6111e0612601565b600d546000906111fa906001600160a01b03166001610db1565b600160009081526003602052600080516020615ef4833981519152549192509061122c906112266124bd565b84612772565b905061126e8185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b6112789082615718565b905061128633600184612b18565b600c5461129d906001600160a01b03163383612c96565b6040805182815260016020820152600080516020615f5483398151915291015b60405180910390a150506112d16001600755565b5050565b6112dd6125a8565b600d546001600160a01b0316330361130857604051631decfebb60e31b815260040160405180910390fd5b611310612601565b61131b336001610db1565b83111561133b57604051631e9acf1760e31b815260040160405180910390fd5b600160009081526003602052600080516020615ef48339815191525461136390610f066124bd565b90506113a58184848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b6113af9082615718565b600e54909150600160c01b90046001600160401b031660006113d1828461294d565b905060006113df8285615718565b600d549091506114159033906001600160a01b03166001611400878c61294d565b604051806020016040528060008152506129f2565b61142f336001611425868b61294d565b611026908b615718565b600c54611446906001600160a01b03163383612c96565b60125460ff16801561145d575061145b612de0565b155b1561147b57604051633a2c8b6960e01b815260040160405180910390fd5b6040805182815260016020820152600080516020615f548339815191529101611075565b6114a76125a8565b600d546001600160a01b031633146114d257604051631decfebb60e31b815260040160405180910390fd5b6114da612601565b600d546000906114f3906001600160a01b031682610db1565b60008080526003602052600080516020615f34833981519152549192509061151d906112266117b7565b905061152881612985565b600f80546000906115439084906001600160d81b031661572b565b92506101000a8154816001600160d81b0302191690836001600160d81b031602179055506115a78185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b6115b19082615718565b90506115bf33600084612b18565b600c546115d6906001600160a01b03163383612c96565b6040805182815260006020820152600080516020615f5483398151915291016112bd565b6001600160a01b03851633148061161657506116168533610d4e565b6116325760405162461bcd60e51b8152600401610e18906157ce565b61163f8585858585612e1a565b5050505050565b816116b25760405162461bcd60e51b815260206004820152603660248201527f416363657373436f6e74726f6c3a2063616e2774206469726563746c79206772604482015275616e742064656661756c742061646d696e20726f6c6560501b6064820152608401610e18565b6112d18282612ffd565b811580156116d75750600b546001600160a01b038281169116145b1561179c576000806116e7612346565b90925090506001600160a01b03821615801561170a575065ffffffffffff811615155b801561171d57504265ffffffffffff8216105b6117875760405162461bcd60e51b815260206004820152603560248201527f416363657373436f6e74726f6c3a206f6e6c792063616e2072656e6f756e636560448201527420696e2074776f2064656c6179656420737465707360581b6064820152608401610e18565b5050600a805465ffffffffffff60a01b191690555b6112d18282613022565b60606117b2600561309c565b905090565b60006117b26117c4611ca0565b6117cc611d85565b6130a9565b60006117dc81612593565b61108b83836130bf565b600080516020615f148339815191526117fe81612593565b611806613214565b610e7761325d565b606081518351146118735760405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608401610e18565b600083516001600160401b0381111561188e5761188e615054565b6040519080825280602002602001820160405280156118b7578160200160208202803683370190505b50905060005b845181101561192f576119028582815181106118db576118db61581c565b60200260200101518583815181106118f5576118f561581c565b6020026020010151610db1565b8282815181106119145761191461581c565b602090810291909101015261192881615832565b90506118bd565b509392505050565b60006117b2612cf9565b600080516020615f1483398151915261195981612593565b6119616132a9565b610e776132ef565b6119716132a9565b6119796125a8565b611981612601565b600160009081526003602052600080516020615ef4833981519152546119af906119a96124bd565b8461332c565b9050806000036119d257604051633119677b60e11b815260040160405180910390fd5b60016000526003602052600080516020615ef483398151915254158015611a205750611a1e7fabb48c761a18ce43ed26bd5540e567e00be7db5806f6336e9e6e7119fe69dba533611f44565b155b15611a3e57604051631decfebb60e31b815260040160405180910390fd5b600c54611a56906001600160a01b0316333085613348565b611a723360018360405180602001604052806000815250613380565b611a7a612cf9565b15611a8757611a87612da8565b60408051838152600160208201527f3276139503c4a568a484c55b6b74b258cf9afbb9fe00633815ab853e18f66e1591015b60405180910390a150610e776001600755565b6000611ad781612593565b611adf612601565b6112d182613488565b6000611af381612593565b611afb612601565b6112d18261350e565b60125460ff16611b2757604051632e8acb0d60e01b815260040160405180910390fd5b611b2f612cf9565b15611b4d57604051636734bfc160e11b815260040160405180910390fd5b611b55612601565b6012805460ff191690556040805160208086028281018201909352858252611bcc9287918791829185019084908082843760009201919091525050604080516020601f8801819004810282018101909252868152925086915085908190840183828082843760009201919091525061358c92505050565b6040517f1142a68cc39970640eb3524e77b91f78be21abc64f20f5919387eb46699bb77290600090a150505050565b6000611c0681612593565b6112d18261360a565b6000611c1a81612593565b6112d18261367d565b611c2b6125a8565b611c518484611c38611f30565b6001600160a01b0316336001600160a01b0316146136e6565b611c9082828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610e7792505050565b611c9a6001600755565b50505050565b600080611cab6117a6565b90506000805b8251811015611cf857611cdc838281518110611ccf57611ccf61581c565b6020026020010151613830565b611ce6908361584b565b9150611cf181615832565b9050611cb1565b50600c546040516370a0823160e01b815282916001600160a01b0316906370a0823190611d29903090600401615542565b602060405180830381865afa158015611d46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d6a919061585e565b611d74919061584b565b9250505090565b60006117b2612de0565b600f546012546000916001600160d81b03169060ff16611da457919050565b600e54600090611de790611de290611dcb90600160401b90046001600160401b03166138e4565b600f54600160d81b900464ffffffffff16426138ff565b613a2b565b9050611d74828261294d565b6000611dfe81612593565b60405163307699d960e21b81527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063c1da676490611e3a9086908690601690600401615877565b60006040518083038186803b158015611e5257600080fd5b505af4158015611e66573d6000803e3d6000fd5b50505050505050565b6000611e7a81612593565b6040516372c1823360e11b81527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063e583046690611e3a908690869060159060040161594b565b6000611ec181612593565b604051630812a5d760e11b815260048101839052601360248201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b56906310254bae906044015b60006040518083038186803b158015611f1457600080fd5b505af4158015611f28573d6000803e3d6000fd5b505050505050565b60006117b2600b546001600160a01b031690565b60009182526009602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60008083611f7e576000611f81565b60015b9050600084611f9757611f926117b7565b611f9f565b611f9f6124bd565b9050611fc1611fba8360009081526003602052604090205490565b8286612772565b95945050505050565b600b54600090600160d01b900465ffffffffffff168015158015611ff657504265ffffffffffff821610155b61200257600080612016565b600b54600160a01b900465ffffffffffff16815b915091509091565b6112d1338383613a4e565b600061203481612593565b6112d182613b2e565b600061204881612593565b6112d182613ba7565b6120596132a9565b6120616125a8565b6120696124bd565b60000361208957604051633a2c8b6960e01b815260040160405180910390fd5b612091612601565b60008080526003602052600080516020615f34833981519152546120b7906119a96117b7565b9050806000036120da57604051633119677b60e11b815260040160405180910390fd5b6120e382612985565b600f80546000906120fe9084906001600160d81b03166159b6565b82546001600160d81b039182166101009390930a928302919092021990911617905550600c54612139906001600160a01b0316333085613348565b6121553360008360405180602001604052806000815250613380565b61215d612de0565b61217a57604051633a2c8b6960e01b815260040160405180910390fd5b60408051838152600060208201527f3276139503c4a568a484c55b6b74b258cf9afbb9fe00633815ab853e18f66e159101611ab9565b60006117b260085460ff1690565b60006121cb848484613c46565b90505b9392505050565b60125460ff16156121f95760405163c9b0a2a760e01b815260040160405180910390fd5b611c9a84848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020601f8801819004810282018101909252868152925086915085908190840183828082843760009201919091525061358c92505050565b600b54600090600160d01b900465ffffffffffff16801515801561229457504265ffffffffffff8216105b6122af57600a54600160d01b900465ffffffffffff166122c2565b600b54600160a01b900465ffffffffffff165b91505090565b60006122d2612346565b509050336001600160a01b0382161461233e5760405162461bcd60e51b815260206004820152602860248201527f416363657373436f6e74726f6c3a2070656e64696e672061646d696e206d75736044820152671d081858d8d95c1d60c21b6064820152608401610e18565b610e77613c73565b600a546001600160a01b03811691600160a01b90910465ffffffffffff1690565b600061237281612593565b6112d182613d3e565b816123e85760405162461bcd60e51b815260206004820152603760248201527f416363657373436f6e74726f6c3a2063616e2774206469726563746c79207265604482015276766f6b652064656661756c742061646d696e20726f6c6560481b6064820152608401610e18565b6112d18282613dbc565b60006123fd81612593565b610e77613de1565b600061241081612593565b604051633672a1c960e01b815260048101839052601360248201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b5690633672a1c990604401611efc565b600061245a81612593565b612462612601565b6112d182613dec565b6000808361247a57600061247d565b60015b90506000846124935761248e6117b7565b61249b565b61249b6124bd565b9050611fc16124b68360009081526003602052604090205490565b828661332c565b60006124c76117b7565b6124cf611ca0565b6117b29190615718565b6001600160a01b0385163314806124f557506124f58533610d4e565b6125115760405162461bcd60e51b8152600401610e18906157ce565b61163f85858585856129f2565b60006001600160e01b031982166318a4c3c360e11b1480610e445750610e4482613e65565b60006001600160e01b03198216636cdb3d1360e11b148061257457506001600160e01b031982166303a24d0760e21b145b80610e4457506301ffc9a760e01b6001600160e01b0319831614610e44565b610e778133613e8a565b6111a3600080613ee3565b6002600754036125fa5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610e18565b6002600755565b600f546001600160d81b03811690600160d81b900464ffffffffff1661262642612d42565b600f805464ffffffffff92909216600160d81b026001600160d81b03909216919091179055811580159061265c575060125460ff165b801561266e57508064ffffffffff1642115b156112d157600e546000906126a190611de29061269a90600160401b90046001600160401b03166138e4565b84426138ff565b90506126b0610f8c848361294d565b600f80546001600160d81b0319166001600160d81b039290921691821790556000906126fa906126e1908690615718565b600e54600160801b90046001600160401b03169061294d565b600f549091506000906127179083906001600160d81b0316615718565b600080526003602052600080516020615f348339815191525461273a908461574b565b6127449190615778565b600d546040805160208101909152600080825292935061163f926001600160a01b0390921691908490613380565b600083600003612784575060006121ce565b8361278f848461574b565b6121cb9190615778565b600c546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906127ce903090600401615542565b602060405180830381865afa1580156127eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061280f919061585e565b905083811115612823576000915050610e44565b600061282f8286615718565b90506000805b8015801561284c5750612848600561309c565b5182105b156129055761286683612860600585613fa3565b88613faf565b600c546040516370a0823160e01b81529192506001600160a01b0316906370a0823190612897903090600401615542565b602060405180830381865afa1580156128b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d8919061585e565b93508684116128f0576128eb8488615718565b6128f3565b60005b92506128fe82615832565b9150612835565b60008680602001905181019061291b919061585e565b9050808411156129415760405163c730333f60e01b815260048101859052602401610e18565b50919695505050505050565b600081156706f05b59d3b20000198390048411151761296b57600080fd5b50670de0b6b3a764000091026706f05b59d3b20000010490565b60006001600160d81b038211156129ee5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b6064820152608401610e18565b5090565b6001600160a01b038416612a185760405162461bcd60e51b8152600401610e18906159d6565b336000612a2485614091565b90506000612a3185614091565b9050612a418389898585896140dc565b6000868152602081815260408083206001600160a01b038c16845290915290205485811015612a825760405162461bcd60e51b8152600401610e1890615a1b565b6000878152602081815260408083206001600160a01b038d8116855292528083208985039055908a16825281208054889290612abf90849061584b565b909155505060408051888152602081018890526001600160a01b03808b16928c82169291881691600080516020615ed4833981519152910160405180910390a4612b0d848a8a8a8a8a614255565b505050505050505050565b6001600160a01b038316612b7a5760405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608401610e18565b336000612b8684614091565b90506000612b9384614091565b9050612bb3838760008585604051806020016040528060008152506140dc565b6000858152602081815260408083206001600160a01b038a16845290915290205484811015612c305760405162461bcd60e51b8152602060048201526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608401610e18565b6000868152602081815260408083206001600160a01b038b81168086529184528285208a8703905582518b81529384018a9052909290881691600080516020615ed4833981519152910160405180910390a4604080516020810190915260009052611e66565b6040516001600160a01b03831660248201526044810182905261108b90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526143b0565b600080612d04611ca0565b90506000612d106124bd565b9050600082118015611d745750600d54600160a01b90046001600160401b0316612d3a8284614485565b119250505090565b600064ffffffffff8211156129ee5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526530206269747360d01b6064820152608401610e18565b6012805460ff191660011790556040517fed1cd0670ee0c0017f550451a038818c696d0b6a9d6ce5b369e44275573cf9b090600090a1565b600080612deb611ca0565b90506000612df76124bd565b9050600082118015611d745750600e546001600160401b0316612d3a8284614485565b8151835114612e7c5760405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608401610e18565b6001600160a01b038416612ea25760405162461bcd60e51b8152600401610e18906159d6565b33612eb18187878787876140dc565b60005b8451811015612f97576000858281518110612ed157612ed161581c565b602002602001015190506000858381518110612eef57612eef61581c565b602090810291909101810151600084815280835260408082206001600160a01b038e168352909352919091205490915081811015612f3f5760405162461bcd60e51b8152600401610e1890615a1b565b6000838152602081815260408083206001600160a01b038e8116855292528083208585039055908b16825281208054849290612f7c90849061584b565b9250508190555050505080612f9090615832565b9050612eb4565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8787604051612fe7929190615a65565b60405180910390a4611f288187878787876144bc565b60008281526009602052604090206001015461301881612593565b61108b8383614577565b6001600160a01b03811633146130925760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610e18565b6112d18282614621565b606060006121ce8361465c565b60008183106130b857816121ce565b5090919050565b60005b8181101561108b5760008383838181106130de576130de61581c565b905060a002018036038101906130f49190615a8a565b9050600061310f8260200151836000015184604001516146b7565b60608301516000828152600460205260409020805460ff191691151591909117905560808301519091508015613146575081606001515b1561316257602082015161315c906005906146ed565b5061318d565b8160800151801561317557508160600151155b1561318d57602082015161318b90600590614702565b505b81600001516001600160a01b031682602001516001600160a01b03167f2e33a35090f4b8645dad0317a5106cfef9b9c426e86fc441b1b4842f7dbc663c846040015185606001516040516131f99291906001600160e01b03199290921682521515602082015260400190565b60405180910390a350508061320d90615832565b90506130c2565b60085460ff166111a35760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610e18565b613265613214565b6008805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405161329f9190615542565b60405180910390a1565b60085460ff16156111a35760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610e18565b6132f76132a9565b6008805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586132923390565b60008360000361333d5750806121ce565b8261278f858461574b565b6040516001600160a01b0380851660248301528316604482015260648101829052611c9a9085906323b872dd60e01b90608401612cc2565b6001600160a01b0384166133e05760405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608401610e18565b3360006133ec85614091565b905060006133f985614091565b905061340a836000898585896140dc565b6000868152602081815260408083206001600160a01b038b1684529091528120805487929061343a90849061584b565b909155505060408051878152602081018790526001600160a01b03808a169260009291871691600080516020615ed4833981519152910160405180910390a4611e6683600089898989614255565b600e54600160801b90046001600160401b03166134a482614717565b600e80546001600160401b0392909216600160801b0267ffffffffffffffff60801b1990921691909117905560408051828152602081018490527fa05d41f2b51cd36a25a89c13f924265e866e4cba73f94309d1762d2be3571e8f91015b60405180910390a15050565b600e54600160401b90046001600160401b031661352a82614717565b600e80546001600160401b0392909216600160401b0267ffffffffffffffff60401b1990921691909117905560408051828152602081018490527f1291737bc1f130247bdde7cb11d5ed967988c2052a47a007b5a2a862ef6048e89101613502565b815160005b81811015611c9a5760008482815181106135ad576135ad61581c565b602002602001015190506135cb81600561477f90919063ffffffff16565b6135ea578060405163f70c7cd160e01b8152600401610e189190615542565b6135f76000198286613faf565b50508061360390615832565b9050613591565b6000613614612269565b61361d426147a1565b6136279190615b1d565b90506136338282614808565b60405165ffffffffffff821681526001600160a01b038316907f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed69060200160405180910390a25050565b600061368882614887565b613691426147a1565b61369b9190615b1d565b90506136a78282613ee3565b6040805165ffffffffffff8085168252831660208201527ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b9101613502565b60005b82811015611c9a5760008484838181106137055761370561581c565b90506020028101906137179190615b3c565b61372090615b5c565b90506000816020015161373290615bd8565b90506000613745836000015133846146b7565b905084158015613764575060008181526004602052604090205460ff16155b156137895782516040516307f5a63960e21b8152610e18919033908590600401615c0f565b600083600001516001600160a01b0316846040015185602001516040516137b09190615c3c565b60006040518083038185875af1925050503d80600081146137ed576040519150601f19603f3d011682016040523d82523d6000602084013e6137f2565b606091505b505090508061381b578351604051636708c5f760e11b8152610e18919033908690600401615c0f565b505050508061382990615832565b90506136e9565b6001600160a01b0381811660008181526015602052604080822054600c54601354925163850f264960e01b81526004810195909552908516602485015290931660448301526064820192909252601660848201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063850f26499060a401602060405180830381865af41580156138c0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e44919061585e565b633b9aca0081810290810482146138fa57600080fd5b919050565b60008061391364ffffffffff851684615718565b905080600003613932576b033b2e3c9fd0803ce80000009150506121ce565b6000198101600080806002851161394a57600061394f565b600285035b925066038882915c40006139638a806148cf565b8161397057613970615762565b0491506301e13380613982838b6148cf565b8161398f5761398f615762565b04905060008261399f868861574b565b6139a9919061574b565b600290049050600082856139bd888a61574b565b6139c7919061574b565b6139d1919061574b565b60069004905080826301e133806139e88a8f61574b565b6139f29190615778565b613a08906b033b2e3c9fd0803ce800000061584b565b613a12919061584b565b613a1c919061584b565b9b9a5050505050505050505050565b633b9aca00808204908206631dcd65008110613a48576001820191505b50919050565b816001600160a01b0316836001600160a01b031603613ac15760405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608401610e18565b6001600160a01b03838116600081815260016020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b600e54600160c01b90046001600160401b0316613b4a82614717565b600e80546001600160401b0392909216600160c01b026001600160c01b0390921691909117905560408051828152602081018490527f28a572c8c759d40c2d26dcdaaefd9650e9e37ff11ee147ce0f645cd7664048cb9101613502565b600d54600160a01b90046001600160401b0316811015613bda576040516345d159c560e01b815260040160405180910390fd5b600e546001600160401b0316613bef82614717565b600e805467ffffffffffffffff19166001600160401b039290921691909117905560408051828152602081018490527f7e57e00064db7a4aa08be9f74eeec9d12a0f489eb1192e1b9d1331f0df0dfa4b9101613502565b600060046000613c578686866146b7565b815260208101919091526040016000205460ff16949350505050565b600080613c7e612346565b91509150613c938165ffffffffffff16151590565b8015613ca657504265ffffffffffff8216105b613d035760405162461bcd60e51b815260206004820152602860248201527f416363657373436f6e74726f6c3a207472616e736665722064656c6179206e6f6044820152671d081c185cdcd95960c21b6064820152608401610e18565b613d1f6000613d1a600b546001600160a01b031690565b614621565b613d2a600083614577565b5050600a80546001600160d01b0319169055565b600d54600160a01b90046001600160401b0316613d5a82614717565b600d80546001600160401b0392909216600160a01b0267ffffffffffffffff60a01b1990921691909117905560408051828152602081018490527f8210259c071b6dceddd5c4a87c89c7dca3f3f4473b065e4a474c2f0ae36519d09101613502565b600082815260096020526040902060010154613dd781612593565b61108b8383614621565b6111a3600080614808565b6001600160a01b038116613e1357604051630ed1b8b360e31b815260040160405180910390fd5b600d80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f15d80a013f22151bc7246e3bc132e12828cde19de98870475e3fa7084015272190600090a35050565b60006001600160e01b03198216637965db0b60e01b1480610e445750610e4482612543565b613e948282611f44565b6112d157613ea181614913565b613eac836020614925565b604051602001613ebd929190615c4e565b60408051601f198184030181529082905262461bcd60e51b8252610e1891600401615000565b600b54600160d01b900465ffffffffffff168015613f66574265ffffffffffff82161015613f3c57600b54600a80546001600160d01b0316600160a01b90920465ffffffffffff16600160d01b02919091179055613f66565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec590600090a15b50600b80546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b60006121ce8383614ac0565b6040805160a0810182526013548152602081018581526014548284019081526001600160a01b0386811660608501908152600c54821660808601908152955163406035ff60e11b815294516004860152925160248501529051604484015290518116606483015291519091166084820152601560a4820152601660c48201526000907309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b56906380c06bfe9060e401602060405180830381865af415801561406d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121cb9190615cbd565b604080516001808252818301909252606091600091906020808301908036833701905050905082816000815181106140cb576140cb61581c565b602090810291909101015292915050565b6001600160a01b0385166141635760005b8351811015614161578281815181106141085761410861581c565b6020026020010151600360008684815181106141265761412661581c565b60200260200101518152602001908152602001600020600082825461414b919061584b565b9091555061415a905081615832565b90506140ed565b505b6001600160a01b038416611f285760005b8351811015611e665760008482815181106141915761419161581c565b6020026020010151905060008483815181106141af576141af61581c565b60200260200101519050600060036000848152602001908152602001600020549050818110156142325760405162461bcd60e51b815260206004820152602860248201527f455243313135353a206275726e20616d6f756e74206578636565647320746f74604482015267616c537570706c7960c01b6064820152608401610e18565b6000928352600360205260409092209103905561424e81615832565b9050614174565b6001600160a01b0384163b15611f285760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e61906142999089908990889088908890600401615cda565b6020604051808303816000875af19250505080156142d4575060408051601f3d908101601f191682019092526142d191810190615d1f565b60015b614380576142e0615d3c565b806308c379a00361431957506142f4615d58565b806142ff575061431b565b8060405162461bcd60e51b8152600401610e189190615000565b505b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608401610e18565b6001600160e01b0319811663f23a6e6160e01b14611e665760405162461bcd60e51b8152600401610e1890615de1565b6000614405826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614aea9092919063ffffffff16565b90508051600014806144265750808060200190518101906144269190615cbd565b61108b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610e18565b60008115670de0b6b3a7640000600284041904841117156144a557600080fd5b50670de0b6b3a76400009190910260028204010490565b6001600160a01b0384163b15611f285760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906145009089908990889088908890600401615e29565b6020604051808303816000875af192505050801561453b575060408051601f3d908101601f1916820190925261453891810190615d1f565b60015b614547576142e0615d3c565b6001600160e01b0319811663bc197c8160e01b14611e665760405162461bcd60e51b8152600401610e1890615de1565b81614617576000614590600b546001600160a01b031690565b6001600160a01b0316146145fb5760405162461bcd60e51b815260206004820152602c60248201527f416363657373436f6e74726f6c3a2064656661756c742061646d696e20616c7260448201526b1958591e4819dc985b9d195960a21b6064820152608401610e18565b600b80546001600160a01b0319166001600160a01b0383161790555b6112d18282614af9565b8115801561463c5750600b546001600160a01b038281169116145b1561465257600b80546001600160a01b03191690555b6112d18282614b7f565b60608160000180548060200260200160405190810160405280929190818152602001828054801561111857602002820191906000526020600020905b8154815260200190600101908083116146985750505050509050919050565b60008383836040516020016146ce93929190615c0f565b6040516020818303038152906040528051906020012090509392505050565b60006121ce836001600160a01b038416614be6565b60006121ce836001600160a01b038416614c35565b60006001600160401b038211156129ee5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401610e18565b6001600160a01b038116600090815260018301602052604081205415156121ce565b600065ffffffffffff8211156129ee5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526538206269747360d01b6064820152608401610e18565b6000614812612346565b600a805465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b03881617179055915061485490508165ffffffffffff16151590565b1561108b576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510990600090a1505050565b600080614892612269565b90508065ffffffffffff168365ffffffffffff16116148ba576148b58382615e87565b6121ce565b6121ce65ffffffffffff8416620697806130a9565b600081156b019d971e4fe8401e7400000019839004841115176148f157600080fd5b506b033b2e3c9fd0803ce800000091026b019d971e4fe8401e74000000010490565b6060610e446001600160a01b03831660145b6060600061493483600261574b565b61493f90600261584b565b6001600160401b0381111561495657614956615054565b6040519080825280601f01601f191660200182016040528015614980576020820181803683370190505b509050600360fc1b8160008151811061499b5761499b61581c565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106149ca576149ca61581c565b60200101906001600160f81b031916908160001a90535060006149ee84600261574b565b6149f990600161584b565b90505b6001811115614a71576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110614a2d57614a2d61581c565b1a60f81b828281518110614a4357614a4361581c565b60200101906001600160f81b031916908160001a90535060049490941c93614a6a81615ea6565b90506149fc565b5083156121ce5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610e18565b6000826000018281548110614ad757614ad761581c565b9060005260206000200154905092915050565b60606121cb8484600085614d2f565b614b038282611f44565b6112d15760008281526009602090815260408083206001600160a01b03851684529091529020805460ff19166001179055614b3b3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b614b898282611f44565b156112d15760008281526009602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000818152600183016020526040812054614c2d57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610e44565b506000610e44565b60008181526001830160205260408120548015614d1e576000614c59600183615718565b8554909150600090614c6d90600190615718565b9050818114614cd2576000866000018281548110614c8d57614c8d61581c565b9060005260206000200154905080876000018481548110614cb057614cb061581c565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614ce357614ce3615ebd565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610e44565b6000915050610e44565b5092915050565b606082471015614d905760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610e18565b600080866001600160a01b03168587604051614dac9190615c3c565b60006040518083038185875af1925050503d8060008114614de9576040519150601f19603f3d011682016040523d82523d6000602084013e614dee565b606091505b5091509150614dff87838387614e0c565b925050505b949350505050565b60608315614e7b578251600003614e74576001600160a01b0385163b614e745760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610e18565b5081614e04565b614e0483838151156142ff5781518083602001fd5b80356001600160a01b03811681146138fa57600080fd5b60008060408385031215614eba57600080fd5b614ec383614e90565b946020939093013593505050565b6001600160e01b031981168114610e7757600080fd5b600060208284031215614ef957600080fd5b81356121ce81614ed1565b60008083601f840112614f1657600080fd5b5081356001600160401b03811115614f2d57600080fd5b602083019150836020828501011115614f4557600080fd5b9250929050565b600080600060408486031215614f6157600080fd5b8335925060208401356001600160401b03811115614f7e57600080fd5b614f8a86828701614f04565b9497909650939450505050565b600060208284031215614fa957600080fd5b5035919050565b60005b83811015614fcb578181015183820152602001614fb3565b50506000910152565b60008151808452614fec816020860160208601614fb0565b601f01601f19169290920160200192915050565b6020815260006121ce6020830184614fd4565b6000806020838503121561502657600080fd5b82356001600160401b0381111561503c57600080fd5b61504885828601614f04565b90969095509350505050565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561508f5761508f615054565b6040525050565b60006001600160401b038211156150af576150af615054565b5060051b60200190565b600082601f8301126150ca57600080fd5b813560206150d782615096565b6040516150e4828261506a565b83815260059390931b850182019282810191508684111561510457600080fd5b8286015b8481101561511f5780358352918301918301615108565b509695505050505050565b600082601f83011261513b57600080fd5b81356001600160401b0381111561515457615154615054565b60405161516b601f8301601f19166020018261506a565b81815284602083860101111561518057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156151b557600080fd5b6151be86614e90565b94506151cc60208701614e90565b935060408601356001600160401b03808211156151e857600080fd5b6151f489838a016150b9565b9450606088013591508082111561520a57600080fd5b61521689838a016150b9565b9350608088013591508082111561522c57600080fd5b506152398882890161512a565b9150509295509295909350565b6000806040838503121561525957600080fd5b8235915061526960208401614e90565b90509250929050565b6020808252825182820181905260009190848201906040850190845b818110156152b35783516001600160a01b03168352928401929184019160010161528e565b50909695505050505050565b60008083601f8401126152d157600080fd5b5081356001600160401b038111156152e857600080fd5b60208301915083602060a083028501011115614f4557600080fd5b6000806020838503121561531657600080fd5b82356001600160401b0381111561532c57600080fd5b615048858286016152bf565b6000806040838503121561534b57600080fd5b82356001600160401b038082111561536257600080fd5b818501915085601f83011261537657600080fd5b8135602061538382615096565b604051615390828261506a565b83815260059390931b85018201928281019150898411156153b057600080fd5b948201945b838610156153d5576153c686614e90565b825294820194908201906153b5565b965050860135925050808211156153eb57600080fd5b506153f8858286016150b9565b9150509250929050565b600081518084526020808501945080840160005b8381101561543257815187529582019590820190600101615416565b509495945050505050565b6020815260006121ce6020830184615402565b60008083601f84011261546257600080fd5b5081356001600160401b0381111561547957600080fd5b6020830191508360208260051b8501011115614f4557600080fd5b600080600080604085870312156154aa57600080fd5b84356001600160401b03808211156154c157600080fd5b6154cd88838901615450565b909650945060208701359150808211156154e657600080fd5b506154f387828801614f04565b95989497509550505050565b60006020828403121561551157600080fd5b6121ce82614e90565b60006020828403121561552c57600080fd5b813565ffffffffffff811681146121ce57600080fd5b6001600160a01b0391909116815260200190565b6000806020838503121561556957600080fd5b82356001600160401b038082111561558057600080fd5b818501915085601f83011261559457600080fd5b8135818111156155a357600080fd5b8660208260061b85010111156155b857600080fd5b60209290920196919550909350505050565b8015158114610e7757600080fd5b600080604083850312156155eb57600080fd5b8235614ec3816155ca565b6000806040838503121561560957600080fd5b61561283614e90565b91506020830135615622816155ca565b809150509250929050565b60008060006060848603121561564257600080fd5b61564b84614e90565b925061565960208501614e90565b9150604084013561566981614ed1565b809150509250925092565b6000806040838503121561568757600080fd5b61569083614e90565b915061526960208401614e90565b600080600080600060a086880312156156b657600080fd5b6156bf86614e90565b94506156cd60208701614e90565b9350604086013592506060860135915060808601356001600160401b038111156156f657600080fd5b6152398882890161512a565b634e487b7160e01b600052601160045260246000fd5b81810381811115610e4457610e44615702565b6001600160d81b03828116828216039080821115614d2857614d28615702565b8082028115828204841417610e4457610e44615702565b634e487b7160e01b600052601260045260246000fd5b60008261579557634e487b7160e01b600052601260045260246000fd5b500490565b600181811c908216806157ae57607f821691505b602082108103613a4857634e487b7160e01b600052602260045260246000fd5b6020808252602e908201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60408201526d195c881bdc88185c1c1c9bdd995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b60006001820161584457615844615702565b5060010190565b80820180821115610e4457610e44615702565b60006020828403121561587057600080fd5b5051919050565b6040808252818101849052600090606080840187845b88811015615935576001600160a01b036158a683614e90565b16835260208083013560ff81168082146158bf57600080fd5b80838701525050508482013562ffffff81168082146158dd57600080fd5b8487015250818401356001600160801b03811681146158fb57600080fd5b6001600160801b0316848401526080615915838201614e90565b6001600160a01b03169084015260a092830192919091019060010161588d565b5050809350505050826020830152949350505050565b60408082528181018490526000908560608401835b878110156159a1576001600160a01b038061597a85614e90565b16835260208161598b828701614e90565b1690840152509183019190830190600101615960565b50809350505050826020830152949350505050565b6001600160d81b03818116838216019080821115614d2857614d28615702565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604082015264647265737360d81b606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201526939103a3930b739b332b960b11b606082015260800190565b604081526000615a786040830185615402565b8281036020840152611fc18185615402565b600060a08284031215615a9c57600080fd5b60405160a081018181106001600160401b0382111715615abe57615abe615054565b604052615aca83614e90565b8152615ad860208401614e90565b60208201526040830135615aeb81614ed1565b60408201526060830135615afe816155ca565b60608201526080830135615b11816155ca565b60808201529392505050565b65ffffffffffff818116838216019080821115614d2857614d28615702565b60008235605e19833603018112615b5257600080fd5b9190910192915050565b600060608236031215615b6e57600080fd5b604051606081016001600160401b038282108183111715615b9157615b91615054565b81604052615b9e85614e90565b83526020850135915080821115615bb457600080fd5b50615bc13682860161512a565b602083015250604092830135928101929092525090565b805160208201516001600160e01b03198082169291906004831015615c075780818460040360031b1b83161693505b505050919050565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b60008251615b52818460208701614fb0565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351615c80816017850160208801614fb0565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615cb1816028840160208801614fb0565b01602801949350505050565b600060208284031215615ccf57600080fd5b81516121ce816155ca565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090615d1490830184614fd4565b979650505050505050565b600060208284031215615d3157600080fd5b81516121ce81614ed1565b600060033d1115615d555760046000803e5060005160e01c5b90565b600060443d1015615d665790565b6040516003193d81016004833e81513d6001600160401b038160248401118184111715615d9557505050505090565b8285019150815181811115615dad5750505050505090565b843d8701016020828501011115615dc75750505050505090565b615dd66020828601018761506a565b509095945050505050565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a656374656040820152676420746f6b656e7360c01b606082015260800190565b6001600160a01b0386811682528516602082015260a060408201819052600090615e5590830186615402565b8281036060840152615e678186615402565b90508281036080840152615e7b8185614fd4565b98975050505050505050565b65ffffffffffff828116828216039080821115614d2857614d28615702565b600081615eb557615eb5615702565b506000190190565b634e487b7160e01b600052603160045260246000fdfec3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62a15bc60c955c405d20d9149c709e2460f1c2d9a497496a7f46004d1772c3054c65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a3617319a054d772f909f7c479a2cebe5066e836a939412e32403c99029b92eff7d8646d47cd4be8a9473190d94597582442ef9fa2d64b31ca8b4c999ee751b46a26469706673582212207d63e8b95dc2abe862fa64b945a25d8a765bd7a555b1d2387201a8e4cb25ac4564736f6c6343000813003300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000de7d1b0f0f10000000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000b1a2bc2ec500000000000000000000000000000000000000000000000000000214e8348c4f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008af45c444e7110276adebc5322358dc77a34d4be00000000000000000000000012ee348880daff8effadeb0e6551cff7de9bb0c600000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000020726573657276652d776574682d6c69717569646974792d77617265686f757365000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbd2fc137a30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001fb84fa6d252762e8367ea607a6586e09dcebe3d00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1

Deployed Bytecode

0x6080604052600436106103b25760003560e01c80637f596208116101e8578063bb9b092911610108578063d602b9fd116100ab578063e74b981b1161007a578063e74b981b14610cf3578063e9204f8d14610d13578063e985e9c514610d33578063eda273cd14610d7c578063f242432a14610d9157600080fd5b8063d602b9fd14610c68578063dd33307314610c7d578063dddbc04914610cb1578063e63ab1e914610cd157600080fd5b8063bb9b092914610b76578063bc31487714610a97578063bd85b03914610b96578063cc8463c814610bc3578063cefc142914610bd8578063cf6eefb714610bed578063d0b0c81614610c28578063d547741f14610c4857600080fd5b8063a1eda53c1161018b578063ac45ba831161015a578063ac45ba8314610aec578063ae4c12bb14610b0c578063b1498b5714610b2c578063b187bd2614610b41578063b6749e2314610b5657600080fd5b8063a1eda53c14610a63578063a217fddf14610a97578063a22cb46514610aac578063ac1e502514610acc57600080fd5b80637f5962081461097257806381b241341461098757806384ef8ffc146109a757806386679448146109ce5780638b262fca146109ee5780638da5cb5b14610a0e57806391d1485414610a2357806393e0ec0e14610a4357600080fd5b80634173b417116102d35780635b56d6f511610276578063634e93da11610245578063634e93da146108f5578063649a5ec71461091557806365765558146109355780636639a81d14610948578063669e305c1461095d57600080fd5b80635b56d6f51461087d5780635c975abb1461089d5780635f84f302146108b557806360d6140d146108d557600080fd5b80634173b4171461066f5780634673cf5e146107a25780634a4e3bd5146107c25780634e1273f4146107d75780634f558e7914610804578063501c136f1461083357806351858e2714610848578063538932f51461085d57600080fd5b8063145f4864116103565780632eb2c2d6116103255780632eb2c2d6146105d85780632f2ff15d146105f857806336568abe146106185780633d21070e146106385780633f85d9841461065a57600080fd5b8063145f4864146105505780631f93eed21461057057806322f3e2d414610590578063248a9ca3146105a857600080fd5b8062fdd58e1461042d57806301ffc9a714610460578063022d63fb146104905780630aa6220b146104b95780630c3f2f21146104ce5780630e89341c146104ee5780630f15f4c01461051b57806311fae93a1461053057600080fd5b36610428577f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab16001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561041257600080fd5b505af1158015610426573d6000803e3d6000fd5b005b600080fd5b34801561043957600080fd5b5061044d610448366004614ea7565b610db1565b6040519081526020015b60405180910390f35b34801561046c57600080fd5b5061048061047b366004614ee7565b610e4a565b6040519015158152602001610457565b34801561049c57600080fd5b50620697805b60405165ffffffffffff9091168152602001610457565b3480156104c557600080fd5b50610426610e64565b3480156104da57600080fd5b506104266104e9366004614f4c565b610e7a565b3480156104fa57600080fd5b5061050e610509366004614f97565b611090565b6040516104579190615000565b34801561052757600080fd5b50610426611124565b34801561053c57600080fd5b5061042661054b366004615013565b6111a5565b34801561055c57600080fd5b5061042661056b366004614f4c565b6112d5565b34801561057c57600080fd5b5061042661058b366004615013565b61149f565b34801561059c57600080fd5b5060125460ff16610480565b3480156105b457600080fd5b5061044d6105c3366004614f97565b60009081526009602052604090206001015490565b3480156105e457600080fd5b506104266105f336600461519d565b6115fa565b34801561060457600080fd5b50610426610613366004615246565b611646565b34801561062457600080fd5b50610426610633366004615246565b6116bc565b34801561064457600080fd5b5061064d6117a6565b6040516104579190615272565b34801561066657600080fd5b5061044d6117b7565b34801561067b57600080fd5b506107306040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152506040805160e081018252600c546001600160a01b039081168252600d5490811660208301526001600160401b03600160a01b909104811692820192909252600e548083166060830152600160401b810483166080830152600160801b8104831660a0830152600160c01b900490911660c082015290565b6040805182516001600160a01b03908116825260208085015190911690820152828201516001600160401b039081169282019290925260608084015183169082015260808084015183169082015260a08084015183169082015260c0928301519091169181019190915260e001610457565b3480156107ae57600080fd5b506104266107bd366004615303565b6117d1565b3480156107ce57600080fd5b506104266117e6565b3480156107e357600080fd5b506107f76107f2366004615338565b61180e565b604051610457919061543d565b34801561081057600080fd5b5061048061081f366004614f97565b600090815260036020526040902054151590565b34801561083f57600080fd5b50610480611937565b34801561085457600080fd5b50610426611941565b34801561086957600080fd5b50610426610878366004614f97565b611969565b34801561088957600080fd5b50610426610898366004614f97565b611acc565b3480156108a957600080fd5b5060085460ff16610480565b3480156108c157600080fd5b506104266108d0366004614f97565b611ae8565b3480156108e157600080fd5b506104266108f0366004615494565b611b04565b34801561090157600080fd5b506104266109103660046154ff565b611bfb565b34801561092157600080fd5b5061042661093036600461551a565b611c0f565b610426610943366004615494565b611c23565b34801561095457600080fd5b5061044d611ca0565b34801561096957600080fd5b50610480611d7b565b34801561097e57600080fd5b5061044d611d85565b34801561099357600080fd5b506104266109a2366004615303565b611df3565b3480156109b357600080fd5b50600b546001600160a01b03165b6040516104579190615542565b3480156109da57600080fd5b506104266109e9366004615556565b611e6f565b3480156109fa57600080fd5b50610426610a09366004614f97565b611eb6565b348015610a1a57600080fd5b506109c1611f30565b348015610a2f57600080fd5b50610480610a3e366004615246565b611f44565b348015610a4f57600080fd5b5061044d610a5e3660046155d8565b611f6f565b348015610a6f57600080fd5b50610a78611fca565b6040805165ffffffffffff938416815292909116602083015201610457565b348015610aa357600080fd5b5061044d600081565b348015610ab857600080fd5b50610426610ac73660046155f6565b61201e565b348015610ad857600080fd5b50610426610ae7366004614f97565b612029565b348015610af857600080fd5b50610426610b07366004614f97565b61203d565b348015610b1857600080fd5b50610426610b27366004614f97565b612051565b348015610b3857600080fd5b5061044d600181565b348015610b4d57600080fd5b506104806121b0565b348015610b6257600080fd5b50610480610b7136600461562d565b6121be565b348015610b8257600080fd5b50610426610b91366004615494565b6121d5565b348015610ba257600080fd5b5061044d610bb1366004614f97565b60009081526003602052604090205490565b348015610bcf57600080fd5b506104a2612269565b348015610be457600080fd5b506104266122c8565b348015610bf957600080fd5b50610c02612346565b604080516001600160a01b03909316835265ffffffffffff909116602083015201610457565b348015610c3457600080fd5b50610426610c43366004614f97565b612367565b348015610c5457600080fd5b50610426610c63366004615246565b61237b565b348015610c7457600080fd5b506104266123f2565b348015610c8957600080fd5b5061044d7fabb48c761a18ce43ed26bd5540e567e00be7db5806f6336e9e6e7119fe69dba581565b348015610cbd57600080fd5b50610426610ccc366004614f97565b612405565b348015610cdd57600080fd5b5061044d600080516020615f1483398151915281565b348015610cff57600080fd5b50610426610d0e3660046154ff565b61244f565b348015610d1f57600080fd5b5061044d610d2e3660046155d8565b61246b565b348015610d3f57600080fd5b50610480610d4e366004615674565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b348015610d8857600080fd5b5061044d6124bd565b348015610d9d57600080fd5b50610426610dac36600461569e565b6124d9565b60006001600160a01b038316610e215760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b60648201526084015b60405180910390fd5b506000818152602081815260408083206001600160a01b03861684529091529020545b92915050565b6000610e558261251e565b80610e445750610e4482612543565b6000610e6f81612593565b610e7761259d565b50565b610e826125a8565b600d546001600160a01b03163303610ead57604051631decfebb60e31b815260040160405180910390fd5b610eb5612601565b610ec0336000610db1565b831115610ee057604051631e9acf1760e31b815260040160405180910390fd5b60008080526003602052600080516020615f3483398151915254610f0c90610f066117b7565b86612772565b90506000610f508285858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b610f5a9083615718565b600e54909150600090610f7d90600160c01b90046001600160401b03168361294d565b9050610f91610f8c8285615718565b612985565b600f8054600090610fac9084906001600160d81b031661572b565b92506101000a8154816001600160d81b0302191690836001600160d81b031602179055506000838783610fdf919061574b565b610fe99190615778565b600d54604080516020810190915260008082529293506110169233926001600160a01b03169185906129f2565b61102b336000611026848b615718565b612b18565b61104c336110398486615718565b600c546001600160a01b03169190612c96565b600080516020615f548339815191526110658385615718565b6040805191825260006020830152015b60405180910390a15050505061108b6001600755565b505050565b60606002805461109f9061579a565b80601f01602080910402602001604051908101604052809291908181526020018280546110cb9061579a565b80156111185780601f106110ed57610100808354040283529160200191611118565b820191906000526020600020905b8154815290600101906020018083116110fb57829003601f168201915b50505050509050919050565b60125460ff16156111485760405163c9b0a2a760e01b815260040160405180910390fd5b611150612cf9565b61116d5760405163188c1c4b60e01b815260040160405180910390fd5b61117642612d42565b600f805464ffffffffff92909216600160d81b026001600160d81b039092169190911790556111a3612da8565b565b6111ad6125a8565b600d546001600160a01b031633146111d857604051631decfebb60e31b815260040160405180910390fd5b6111e0612601565b600d546000906111fa906001600160a01b03166001610db1565b600160009081526003602052600080516020615ef4833981519152549192509061122c906112266124bd565b84612772565b905061126e8185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b6112789082615718565b905061128633600184612b18565b600c5461129d906001600160a01b03163383612c96565b6040805182815260016020820152600080516020615f5483398151915291015b60405180910390a150506112d16001600755565b5050565b6112dd6125a8565b600d546001600160a01b0316330361130857604051631decfebb60e31b815260040160405180910390fd5b611310612601565b61131b336001610db1565b83111561133b57604051631e9acf1760e31b815260040160405180910390fd5b600160009081526003602052600080516020615ef48339815191525461136390610f066124bd565b90506113a58184848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b6113af9082615718565b600e54909150600160c01b90046001600160401b031660006113d1828461294d565b905060006113df8285615718565b600d549091506114159033906001600160a01b03166001611400878c61294d565b604051806020016040528060008152506129f2565b61142f336001611425868b61294d565b611026908b615718565b600c54611446906001600160a01b03163383612c96565b60125460ff16801561145d575061145b612de0565b155b1561147b57604051633a2c8b6960e01b815260040160405180910390fd5b6040805182815260016020820152600080516020615f548339815191529101611075565b6114a76125a8565b600d546001600160a01b031633146114d257604051631decfebb60e31b815260040160405180910390fd5b6114da612601565b600d546000906114f3906001600160a01b031682610db1565b60008080526003602052600080516020615f34833981519152549192509061151d906112266117b7565b905061152881612985565b600f80546000906115439084906001600160d81b031661572b565b92506101000a8154816001600160d81b0302191690836001600160d81b031602179055506115a78185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061279992505050565b6115b19082615718565b90506115bf33600084612b18565b600c546115d6906001600160a01b03163383612c96565b6040805182815260006020820152600080516020615f5483398151915291016112bd565b6001600160a01b03851633148061161657506116168533610d4e565b6116325760405162461bcd60e51b8152600401610e18906157ce565b61163f8585858585612e1a565b5050505050565b816116b25760405162461bcd60e51b815260206004820152603660248201527f416363657373436f6e74726f6c3a2063616e2774206469726563746c79206772604482015275616e742064656661756c742061646d696e20726f6c6560501b6064820152608401610e18565b6112d18282612ffd565b811580156116d75750600b546001600160a01b038281169116145b1561179c576000806116e7612346565b90925090506001600160a01b03821615801561170a575065ffffffffffff811615155b801561171d57504265ffffffffffff8216105b6117875760405162461bcd60e51b815260206004820152603560248201527f416363657373436f6e74726f6c3a206f6e6c792063616e2072656e6f756e636560448201527420696e2074776f2064656c6179656420737465707360581b6064820152608401610e18565b5050600a805465ffffffffffff60a01b191690555b6112d18282613022565b60606117b2600561309c565b905090565b60006117b26117c4611ca0565b6117cc611d85565b6130a9565b60006117dc81612593565b61108b83836130bf565b600080516020615f148339815191526117fe81612593565b611806613214565b610e7761325d565b606081518351146118735760405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608401610e18565b600083516001600160401b0381111561188e5761188e615054565b6040519080825280602002602001820160405280156118b7578160200160208202803683370190505b50905060005b845181101561192f576119028582815181106118db576118db61581c565b60200260200101518583815181106118f5576118f561581c565b6020026020010151610db1565b8282815181106119145761191461581c565b602090810291909101015261192881615832565b90506118bd565b509392505050565b60006117b2612cf9565b600080516020615f1483398151915261195981612593565b6119616132a9565b610e776132ef565b6119716132a9565b6119796125a8565b611981612601565b600160009081526003602052600080516020615ef4833981519152546119af906119a96124bd565b8461332c565b9050806000036119d257604051633119677b60e11b815260040160405180910390fd5b60016000526003602052600080516020615ef483398151915254158015611a205750611a1e7fabb48c761a18ce43ed26bd5540e567e00be7db5806f6336e9e6e7119fe69dba533611f44565b155b15611a3e57604051631decfebb60e31b815260040160405180910390fd5b600c54611a56906001600160a01b0316333085613348565b611a723360018360405180602001604052806000815250613380565b611a7a612cf9565b15611a8757611a87612da8565b60408051838152600160208201527f3276139503c4a568a484c55b6b74b258cf9afbb9fe00633815ab853e18f66e1591015b60405180910390a150610e776001600755565b6000611ad781612593565b611adf612601565b6112d182613488565b6000611af381612593565b611afb612601565b6112d18261350e565b60125460ff16611b2757604051632e8acb0d60e01b815260040160405180910390fd5b611b2f612cf9565b15611b4d57604051636734bfc160e11b815260040160405180910390fd5b611b55612601565b6012805460ff191690556040805160208086028281018201909352858252611bcc9287918791829185019084908082843760009201919091525050604080516020601f8801819004810282018101909252868152925086915085908190840183828082843760009201919091525061358c92505050565b6040517f1142a68cc39970640eb3524e77b91f78be21abc64f20f5919387eb46699bb77290600090a150505050565b6000611c0681612593565b6112d18261360a565b6000611c1a81612593565b6112d18261367d565b611c2b6125a8565b611c518484611c38611f30565b6001600160a01b0316336001600160a01b0316146136e6565b611c9082828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610e7792505050565b611c9a6001600755565b50505050565b600080611cab6117a6565b90506000805b8251811015611cf857611cdc838281518110611ccf57611ccf61581c565b6020026020010151613830565b611ce6908361584b565b9150611cf181615832565b9050611cb1565b50600c546040516370a0823160e01b815282916001600160a01b0316906370a0823190611d29903090600401615542565b602060405180830381865afa158015611d46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d6a919061585e565b611d74919061584b565b9250505090565b60006117b2612de0565b600f546012546000916001600160d81b03169060ff16611da457919050565b600e54600090611de790611de290611dcb90600160401b90046001600160401b03166138e4565b600f54600160d81b900464ffffffffff16426138ff565b613a2b565b9050611d74828261294d565b6000611dfe81612593565b60405163307699d960e21b81527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063c1da676490611e3a9086908690601690600401615877565b60006040518083038186803b158015611e5257600080fd5b505af4158015611e66573d6000803e3d6000fd5b50505050505050565b6000611e7a81612593565b6040516372c1823360e11b81527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063e583046690611e3a908690869060159060040161594b565b6000611ec181612593565b604051630812a5d760e11b815260048101839052601360248201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b56906310254bae906044015b60006040518083038186803b158015611f1457600080fd5b505af4158015611f28573d6000803e3d6000fd5b505050505050565b60006117b2600b546001600160a01b031690565b60009182526009602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60008083611f7e576000611f81565b60015b9050600084611f9757611f926117b7565b611f9f565b611f9f6124bd565b9050611fc1611fba8360009081526003602052604090205490565b8286612772565b95945050505050565b600b54600090600160d01b900465ffffffffffff168015158015611ff657504265ffffffffffff821610155b61200257600080612016565b600b54600160a01b900465ffffffffffff16815b915091509091565b6112d1338383613a4e565b600061203481612593565b6112d182613b2e565b600061204881612593565b6112d182613ba7565b6120596132a9565b6120616125a8565b6120696124bd565b60000361208957604051633a2c8b6960e01b815260040160405180910390fd5b612091612601565b60008080526003602052600080516020615f34833981519152546120b7906119a96117b7565b9050806000036120da57604051633119677b60e11b815260040160405180910390fd5b6120e382612985565b600f80546000906120fe9084906001600160d81b03166159b6565b82546001600160d81b039182166101009390930a928302919092021990911617905550600c54612139906001600160a01b0316333085613348565b6121553360008360405180602001604052806000815250613380565b61215d612de0565b61217a57604051633a2c8b6960e01b815260040160405180910390fd5b60408051838152600060208201527f3276139503c4a568a484c55b6b74b258cf9afbb9fe00633815ab853e18f66e159101611ab9565b60006117b260085460ff1690565b60006121cb848484613c46565b90505b9392505050565b60125460ff16156121f95760405163c9b0a2a760e01b815260040160405180910390fd5b611c9a84848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020601f8801819004810282018101909252868152925086915085908190840183828082843760009201919091525061358c92505050565b600b54600090600160d01b900465ffffffffffff16801515801561229457504265ffffffffffff8216105b6122af57600a54600160d01b900465ffffffffffff166122c2565b600b54600160a01b900465ffffffffffff165b91505090565b60006122d2612346565b509050336001600160a01b0382161461233e5760405162461bcd60e51b815260206004820152602860248201527f416363657373436f6e74726f6c3a2070656e64696e672061646d696e206d75736044820152671d081858d8d95c1d60c21b6064820152608401610e18565b610e77613c73565b600a546001600160a01b03811691600160a01b90910465ffffffffffff1690565b600061237281612593565b6112d182613d3e565b816123e85760405162461bcd60e51b815260206004820152603760248201527f416363657373436f6e74726f6c3a2063616e2774206469726563746c79207265604482015276766f6b652064656661756c742061646d696e20726f6c6560481b6064820152608401610e18565b6112d18282613dbc565b60006123fd81612593565b610e77613de1565b600061241081612593565b604051633672a1c960e01b815260048101839052601360248201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b5690633672a1c990604401611efc565b600061245a81612593565b612462612601565b6112d182613dec565b6000808361247a57600061247d565b60015b90506000846124935761248e6117b7565b61249b565b61249b6124bd565b9050611fc16124b68360009081526003602052604090205490565b828661332c565b60006124c76117b7565b6124cf611ca0565b6117b29190615718565b6001600160a01b0385163314806124f557506124f58533610d4e565b6125115760405162461bcd60e51b8152600401610e18906157ce565b61163f85858585856129f2565b60006001600160e01b031982166318a4c3c360e11b1480610e445750610e4482613e65565b60006001600160e01b03198216636cdb3d1360e11b148061257457506001600160e01b031982166303a24d0760e21b145b80610e4457506301ffc9a760e01b6001600160e01b0319831614610e44565b610e778133613e8a565b6111a3600080613ee3565b6002600754036125fa5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610e18565b6002600755565b600f546001600160d81b03811690600160d81b900464ffffffffff1661262642612d42565b600f805464ffffffffff92909216600160d81b026001600160d81b03909216919091179055811580159061265c575060125460ff165b801561266e57508064ffffffffff1642115b156112d157600e546000906126a190611de29061269a90600160401b90046001600160401b03166138e4565b84426138ff565b90506126b0610f8c848361294d565b600f80546001600160d81b0319166001600160d81b039290921691821790556000906126fa906126e1908690615718565b600e54600160801b90046001600160401b03169061294d565b600f549091506000906127179083906001600160d81b0316615718565b600080526003602052600080516020615f348339815191525461273a908461574b565b6127449190615778565b600d546040805160208101909152600080825292935061163f926001600160a01b0390921691908490613380565b600083600003612784575060006121ce565b8361278f848461574b565b6121cb9190615778565b600c546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906127ce903090600401615542565b602060405180830381865afa1580156127eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061280f919061585e565b905083811115612823576000915050610e44565b600061282f8286615718565b90506000805b8015801561284c5750612848600561309c565b5182105b156129055761286683612860600585613fa3565b88613faf565b600c546040516370a0823160e01b81529192506001600160a01b0316906370a0823190612897903090600401615542565b602060405180830381865afa1580156128b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d8919061585e565b93508684116128f0576128eb8488615718565b6128f3565b60005b92506128fe82615832565b9150612835565b60008680602001905181019061291b919061585e565b9050808411156129415760405163c730333f60e01b815260048101859052602401610e18565b50919695505050505050565b600081156706f05b59d3b20000198390048411151761296b57600080fd5b50670de0b6b3a764000091026706f05b59d3b20000010490565b60006001600160d81b038211156129ee5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b6064820152608401610e18565b5090565b6001600160a01b038416612a185760405162461bcd60e51b8152600401610e18906159d6565b336000612a2485614091565b90506000612a3185614091565b9050612a418389898585896140dc565b6000868152602081815260408083206001600160a01b038c16845290915290205485811015612a825760405162461bcd60e51b8152600401610e1890615a1b565b6000878152602081815260408083206001600160a01b038d8116855292528083208985039055908a16825281208054889290612abf90849061584b565b909155505060408051888152602081018890526001600160a01b03808b16928c82169291881691600080516020615ed4833981519152910160405180910390a4612b0d848a8a8a8a8a614255565b505050505050505050565b6001600160a01b038316612b7a5760405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608401610e18565b336000612b8684614091565b90506000612b9384614091565b9050612bb3838760008585604051806020016040528060008152506140dc565b6000858152602081815260408083206001600160a01b038a16845290915290205484811015612c305760405162461bcd60e51b8152602060048201526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608401610e18565b6000868152602081815260408083206001600160a01b038b81168086529184528285208a8703905582518b81529384018a9052909290881691600080516020615ed4833981519152910160405180910390a4604080516020810190915260009052611e66565b6040516001600160a01b03831660248201526044810182905261108b90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526143b0565b600080612d04611ca0565b90506000612d106124bd565b9050600082118015611d745750600d54600160a01b90046001600160401b0316612d3a8284614485565b119250505090565b600064ffffffffff8211156129ee5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526530206269747360d01b6064820152608401610e18565b6012805460ff191660011790556040517fed1cd0670ee0c0017f550451a038818c696d0b6a9d6ce5b369e44275573cf9b090600090a1565b600080612deb611ca0565b90506000612df76124bd565b9050600082118015611d745750600e546001600160401b0316612d3a8284614485565b8151835114612e7c5760405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608401610e18565b6001600160a01b038416612ea25760405162461bcd60e51b8152600401610e18906159d6565b33612eb18187878787876140dc565b60005b8451811015612f97576000858281518110612ed157612ed161581c565b602002602001015190506000858381518110612eef57612eef61581c565b602090810291909101810151600084815280835260408082206001600160a01b038e168352909352919091205490915081811015612f3f5760405162461bcd60e51b8152600401610e1890615a1b565b6000838152602081815260408083206001600160a01b038e8116855292528083208585039055908b16825281208054849290612f7c90849061584b565b9250508190555050505080612f9090615832565b9050612eb4565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8787604051612fe7929190615a65565b60405180910390a4611f288187878787876144bc565b60008281526009602052604090206001015461301881612593565b61108b8383614577565b6001600160a01b03811633146130925760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610e18565b6112d18282614621565b606060006121ce8361465c565b60008183106130b857816121ce565b5090919050565b60005b8181101561108b5760008383838181106130de576130de61581c565b905060a002018036038101906130f49190615a8a565b9050600061310f8260200151836000015184604001516146b7565b60608301516000828152600460205260409020805460ff191691151591909117905560808301519091508015613146575081606001515b1561316257602082015161315c906005906146ed565b5061318d565b8160800151801561317557508160600151155b1561318d57602082015161318b90600590614702565b505b81600001516001600160a01b031682602001516001600160a01b03167f2e33a35090f4b8645dad0317a5106cfef9b9c426e86fc441b1b4842f7dbc663c846040015185606001516040516131f99291906001600160e01b03199290921682521515602082015260400190565b60405180910390a350508061320d90615832565b90506130c2565b60085460ff166111a35760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610e18565b613265613214565b6008805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405161329f9190615542565b60405180910390a1565b60085460ff16156111a35760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610e18565b6132f76132a9565b6008805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586132923390565b60008360000361333d5750806121ce565b8261278f858461574b565b6040516001600160a01b0380851660248301528316604482015260648101829052611c9a9085906323b872dd60e01b90608401612cc2565b6001600160a01b0384166133e05760405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608401610e18565b3360006133ec85614091565b905060006133f985614091565b905061340a836000898585896140dc565b6000868152602081815260408083206001600160a01b038b1684529091528120805487929061343a90849061584b565b909155505060408051878152602081018790526001600160a01b03808a169260009291871691600080516020615ed4833981519152910160405180910390a4611e6683600089898989614255565b600e54600160801b90046001600160401b03166134a482614717565b600e80546001600160401b0392909216600160801b0267ffffffffffffffff60801b1990921691909117905560408051828152602081018490527fa05d41f2b51cd36a25a89c13f924265e866e4cba73f94309d1762d2be3571e8f91015b60405180910390a15050565b600e54600160401b90046001600160401b031661352a82614717565b600e80546001600160401b0392909216600160401b0267ffffffffffffffff60401b1990921691909117905560408051828152602081018490527f1291737bc1f130247bdde7cb11d5ed967988c2052a47a007b5a2a862ef6048e89101613502565b815160005b81811015611c9a5760008482815181106135ad576135ad61581c565b602002602001015190506135cb81600561477f90919063ffffffff16565b6135ea578060405163f70c7cd160e01b8152600401610e189190615542565b6135f76000198286613faf565b50508061360390615832565b9050613591565b6000613614612269565b61361d426147a1565b6136279190615b1d565b90506136338282614808565b60405165ffffffffffff821681526001600160a01b038316907f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed69060200160405180910390a25050565b600061368882614887565b613691426147a1565b61369b9190615b1d565b90506136a78282613ee3565b6040805165ffffffffffff8085168252831660208201527ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b9101613502565b60005b82811015611c9a5760008484838181106137055761370561581c565b90506020028101906137179190615b3c565b61372090615b5c565b90506000816020015161373290615bd8565b90506000613745836000015133846146b7565b905084158015613764575060008181526004602052604090205460ff16155b156137895782516040516307f5a63960e21b8152610e18919033908590600401615c0f565b600083600001516001600160a01b0316846040015185602001516040516137b09190615c3c565b60006040518083038185875af1925050503d80600081146137ed576040519150601f19603f3d011682016040523d82523d6000602084013e6137f2565b606091505b505090508061381b578351604051636708c5f760e11b8152610e18919033908690600401615c0f565b505050508061382990615832565b90506136e9565b6001600160a01b0381811660008181526015602052604080822054600c54601354925163850f264960e01b81526004810195909552908516602485015290931660448301526064820192909252601660848201527309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b569063850f26499060a401602060405180830381865af41580156138c0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e44919061585e565b633b9aca0081810290810482146138fa57600080fd5b919050565b60008061391364ffffffffff851684615718565b905080600003613932576b033b2e3c9fd0803ce80000009150506121ce565b6000198101600080806002851161394a57600061394f565b600285035b925066038882915c40006139638a806148cf565b8161397057613970615762565b0491506301e13380613982838b6148cf565b8161398f5761398f615762565b04905060008261399f868861574b565b6139a9919061574b565b600290049050600082856139bd888a61574b565b6139c7919061574b565b6139d1919061574b565b60069004905080826301e133806139e88a8f61574b565b6139f29190615778565b613a08906b033b2e3c9fd0803ce800000061584b565b613a12919061584b565b613a1c919061584b565b9b9a5050505050505050505050565b633b9aca00808204908206631dcd65008110613a48576001820191505b50919050565b816001600160a01b0316836001600160a01b031603613ac15760405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608401610e18565b6001600160a01b03838116600081815260016020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b600e54600160c01b90046001600160401b0316613b4a82614717565b600e80546001600160401b0392909216600160c01b026001600160c01b0390921691909117905560408051828152602081018490527f28a572c8c759d40c2d26dcdaaefd9650e9e37ff11ee147ce0f645cd7664048cb9101613502565b600d54600160a01b90046001600160401b0316811015613bda576040516345d159c560e01b815260040160405180910390fd5b600e546001600160401b0316613bef82614717565b600e805467ffffffffffffffff19166001600160401b039290921691909117905560408051828152602081018490527f7e57e00064db7a4aa08be9f74eeec9d12a0f489eb1192e1b9d1331f0df0dfa4b9101613502565b600060046000613c578686866146b7565b815260208101919091526040016000205460ff16949350505050565b600080613c7e612346565b91509150613c938165ffffffffffff16151590565b8015613ca657504265ffffffffffff8216105b613d035760405162461bcd60e51b815260206004820152602860248201527f416363657373436f6e74726f6c3a207472616e736665722064656c6179206e6f6044820152671d081c185cdcd95960c21b6064820152608401610e18565b613d1f6000613d1a600b546001600160a01b031690565b614621565b613d2a600083614577565b5050600a80546001600160d01b0319169055565b600d54600160a01b90046001600160401b0316613d5a82614717565b600d80546001600160401b0392909216600160a01b0267ffffffffffffffff60a01b1990921691909117905560408051828152602081018490527f8210259c071b6dceddd5c4a87c89c7dca3f3f4473b065e4a474c2f0ae36519d09101613502565b600082815260096020526040902060010154613dd781612593565b61108b8383614621565b6111a3600080614808565b6001600160a01b038116613e1357604051630ed1b8b360e31b815260040160405180910390fd5b600d80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f15d80a013f22151bc7246e3bc132e12828cde19de98870475e3fa7084015272190600090a35050565b60006001600160e01b03198216637965db0b60e01b1480610e445750610e4482612543565b613e948282611f44565b6112d157613ea181614913565b613eac836020614925565b604051602001613ebd929190615c4e565b60408051601f198184030181529082905262461bcd60e51b8252610e1891600401615000565b600b54600160d01b900465ffffffffffff168015613f66574265ffffffffffff82161015613f3c57600b54600a80546001600160d01b0316600160a01b90920465ffffffffffff16600160d01b02919091179055613f66565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec590600090a15b50600b80546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b60006121ce8383614ac0565b6040805160a0810182526013548152602081018581526014548284019081526001600160a01b0386811660608501908152600c54821660808601908152955163406035ff60e11b815294516004860152925160248501529051604484015290518116606483015291519091166084820152601560a4820152601660c48201526000907309c9ff9d9982b4d49ae2eb1c5a9e243f726c9b56906380c06bfe9060e401602060405180830381865af415801561406d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121cb9190615cbd565b604080516001808252818301909252606091600091906020808301908036833701905050905082816000815181106140cb576140cb61581c565b602090810291909101015292915050565b6001600160a01b0385166141635760005b8351811015614161578281815181106141085761410861581c565b6020026020010151600360008684815181106141265761412661581c565b60200260200101518152602001908152602001600020600082825461414b919061584b565b9091555061415a905081615832565b90506140ed565b505b6001600160a01b038416611f285760005b8351811015611e665760008482815181106141915761419161581c565b6020026020010151905060008483815181106141af576141af61581c565b60200260200101519050600060036000848152602001908152602001600020549050818110156142325760405162461bcd60e51b815260206004820152602860248201527f455243313135353a206275726e20616d6f756e74206578636565647320746f74604482015267616c537570706c7960c01b6064820152608401610e18565b6000928352600360205260409092209103905561424e81615832565b9050614174565b6001600160a01b0384163b15611f285760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e61906142999089908990889088908890600401615cda565b6020604051808303816000875af19250505080156142d4575060408051601f3d908101601f191682019092526142d191810190615d1f565b60015b614380576142e0615d3c565b806308c379a00361431957506142f4615d58565b806142ff575061431b565b8060405162461bcd60e51b8152600401610e189190615000565b505b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608401610e18565b6001600160e01b0319811663f23a6e6160e01b14611e665760405162461bcd60e51b8152600401610e1890615de1565b6000614405826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614aea9092919063ffffffff16565b90508051600014806144265750808060200190518101906144269190615cbd565b61108b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610e18565b60008115670de0b6b3a7640000600284041904841117156144a557600080fd5b50670de0b6b3a76400009190910260028204010490565b6001600160a01b0384163b15611f285760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906145009089908990889088908890600401615e29565b6020604051808303816000875af192505050801561453b575060408051601f3d908101601f1916820190925261453891810190615d1f565b60015b614547576142e0615d3c565b6001600160e01b0319811663bc197c8160e01b14611e665760405162461bcd60e51b8152600401610e1890615de1565b81614617576000614590600b546001600160a01b031690565b6001600160a01b0316146145fb5760405162461bcd60e51b815260206004820152602c60248201527f416363657373436f6e74726f6c3a2064656661756c742061646d696e20616c7260448201526b1958591e4819dc985b9d195960a21b6064820152608401610e18565b600b80546001600160a01b0319166001600160a01b0383161790555b6112d18282614af9565b8115801561463c5750600b546001600160a01b038281169116145b1561465257600b80546001600160a01b03191690555b6112d18282614b7f565b60608160000180548060200260200160405190810160405280929190818152602001828054801561111857602002820191906000526020600020905b8154815260200190600101908083116146985750505050509050919050565b60008383836040516020016146ce93929190615c0f565b6040516020818303038152906040528051906020012090509392505050565b60006121ce836001600160a01b038416614be6565b60006121ce836001600160a01b038416614c35565b60006001600160401b038211156129ee5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401610e18565b6001600160a01b038116600090815260018301602052604081205415156121ce565b600065ffffffffffff8211156129ee5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526538206269747360d01b6064820152608401610e18565b6000614812612346565b600a805465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b03881617179055915061485490508165ffffffffffff16151590565b1561108b576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510990600090a1505050565b600080614892612269565b90508065ffffffffffff168365ffffffffffff16116148ba576148b58382615e87565b6121ce565b6121ce65ffffffffffff8416620697806130a9565b600081156b019d971e4fe8401e7400000019839004841115176148f157600080fd5b506b033b2e3c9fd0803ce800000091026b019d971e4fe8401e74000000010490565b6060610e446001600160a01b03831660145b6060600061493483600261574b565b61493f90600261584b565b6001600160401b0381111561495657614956615054565b6040519080825280601f01601f191660200182016040528015614980576020820181803683370190505b509050600360fc1b8160008151811061499b5761499b61581c565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106149ca576149ca61581c565b60200101906001600160f81b031916908160001a90535060006149ee84600261574b565b6149f990600161584b565b90505b6001811115614a71576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110614a2d57614a2d61581c565b1a60f81b828281518110614a4357614a4361581c565b60200101906001600160f81b031916908160001a90535060049490941c93614a6a81615ea6565b90506149fc565b5083156121ce5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610e18565b6000826000018281548110614ad757614ad761581c565b9060005260206000200154905092915050565b60606121cb8484600085614d2f565b614b038282611f44565b6112d15760008281526009602090815260408083206001600160a01b03851684529091529020805460ff19166001179055614b3b3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b614b898282611f44565b156112d15760008281526009602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000818152600183016020526040812054614c2d57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610e44565b506000610e44565b60008181526001830160205260408120548015614d1e576000614c59600183615718565b8554909150600090614c6d90600190615718565b9050818114614cd2576000866000018281548110614c8d57614c8d61581c565b9060005260206000200154905080876000018481548110614cb057614cb061581c565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614ce357614ce3615ebd565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610e44565b6000915050610e44565b5092915050565b606082471015614d905760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610e18565b600080866001600160a01b03168587604051614dac9190615c3c565b60006040518083038185875af1925050503d8060008114614de9576040519150601f19603f3d011682016040523d82523d6000602084013e614dee565b606091505b5091509150614dff87838387614e0c565b925050505b949350505050565b60608315614e7b578251600003614e74576001600160a01b0385163b614e745760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610e18565b5081614e04565b614e0483838151156142ff5781518083602001fd5b80356001600160a01b03811681146138fa57600080fd5b60008060408385031215614eba57600080fd5b614ec383614e90565b946020939093013593505050565b6001600160e01b031981168114610e7757600080fd5b600060208284031215614ef957600080fd5b81356121ce81614ed1565b60008083601f840112614f1657600080fd5b5081356001600160401b03811115614f2d57600080fd5b602083019150836020828501011115614f4557600080fd5b9250929050565b600080600060408486031215614f6157600080fd5b8335925060208401356001600160401b03811115614f7e57600080fd5b614f8a86828701614f04565b9497909650939450505050565b600060208284031215614fa957600080fd5b5035919050565b60005b83811015614fcb578181015183820152602001614fb3565b50506000910152565b60008151808452614fec816020860160208601614fb0565b601f01601f19169290920160200192915050565b6020815260006121ce6020830184614fd4565b6000806020838503121561502657600080fd5b82356001600160401b0381111561503c57600080fd5b61504885828601614f04565b90969095509350505050565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561508f5761508f615054565b6040525050565b60006001600160401b038211156150af576150af615054565b5060051b60200190565b600082601f8301126150ca57600080fd5b813560206150d782615096565b6040516150e4828261506a565b83815260059390931b850182019282810191508684111561510457600080fd5b8286015b8481101561511f5780358352918301918301615108565b509695505050505050565b600082601f83011261513b57600080fd5b81356001600160401b0381111561515457615154615054565b60405161516b601f8301601f19166020018261506a565b81815284602083860101111561518057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156151b557600080fd5b6151be86614e90565b94506151cc60208701614e90565b935060408601356001600160401b03808211156151e857600080fd5b6151f489838a016150b9565b9450606088013591508082111561520a57600080fd5b61521689838a016150b9565b9350608088013591508082111561522c57600080fd5b506152398882890161512a565b9150509295509295909350565b6000806040838503121561525957600080fd5b8235915061526960208401614e90565b90509250929050565b6020808252825182820181905260009190848201906040850190845b818110156152b35783516001600160a01b03168352928401929184019160010161528e565b50909695505050505050565b60008083601f8401126152d157600080fd5b5081356001600160401b038111156152e857600080fd5b60208301915083602060a083028501011115614f4557600080fd5b6000806020838503121561531657600080fd5b82356001600160401b0381111561532c57600080fd5b615048858286016152bf565b6000806040838503121561534b57600080fd5b82356001600160401b038082111561536257600080fd5b818501915085601f83011261537657600080fd5b8135602061538382615096565b604051615390828261506a565b83815260059390931b85018201928281019150898411156153b057600080fd5b948201945b838610156153d5576153c686614e90565b825294820194908201906153b5565b965050860135925050808211156153eb57600080fd5b506153f8858286016150b9565b9150509250929050565b600081518084526020808501945080840160005b8381101561543257815187529582019590820190600101615416565b509495945050505050565b6020815260006121ce6020830184615402565b60008083601f84011261546257600080fd5b5081356001600160401b0381111561547957600080fd5b6020830191508360208260051b8501011115614f4557600080fd5b600080600080604085870312156154aa57600080fd5b84356001600160401b03808211156154c157600080fd5b6154cd88838901615450565b909650945060208701359150808211156154e657600080fd5b506154f387828801614f04565b95989497509550505050565b60006020828403121561551157600080fd5b6121ce82614e90565b60006020828403121561552c57600080fd5b813565ffffffffffff811681146121ce57600080fd5b6001600160a01b0391909116815260200190565b6000806020838503121561556957600080fd5b82356001600160401b038082111561558057600080fd5b818501915085601f83011261559457600080fd5b8135818111156155a357600080fd5b8660208260061b85010111156155b857600080fd5b60209290920196919550909350505050565b8015158114610e7757600080fd5b600080604083850312156155eb57600080fd5b8235614ec3816155ca565b6000806040838503121561560957600080fd5b61561283614e90565b91506020830135615622816155ca565b809150509250929050565b60008060006060848603121561564257600080fd5b61564b84614e90565b925061565960208501614e90565b9150604084013561566981614ed1565b809150509250925092565b6000806040838503121561568757600080fd5b61569083614e90565b915061526960208401614e90565b600080600080600060a086880312156156b657600080fd5b6156bf86614e90565b94506156cd60208701614e90565b9350604086013592506060860135915060808601356001600160401b038111156156f657600080fd5b6152398882890161512a565b634e487b7160e01b600052601160045260246000fd5b81810381811115610e4457610e44615702565b6001600160d81b03828116828216039080821115614d2857614d28615702565b8082028115828204841417610e4457610e44615702565b634e487b7160e01b600052601260045260246000fd5b60008261579557634e487b7160e01b600052601260045260246000fd5b500490565b600181811c908216806157ae57607f821691505b602082108103613a4857634e487b7160e01b600052602260045260246000fd5b6020808252602e908201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60408201526d195c881bdc88185c1c1c9bdd995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b60006001820161584457615844615702565b5060010190565b80820180821115610e4457610e44615702565b60006020828403121561587057600080fd5b5051919050565b6040808252818101849052600090606080840187845b88811015615935576001600160a01b036158a683614e90565b16835260208083013560ff81168082146158bf57600080fd5b80838701525050508482013562ffffff81168082146158dd57600080fd5b8487015250818401356001600160801b03811681146158fb57600080fd5b6001600160801b0316848401526080615915838201614e90565b6001600160a01b03169084015260a092830192919091019060010161588d565b5050809350505050826020830152949350505050565b60408082528181018490526000908560608401835b878110156159a1576001600160a01b038061597a85614e90565b16835260208161598b828701614e90565b1690840152509183019190830190600101615960565b50809350505050826020830152949350505050565b6001600160d81b03818116838216019080821115614d2857614d28615702565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604082015264647265737360d81b606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201526939103a3930b739b332b960b11b606082015260800190565b604081526000615a786040830185615402565b8281036020840152611fc18185615402565b600060a08284031215615a9c57600080fd5b60405160a081018181106001600160401b0382111715615abe57615abe615054565b604052615aca83614e90565b8152615ad860208401614e90565b60208201526040830135615aeb81614ed1565b60408201526060830135615afe816155ca565b60608201526080830135615b11816155ca565b60808201529392505050565b65ffffffffffff818116838216019080821115614d2857614d28615702565b60008235605e19833603018112615b5257600080fd5b9190910192915050565b600060608236031215615b6e57600080fd5b604051606081016001600160401b038282108183111715615b9157615b91615054565b81604052615b9e85614e90565b83526020850135915080821115615bb457600080fd5b50615bc13682860161512a565b602083015250604092830135928101929092525090565b805160208201516001600160e01b03198082169291906004831015615c075780818460040360031b1b83161693505b505050919050565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b60008251615b52818460208701614fb0565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351615c80816017850160208801614fb0565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615cb1816028840160208801614fb0565b01602801949350505050565b600060208284031215615ccf57600080fd5b81516121ce816155ca565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090615d1490830184614fd4565b979650505050505050565b600060208284031215615d3157600080fd5b81516121ce81614ed1565b600060033d1115615d555760046000803e5060005160e01c5b90565b600060443d1015615d665790565b6040516003193d81016004833e81513d6001600160401b038160248401118184111715615d9557505050505090565b8285019150815181811115615dad5750505050505090565b843d8701016020828501011115615dc75750505050505090565b615dd66020828601018761506a565b509095945050505050565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a656374656040820152676420746f6b656e7360c01b606082015260800190565b6001600160a01b0386811682528516602082015260a060408201819052600090615e5590830186615402565b8281036060840152615e678186615402565b90508281036080840152615e7b8185614fd4565b98975050505050505050565b65ffffffffffff828116828216039080821115614d2857614d28615702565b600081615eb557615eb5615702565b506000190190565b634e487b7160e01b600052603160045260246000fdfec3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62a15bc60c955c405d20d9149c709e2460f1c2d9a497496a7f46004d1772c3054c65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a3617319a054d772f909f7c479a2cebe5066e836a939412e32403c99029b92eff7d8646d47cd4be8a9473190d94597582442ef9fa2d64b31ca8b4c999ee751b46a26469706673582212207d63e8b95dc2abe862fa64b945a25d8a765bd7a555b1d2387201a8e4cb25ac4564736f6c63430008130033

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

00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000de7d1b0f0f10000000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000b1a2bc2ec500000000000000000000000000000000000000000000000000000214e8348c4f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008af45c444e7110276adebc5322358dc77a34d4be00000000000000000000000012ee348880daff8effadeb0e6551cff7de9bb0c600000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000020726573657276652d776574682d6c69717569646974792d77617265686f757365000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbd2fc137a30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001fb84fa6d252762e8367ea607a6586e09dcebe3d00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1

-----Decoded View---------------
Arg [0] : params (tuple):
Arg [1] : liquidationThreshold (uint256): 10000000000000000
Arg [2] : capacityThreshold (uint256): 50000000000000000
Arg [3] : interestRate (uint256): 150000000000000000
Arg [4] : interestFee (uint256): 0
Arg [5] : withdrawalFee (uint256): 1000000000000000
Arg [6] : initialDelay (uint48): 0
Arg [7] : asset (address): 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
Arg [8] : feeRecipient (address): 0x8Af45C444e7110276adebc5322358DC77A34D4bE
Arg [9] : initialAdmin (address): 0x12ee348880DafF8effAdEb0e6551cff7de9bb0c6
Arg [10] : wrappedNativeToken (address): 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
Arg [11] : uri (string): reserve-weth-liquidity-warehouse

Arg [1] : assetConfigs (tuple[]):
Arg [1] : asset (address): 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
Arg [2] : assetConfig (tuple):
Arg [1] : id (uint8): 0
Arg [2] : fee (uint24): 0
Arg [3] : slippage (uint128): 990000000000000000
Arg [4] : curveSwapPool (address): 0x0000000000000000000000000000000000000000


Arg [2] : withdrawAsset (tuple[]):
Arg [1] : curvePool (address): 0x1Fb84Fa6D252762e8367eA607A6586E09dceBe3D
Arg [2] : withdrawAsset (address): 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1

Arg [3] : maxDeviation (uint256): 10000000000000000
Arg [4] : extraMargin (uint256): 1002000000000000000

-----Encoded View---------------
27 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000240
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000300
Arg [3] : 000000000000000000000000000000000000000000000000002386f26fc10000
Arg [4] : 0000000000000000000000000000000000000000000000000de7d1b0f0f10000
Arg [5] : 000000000000000000000000000000000000000000000000002386f26fc10000
Arg [6] : 00000000000000000000000000000000000000000000000000b1a2bc2ec50000
Arg [7] : 0000000000000000000000000000000000000000000000000214e8348c4f0000
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [9] : 00000000000000000000000000000000000000000000000000038d7ea4c68000
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [11] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [12] : 0000000000000000000000008af45c444e7110276adebc5322358dc77a34d4be
Arg [13] : 00000000000000000000000012ee348880daff8effadeb0e6551cff7de9bb0c6
Arg [14] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [15] : 0000000000000000000000000000000000000000000000000000000000000160
Arg [16] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [17] : 726573657276652d776574682d6c69717569646974792d77617265686f757365
Arg [18] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [19] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [20] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [21] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [22] : 0000000000000000000000000000000000000000000000000dbd2fc137a30000
Arg [23] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [24] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [25] : 0000000000000000000000001fb84fa6d252762e8367ea607a6586e09dcebe3d
Arg [26] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
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.