ETH Price: $2,138.11 (+4.04%)
 

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Redeem425811072026-02-24 16:46:018 days ago1771951561IN
0x00000000...7127dd218
0 ETH0.000004540.01793523
Redeem356107492025-09-16 8:20:45170 days ago1758010845IN
0x00000000...7127dd218
0 ETH0.000002120.00868868
Approve286788142025-04-08 21:16:15330 days ago1744146975IN
0x00000000...7127dd218
0 ETH0.000000160.00200217
Withdraw244753952025-01-01 14:02:17427 days ago1735740137IN
0x00000000...7127dd218
0 ETH0.000001860.00734379
Redeem229088562024-11-26 7:44:19464 days ago1732607059IN
0x00000000...7127dd218
0 ETH0.000008080.01558894

Latest 1 internal transaction

Parent Transaction Hash Block From To
177482152024-07-29 20:42:57583 days ago1722285777  Contract Creation0 ETH

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Vault

Compiler Version
v0.8.21+commit.d9974bed

Optimization Enabled:
Yes with 1 runs

Other Settings:
shanghai EvmVersion
File 1 of 26 : Vault.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.21;

import { IIonPool } from "./../interfaces/IIonPool.sol";
import { RAY } from "./../libraries/math/WadRayMath.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ERC4626 } from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { Multicall } from "@openzeppelin/contracts/utils/Multicall.sol";
import { ReentrancyGuard } from "openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
import { AccessControlDefaultAdminRules } from
    "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";

// solhint-disable-next-line no-unused-import
import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";

/**
 * @title Ion Lending Vault
 * @author Molecular Labs
 * @notice Vault contract that can allocate a single lender asset over various
 * isolated lending pairs on Ion Protocol. This contract is a fork of the
 * Metamorpho contract licnesed under GPL-2.0 with changes to administrative
 * logic, underlying data structures, and lending interactions to be made
 * compatible with Ion Protocol.
 *
 * @custom:security-contact [email protected]
 */
contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, ReentrancyGuard {
    using EnumerableSet for EnumerableSet.AddressSet;
    using Math for uint256;

    error InvalidQueueLength(uint256 queueLength, uint256 supportedMarketsLength);
    error AllocationCapExceeded(uint256 resultingSupplied, uint256 allocationCap);
    error InvalidReallocation(uint256 totalSupplied, uint256 totalWithdrawn);
    error InvalidMarketRemovalNonZeroSupply(IIonPool pool);
    error InvalidUnderlyingAsset(IIonPool pool);
    error MarketAlreadySupported(IIonPool pool);
    error MarketNotSupported(IIonPool pool);
    error AllSupplyCapsReached();
    error NotEnoughLiquidityToWithdraw();
    error InvalidIdleMarketRemovalNonZeroBalance();
    error InvalidQueueContainsDuplicates();
    error MarketsAndAllocationCapLengthMustBeEqual();
    error IonPoolsArrayAndNewCapsArrayMustBeOfEqualLength();
    error InvalidFeePercentage();
    error InvalidFeeRecipient();
    error MaxSupportedMarketsReached();
    error InvalidIonPoolDecimals(IIonPool pool);

    event UpdateSupplyQueue(address indexed caller, IIonPool[] newSupplyQueue);
    event UpdateWithdrawQueue(address indexed caller, IIonPool[] newWithdrawQueue);

    event ReallocateWithdraw(IIonPool indexed pool, uint256 assets);
    event ReallocateSupply(IIonPool indexed pool, uint256 assets);
    event FeeAccrued(uint256 feeShares, uint256 newTotalAssets);
    event UpdateLastTotalAssets(uint256 lastTotalAssets, uint256 newLastTotalAssets);

    event UpdateFeePercentage(uint256 newFeePercentage);
    event UpdateFeeRecipient(address indexed newFeeRecipient);
    event AddSupportedMarkets(IIonPool[] marketsAdded);
    event RemoveSupportedMarkets(IIonPool[] marketsRemoved);
    event UpdateAllocationCaps(IIonPool[] ionPools, uint256[] newCaps);

    bytes32 public constant OWNER_ROLE = keccak256("OWNER_ROLE");
    bytes32 public constant ALLOCATOR_ROLE = keccak256("ALLOCATOR_ROLE");

    IIonPool public constant IDLE = IIonPool(address(uint160(uint256(keccak256("IDLE_ASSET_HOLDINGS")))));

    uint8 public immutable DECIMALS_OFFSET;

    bytes32 public constant ION_POOL_SUPPLY_CAP_SLOT =
        0xceba3d526b4d5afd91d1b752bf1fd37917c20a6daf576bcb41dd1c57c1f67e09;
    bytes32 public constant ION_POOL_LIQUIDITY_SLOT = 0xceba3d526b4d5afd91d1b752bf1fd37917c20a6daf576bcb41dd1c57c1f67e08;

    IERC20 public immutable BASE_ASSET;

    uint8 public constant MAX_SUPPORTED_MARKETS = 32;

    EnumerableSet.AddressSet supportedMarkets;

    IIonPool[] public supplyQueue;
    IIonPool[] public withdrawQueue;

    address public feeRecipient;
    uint256 public feePercentage; // [RAY]

    uint256 public lastTotalAssets;

    mapping(IIonPool => uint256) public caps;

    struct MarketAllocation {
        IIonPool pool;
        int256 assets;
    }

    struct MarketsArgs {
        IIonPool[] marketsToAdd;
        uint256[] allocationCaps;
        IIonPool[] newSupplyQueue;
        IIonPool[] newWithdrawQueue;
    }

    constructor(
        IERC20 _baseAsset,
        address _feeRecipient,
        uint256 _feePercentage,
        string memory _name,
        string memory _symbol,
        uint48 initialDelay,
        address initialDefaultAdmin,
        MarketsArgs memory marketsArgs
    )
        ERC4626(_baseAsset)
        ERC20(_name, _symbol)
        AccessControlDefaultAdminRules(initialDelay, initialDefaultAdmin)
    {
        BASE_ASSET = _baseAsset;

        if (_feePercentage > RAY) revert InvalidFeePercentage();
        if (_feeRecipient == address(0)) revert InvalidFeeRecipient();

        feePercentage = _feePercentage;
        feeRecipient = _feeRecipient;

        DECIMALS_OFFSET = 4;

        _addSupportedMarkets(
            marketsArgs.marketsToAdd,
            marketsArgs.allocationCaps,
            marketsArgs.newSupplyQueue,
            marketsArgs.newWithdrawQueue
        );

        emit UpdateFeePercentage(_feePercentage);
        emit UpdateFeeRecipient(_feeRecipient);
    }

    /**
     * @notice Updates the fee percentage.
     * @dev Input must be in [RAY]. Ex) 2% would be 0.02e27.
     * @param _feePercentage The percentage of the interest accrued to take as a
     * management fee.
     */
    function updateFeePercentage(uint256 _feePercentage) external onlyRole(OWNER_ROLE) {
        if (_feePercentage > RAY) revert InvalidFeePercentage();
        _accrueFee();
        feePercentage = _feePercentage;
        emit UpdateFeePercentage(_feePercentage);
    }

    /**
     * @notice Updates the fee recipient.
     * @param _feeRecipient The recipient address of the shares minted as fees.
     */
    function updateFeeRecipient(address _feeRecipient) external onlyRole(OWNER_ROLE) {
        if (_feeRecipient == address(0)) revert InvalidFeeRecipient();
        feeRecipient = _feeRecipient;
        emit UpdateFeeRecipient(_feeRecipient);
    }

    /**
     * @notice Add markets that can be supplied and withdrawn from.
     * @dev Elements in `supportedMarkets` must be a valid IonPool or an IDLE
     * address. Valid IonPools require the base asset to be the same. Duplicate
     * addition to the EnumerableSet will revert. The allocationCaps of the
     * new markets being introduced must be set.
     * It MUST be enforced that each IonPool's RewardToken `_decimals` is equal
     * to the decimals of this vault's base asset.
     * @param marketsToAdd Array of new markets to be added.
     * @param allocationCaps Array of allocation caps for only the markets to be added.
     * @param newSupplyQueue Desired supply queue of IonPools for all resulting supported markets.
     * @param newWithdrawQueue Desired withdraw queue of IonPools for all resulting supported markets.
     */
    function addSupportedMarkets(
        IIonPool[] memory marketsToAdd,
        uint256[] memory allocationCaps,
        IIonPool[] memory newSupplyQueue,
        IIonPool[] memory newWithdrawQueue
    )
        external
        onlyRole(OWNER_ROLE)
    {
        _addSupportedMarkets(marketsToAdd, allocationCaps, newSupplyQueue, newWithdrawQueue);
    }

    function _addSupportedMarkets(
        IIonPool[] memory marketsToAdd,
        uint256[] memory allocationCaps,
        IIonPool[] memory newSupplyQueue,
        IIonPool[] memory newWithdrawQueue
    )
        internal
    {
        if (marketsToAdd.length != allocationCaps.length) revert MarketsAndAllocationCapLengthMustBeEqual();

        uint256 marketsToAddLength = marketsToAdd.length;
        uint8 baseAssetDecimals = IERC20Metadata(address(BASE_ASSET)).decimals();
        for (uint256 i; i != marketsToAddLength;) {
            IIonPool pool = marketsToAdd[i];

            if (pool != IDLE) {
                if (pool.decimals() != baseAssetDecimals) revert InvalidIonPoolDecimals(pool);
                if (address(pool.underlying()) != address(BASE_ASSET)) revert InvalidUnderlyingAsset(pool);

                BASE_ASSET.approve(address(pool), type(uint256).max);
            }

            if (!supportedMarkets.add(address(pool))) revert MarketAlreadySupported(pool);

            caps[pool] = allocationCaps[i];

            unchecked {
                ++i;
            }
        }

        if (supportedMarkets.length() > MAX_SUPPORTED_MARKETS) revert MaxSupportedMarketsReached();

        _updateSupplyQueue(newSupplyQueue);
        _updateWithdrawQueue(newWithdrawQueue);

        emit AddSupportedMarkets(marketsToAdd);
    }

    /**
     * @notice Removes a supported market and updates the supply and withdraw
     * queues without the removed market.
     * @dev The allocationCap values of the markets being removed are
     * automatically deleted. Whenever a market is removed, the queues must be
     * updated without the removed market.
     * @param marketsToRemove Markets being removed.
     * @param newSupplyQueue Desired supply queue of all supported markets after
     * the removal.
     * @param newWithdrawQueue Desired withdraw queue of all supported markets
     * after the removal.
     */
    function removeSupportedMarkets(
        IIonPool[] calldata marketsToRemove,
        IIonPool[] calldata newSupplyQueue,
        IIonPool[] calldata newWithdrawQueue
    )
        external
        onlyRole(OWNER_ROLE)
    {
        uint256 marketsToRemoveLength = marketsToRemove.length;
        for (uint256 i; i != marketsToRemoveLength;) {
            IIonPool pool = marketsToRemove[i];

            if (pool == IDLE) {
                if (BASE_ASSET.balanceOf(address(this)) != 0) revert InvalidIdleMarketRemovalNonZeroBalance();
            } else {
                // Checks `normalizedBalanceOf` as it may be possible that
                // `balanceOf` returns zero even though the
                // `normalizedBalance` is zero.
                if (pool.normalizedBalanceOf(address(this)) != 0) revert InvalidMarketRemovalNonZeroSupply(pool);
                BASE_ASSET.approve(address(pool), 0);
            }

            if (!supportedMarkets.remove(address(pool))) revert MarketNotSupported(pool);
            delete caps[pool];

            unchecked {
                ++i;
            }
        }
        _updateSupplyQueue(newSupplyQueue);
        _updateWithdrawQueue(newWithdrawQueue);

        emit RemoveSupportedMarkets(marketsToRemove);
    }

    /**
     * @notice Update the order of the markets in which user deposits are supplied.
     * @dev Each IonPool in the queue must be part of the `supportedMarkets` set.
     * @param newSupplyQueue The new supply queue ordering.
     */
    function updateSupplyQueue(IIonPool[] memory newSupplyQueue) external onlyRole(ALLOCATOR_ROLE) {
        _updateSupplyQueue(newSupplyQueue);
    }

    function _updateSupplyQueue(IIonPool[] memory newSupplyQueue) internal {
        _validateQueueInput(newSupplyQueue);

        supplyQueue = newSupplyQueue;

        emit UpdateSupplyQueue(_msgSender(), newSupplyQueue);
    }

    /**
     * @notice Update the order of the markets in which the deposits are withdrawn.
     * @dev The IonPool in the queue must be part of the `supportedMarkets` set.
     * @param newWithdrawQueue The new withdraw queue ordering.
     */
    function updateWithdrawQueue(IIonPool[] memory newWithdrawQueue) external onlyRole(ALLOCATOR_ROLE) {
        _updateWithdrawQueue(newWithdrawQueue);
    }

    function _updateWithdrawQueue(IIonPool[] memory newWithdrawQueue) internal {
        _validateQueueInput(newWithdrawQueue);

        withdrawQueue = newWithdrawQueue;

        emit UpdateWithdrawQueue(_msgSender(), newWithdrawQueue);
    }

    /**
     * @dev The input array contains ordered IonPools.
     * - Must not contain duplicates.
     * - Must be the same length as the `supportedMarkets` array.
     * - Must not contain indices that are out of bounds of the `supportedMarkets` EnumerableSet's underlying array.
     * The above rule enforces that the queue must have all and only the elements in the `supportedMarkets` set.
     * @param queue The queue being validated.
     */
    function _validateQueueInput(IIonPool[] memory queue) internal view {
        uint256 _supportedMarketsLength = supportedMarkets.length();
        uint256 queueLength = queue.length;

        if (queueLength != _supportedMarketsLength) revert InvalidQueueLength(queueLength, _supportedMarketsLength);

        bool[] memory seen = new bool[](queueLength);

        for (uint256 i; i != queueLength;) {
            // If the pool is not supported, this query reverts.
            uint256 index = _supportedMarketsIndexOf(address(queue[i]));

            if (seen[index] == true) revert InvalidQueueContainsDuplicates();

            seen[index] = true;

            unchecked {
                ++i;
            }
        }
    }

    /**
     * @notice Update allocation caps for specified IonPools or the IDLE pool.
     * @dev The allocation caps are applied to pools in the order of the
     * `ionPool` array argument. The elements inside `ionPools` must exist in
     * `supportedMarkets`. To update the `IDLE` pool, use the `IDLE` constant
     * address.
     * @param ionPools The array of IonPools whose caps will be updated.
     * @param newCaps The array of new allocation caps to be applied.
     */
    function updateAllocationCaps(
        IIonPool[] calldata ionPools,
        uint256[] calldata newCaps
    )
        external
        onlyRole(OWNER_ROLE)
    {
        uint256 ionPoolsLength = ionPools.length;
        if (ionPoolsLength != newCaps.length) revert IonPoolsArrayAndNewCapsArrayMustBeOfEqualLength();

        for (uint256 i; i != ionPoolsLength;) {
            IIonPool pool = ionPools[i];
            if (!supportedMarkets.contains(address(pool))) revert MarketNotSupported(pool);
            caps[pool] = newCaps[i];

            unchecked {
                ++i;
            }
        }

        emit UpdateAllocationCaps(ionPools, newCaps);
    }

    /**
     * @notice Reallocates the base asset supply position across the specified
     * IonPools. This call will revert if the resulting allocation in an IonPool
     * violates the pool's supply cap.
     * @dev Depending on the order of deposits and withdrawals to and from
     * markets, the function could revert if there is not enough assets
     * withdrawn to deposit later in the loop. A key invariant is that the total
     * assets withdrawn should be equal to the total assets supplied. Otherwise,
     * revert.
     * - Negative value indicates a withdrawal.
     * - Positive value indicates a supply.
     * @param allocations Array that indicates how much to deposit or withdraw
     * from each market.
     */
    function reallocate(MarketAllocation[] calldata allocations) external onlyRole(ALLOCATOR_ROLE) nonReentrant {
        uint256 totalSupplied;
        uint256 totalWithdrawn;

        uint256 currentIdleDeposits = BASE_ASSET.balanceOf(address(this));

        uint256 allocationsLength = allocations.length;
        for (uint256 i; i != allocationsLength;) {
            MarketAllocation calldata allocation = allocations[i];
            IIonPool pool = allocation.pool;

            _supportedMarketsIndexOf(address(pool)); // Checks if the pool is supported

            uint256 currentSupplied = pool == IDLE ? currentIdleDeposits : pool.balanceOf(address(this));
            int256 assets = allocation.assets; // to deposit or withdraw

            // if `assets` is `type(int256).min`, this means fully withdraw from the market.
            // This prevents frontrunning in case the market needs to be fully withdrawn
            // from in order to remove the market.
            uint256 transferAmt;
            if (assets < 0) {
                if (assets == type(int256).min) {
                    // The resulting shares from full withdraw must be zero.
                    transferAmt = currentSupplied;
                } else {
                    transferAmt = uint256(-assets);
                }

                // If `IDLE`, the asset is already held by this contract, no
                // need to withdraw from a pool. The asset will be transferred
                // to the user from the previous function scope.
                if (pool != IDLE) {
                    pool.withdraw(address(this), transferAmt);
                } else {
                    currentIdleDeposits -= transferAmt;
                }

                totalWithdrawn += transferAmt;

                emit ReallocateWithdraw(pool, transferAmt);
            } else if (assets > 0) {
                // It is not possible to predict the exact amount of assets that
                // will be withdrawn when using the `type(int256).min` indicator
                // in previous iterations of the loop due to the per-second
                // interest rate accrual. Therefore, the `max` indicator is
                // necessary to be able to fully deposit the total withdrawn
                // amount.
                if (assets == type(int256).max) {
                    transferAmt = totalWithdrawn;
                } else {
                    transferAmt = uint256(assets);
                }

                uint256 resultingSupplied = currentSupplied + transferAmt;
                uint256 allocationCap = caps[pool];
                if (resultingSupplied > allocationCap) {
                    revert AllocationCapExceeded(resultingSupplied, allocationCap);
                }

                // If the assets are being deposited to IDLE, then no need for
                // additional transfers as the balance is already in this
                // contract.
                if (pool != IDLE) {
                    pool.supply(address(this), transferAmt, new bytes32[](0));
                } else {
                    currentIdleDeposits += transferAmt;
                }

                totalSupplied += transferAmt;

                emit ReallocateSupply(pool, transferAmt);
            }

            unchecked {
                ++i;
            }
        }

        if (totalSupplied != totalWithdrawn) revert InvalidReallocation(totalSupplied, totalWithdrawn);
    }

    /**
     * @notice Manually accrues fees and mints shares to the fee recipient.
     */
    function accrueFee() external onlyRole(OWNER_ROLE) returns (uint256 newTotalAssets) {
        return _accrueFee();
    }

    // --- IonPool Interactions ---

    /**
     * @notice Iterates through the supply queue to deposit the desired amount
     * of assets. Reverts if the deposit amount cannot be filled due to the
     * allocation cap or the supply cap.
     * @dev External functions calling this must be non-reentrant in case the
     * underlying IonPool implements callback logic.
     * @param assets The amount of assets that will attempt to be supplied.
     */
    function _supplyToIonPool(uint256 assets) internal {
        // This function is called after the `BASE_ASSET` is transferred to the
        // contract for the supply iterations. The `assets` is subtracted to
        // retrieve the `BASE_ASSET` balance before this transaction began.
        uint256 currentIdleDeposits = BASE_ASSET.balanceOf(address(this)) - assets;
        uint256 supplyQueueLength = supplyQueue.length;

        for (uint256 i; i != supplyQueueLength;) {
            IIonPool pool = supplyQueue[i];
            uint256 depositable = pool == IDLE ? _zeroFloorSub(caps[pool], currentIdleDeposits) : _depositable(pool);
            if (depositable != 0) {
                uint256 toSupply = Math.min(depositable, assets);

                if (pool != IDLE) {
                    // Early exit ok since this is the last remaining part of
                    // the user's requested amount and the deposit will
                    // normalize to zero. Note that this dust amount has already
                    // been transferred to the vault but is not a 'donation'  as
                    // this amount was accounted for when calculating the amount
                    // of shares to mint.
                    uint256 normalizedSupply = toSupply.mulDiv(RAY, pool.supplyFactor());
                    if (toSupply == assets && normalizedSupply == 0) {
                        return;
                    } else {
                        // If this call reverts by trying to mint zero shares
                        // with a small supply amount, skip to the next
                        // iteration.
                        try pool.supply(address(this), toSupply, new bytes32[](0)) {
                            assets -= toSupply;
                            // solhint-disable-next-line no-empty-blocks
                        } catch { }
                    }
                } else {
                    assets -= toSupply;
                }

                if (assets == 0) return;
            }

            unchecked {
                ++i;
            }
        }
        if (assets != 0) revert AllSupplyCapsReached();
    }

    /**
     * @notice Iterates through the withdraw queue to withdraw the desired
     * amount of assets. Will revert if there is not enough liquidity or if
     * trying to withdraw more than the caller owns.
     * @dev External functions calling this must be non-reentrant in case the
     * underlying IonPool implements callback logic.
     * @param assets The desired amount of assets to be withdrawn.
     */
    function _withdrawFromIonPool(uint256 assets) internal {
        uint256 currentIdleDeposits = BASE_ASSET.balanceOf(address(this));
        uint256 withdrawQueueLength = withdrawQueue.length;

        for (uint256 i; i != withdrawQueueLength;) {
            IIonPool pool = withdrawQueue[i];

            uint256 withdrawable = pool == IDLE ? currentIdleDeposits : _withdrawable(pool);

            if (withdrawable != 0) {
                uint256 toWithdraw = Math.min(withdrawable, assets);

                // For the `IDLE` pool, they are already on this contract's
                // balance. Update `assets` accumulator but don't actually
                // transfer. If the pool withdraw reverts, simply skip to the
                // next iteration.
                if (pool != IDLE) {
                    // This will never throw InvalidBurnAmount since
                    // `toWithdraw` is non-zero which means the normalized
                    // shares to burn inside the IonPool must be non-zero.
                    try pool.withdraw(address(this), toWithdraw) {
                        assets -= toWithdraw;
                        // solhint-disable-next-line no-empty-blocks
                    } catch { }
                } else {
                    assets -= toWithdraw;
                }

                if (assets == 0) return;
            }

            unchecked {
                ++i;
            }
        }

        if (assets != 0) revert NotEnoughLiquidityToWithdraw();
    }

    // --- ERC4626 External Functions ---

    /**
     * @inheritdoc IERC4626
     * @notice Transfers the specified amount of assets from the sender,
     * supplies into the underlying
     * IonPool markets, and mints a corresponding amount of shares.
     * @dev All incoming deposits are deposited in the order specified in the deposit queue.
     * @param assets Amount of tokens to be deposited.
     * @param receiver The address to receive the minted shares.
     */
    function deposit(uint256 assets, address receiver) public override nonReentrant returns (uint256 shares) {
        uint256 newTotalAssets = _accrueFee();

        shares = _convertToSharesWithTotals(assets, totalSupply(), newTotalAssets, Math.Rounding.Floor);
        _deposit(_msgSender(), receiver, assets, shares);
    }

    /**
     * @inheritdoc IERC4626
     * @notice Mints the specified amount of shares and deposits a corresponding
     * amount of assets.
     * @dev Converts the shares to assets and iterates through the deposit queue
     * to allocate the deposit across the supported markets.
     * @param shares The exact amount of shares to be minted.
     * @param receiver The address to receive the minted shares.
     */
    function mint(uint256 shares, address receiver) public override nonReentrant returns (uint256 assets) {
        uint256 newTotalAssets = _accrueFee();

        assets = _convertToAssetsWithTotals(shares, totalSupply(), newTotalAssets, Math.Rounding.Ceil);

        _deposit(_msgSender(), receiver, assets, shares);
    }

    /**
     * @notice Withdraws specified amount of assets from IonPools and sends them
     * to the receiver in exchange for burning the owner's vault shares.
     * @dev All withdraws are withdrawn in the order specified in the withdraw
     * queue. The owner needs to approve the caller to spend their shares.
     * @param assets The exact amount of assets to be transferred out.
     * @param receiver The receiver of the assets transferred.
     * @param owner The owner of the vault shares.
     */
    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    )
        public
        override
        nonReentrant
        returns (uint256 shares)
    {
        uint256 newTotalAssets = _accrueFee();
        shares = _convertToSharesWithTotals(assets, totalSupply(), newTotalAssets, Math.Rounding.Ceil);
        _updateLastTotalAssets(_zeroFloorSub(newTotalAssets, assets));

        _withdraw(_msgSender(), receiver, owner, assets, shares);
    }

    /**
     * @inheritdoc IERC4626
     * @notice Redeems the exact amount of shares and receives a corresponding
     * amount of assets.
     * @dev After withdrawing `assets`, the user gets exact `assets` out. But in
     * the IonPool, the resulting total underlying claim may have decreased
     * by a bit above the `assets` amount due to rounding in the pool's favor.
     *
     * In that case, the resulting `totalAssets()` will be smaller than just
     * the `newTotalAssets - assets`. Predicting the exact resulting
     * totalAssets() requires knowing how much liquidity is being withdrawn
     * from each pool, which is not possible to know until the actual
     * iteration on the withdraw queue. So we acknowledge the dust
     * difference here.
     *
     * If the `lastTotalAssets` is slightly greater than the actual `totalAssets`,
     * the impact will be that the calculated interest accrued during fee distribution will be slightly less than the
     * true value.
     * @param shares The exact amount of shares to be burned and redeemed.
     * @param receiver The address that receives the transferred assets.
     * @param owner The address that holds the shares to be redeemed.
     */
    function redeem(
        uint256 shares,
        address receiver,
        address owner
    )
        public
        override
        nonReentrant
        returns (uint256 assets)
    {
        uint256 newTotalAssets = _accrueFee();

        assets = _convertToAssetsWithTotals(shares, totalSupply(), newTotalAssets, Math.Rounding.Floor);

        _updateLastTotalAssets(newTotalAssets - assets);

        _withdraw(_msgSender(), receiver, owner, assets, shares);
    }

    /**
     * @inheritdoc IERC20Metadata
     */
    function decimals() public view override(ERC4626) returns (uint8) {
        return ERC4626.decimals();
    }

    /**
     * @inheritdoc IERC4626
     * @notice Returns the maximum amount of assets that the vault can supply on
     * Ion.
     * @dev The max deposit amount is limited by the vault's allocation cap and
     * the underlying IonPools' supply caps.
     * @return The max amount of assets that can be supplied.
     */
    function maxDeposit(address) public view override returns (uint256) {
        return _maxDeposit();
    }

    /**
     * @inheritdoc IERC4626
     * @notice Returns the maximum amount of vault shares that can be minted.
     * @dev Max mint is limited by the max deposit based on the Vault's
     * allocation caps and the IonPools' supply caps. The conversion from max
     * suppliable assets to shares preempts the shares minted from fee accrual.
     * @return The max amount of shares that can be minted.
     */
    function maxMint(address) public view override returns (uint256) {
        uint256 suppliable = _maxDeposit();

        return _convertToSharesWithFees(suppliable, Math.Rounding.Floor);
    }

    /**
     * @inheritdoc IERC4626
     * @notice Returns the maximum amount of assets that can be withdrawn.
     * @dev Max withdraw is limited by the owner's shares and the  liquidity
     * available to be withdrawn from the underlying IonPools. The max
     * withdrawable claim is inclusive of accrued interest and the extra shares
     * minted to the fee recipient.
     * @param owner The address that holds the assets.
     * @return assets The max amount of assets that can be withdrawn.
     */
    function maxWithdraw(address owner) public view override returns (uint256 assets) {
        (assets,,) = _maxWithdraw(owner);
    }

    /**
     * @inheritdoc IERC4626
     * @notice Calculates the total withdrawable amount based on the available
     * liquidity in the underlying pools and converts it to redeemable shares.
     * @dev Max redeem is derived from çonverting the `_maxWithdraw` to shares.
     * The conversion takes into account the total supply and total assets
     * inclusive of accrued interest and the extra shares minted to the fee
     * recipient.
     * @param owner The address that holds the shares.
     * @return The max amount of shares that can be withdrawn.
     */
    function maxRedeem(address owner) public view override returns (uint256) {
        (uint256 assets, uint256 newTotalSupply, uint256 newTotalAssets) = _maxWithdraw(owner);
        return _convertToSharesWithTotals(assets, newTotalSupply, newTotalAssets, Math.Rounding.Floor);
    }

    /**
     * @notice Returns the total claim that the vault has across all supported IonPools.
     * @dev `IonPool.balanceOf` returns the rebasing balance of the
     * lender receipt token that is pegged 1:1 to the underlying supplied asset.
     * @return assets The total assets held on the contract and inside the underlying
     * pools by this vault.
     */
    function totalAssets() public view override returns (uint256 assets) {
        uint256 _supportedMarketsLength = supportedMarkets.length();
        for (uint256 i; i != _supportedMarketsLength;) {
            IIonPool pool = IIonPool(supportedMarkets.at(i));

            uint256 assetsInPool = pool == IDLE ? BASE_ASSET.balanceOf(address(this)) : pool.balanceOf(address(this));

            assets += assetsInPool;

            unchecked {
                ++i;
            }
        }
    }

    /**
     * @inheritdoc IERC4626
     * @dev Inclusive of manager fee.
     */
    function previewDeposit(uint256 assets) public view override returns (uint256) {
        return _convertToSharesWithFees(assets, Math.Rounding.Floor);
    }

    /**
     * @inheritdoc IERC4626
     * @dev Inclusive of manager fee.
     */
    function previewMint(uint256 shares) public view override returns (uint256) {
        return _convertToAssetsWithFees(shares, Math.Rounding.Ceil);
    }

    /**
     * @inheritdoc IERC4626
     * @dev Inclusive of manager fee.
     */
    function previewWithdraw(uint256 assets) public view override returns (uint256) {
        return _convertToSharesWithFees(assets, Math.Rounding.Ceil);
    }

    /**
     * @inheritdoc IERC4626
     * @dev Inclusive of manager fee.
     */
    function previewRedeem(uint256 shares) public view override returns (uint256) {
        return _convertToAssetsWithFees(shares, Math.Rounding.Floor);
    }

    // --- ERC4626 Internal Functions ---

    function _decimalsOffset() internal view override returns (uint8) {
        return DECIMALS_OFFSET;
    }

    function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal override {
        super._deposit(caller, receiver, assets, shares);
        _supplyToIonPool(assets);
        _updateLastTotalAssets(lastTotalAssets + assets);
    }

    function _withdraw(
        address caller,
        address receiver,
        address owner,
        uint256 assets,
        uint256 shares
    )
        internal
        override
    {
        _withdrawFromIonPool(assets);

        super._withdraw(caller, receiver, owner, assets, shares);
    }

    function _maxDeposit() internal view returns (uint256 maxDepositable) {
        uint256 supportedMarketsLength = supportedMarkets.length();

        for (uint256 i; i != supportedMarketsLength;) {
            IIonPool pool = IIonPool(supportedMarkets.at(i));

            uint256 depositable =
                pool == IDLE ? _zeroFloorSub(caps[pool], BASE_ASSET.balanceOf(address(this))) : _depositable(pool);

            maxDepositable += depositable;

            unchecked {
                ++i;
            }
        }
    }

    function _maxWithdraw(address owner)
        internal
        view
        returns (uint256 assets, uint256 newTotalSupply, uint256 newTotalAssets)
    {
        uint256 feeShares;
        (feeShares, newTotalAssets) = _accruedFeeShares();
        newTotalSupply = totalSupply() + feeShares;

        uint256 shareBalances = balanceOf(owner);
        if (owner == feeRecipient) {
            shareBalances += feeShares;
        }

        assets = _convertToAssetsWithTotals(shareBalances, newTotalSupply, newTotalAssets, Math.Rounding.Floor);

        assets -= _simulateWithdrawIon(assets);
    }

    // --- Internal ---

    function _accrueFee() internal returns (uint256 newTotalAssets) {
        uint256 feeShares;
        (feeShares, newTotalAssets) = _accruedFeeShares();
        if (feeShares != 0) _mint(feeRecipient, feeShares);

        _updateLastTotalAssets(newTotalAssets);

        emit FeeAccrued(feeShares, newTotalAssets);
    }

    /**
     * @dev The total accrued vault revenue is the difference in the total
     * iToken holdings from the last accrued timestamp and now.
     */
    function _accruedFeeShares() internal view returns (uint256 feeShares, uint256 newTotalAssets) {
        newTotalAssets = totalAssets();
        uint256 totalInterest = _zeroFloorSub(newTotalAssets, lastTotalAssets);

        // The new amount of new iTokens that were created for this vault. A
        // portion of this should be claimable by depositors and some portion of
        // this should be claimable by the fee recipient.
        if (totalInterest != 0 && feePercentage != 0) {
            uint256 feeAssets = totalInterest.mulDiv(feePercentage, RAY);

            feeShares =
                _convertToSharesWithTotals(feeAssets, totalSupply(), newTotalAssets - feeAssets, Math.Rounding.Floor);
        }
    }

    /**
     * @dev NOTE The IERC4626 natspec recommends that the `_convertToAssets` and `_convertToShares` "MUST NOT be
     * inclusive of any fees that are charged against assets in the Vault."
     * However, all deposit/mint/withdraw/redeem flow will accrue fees before
     * processing user requests, so manager fee must be accounted for to accurately reflect the resulting state.
     * All preview functions will rely on this `WithFees` version of the `_convertTo` function.
     */
    function _convertToSharesWithFees(uint256 assets, Math.Rounding rounding) internal view returns (uint256) {
        (uint256 feeShares, uint256 newTotalAssets) = _accruedFeeShares();

        return _convertToSharesWithTotals(assets, totalSupply() + feeShares, newTotalAssets, rounding);
    }

    /**
     * @dev NOTE The IERC4626 natspec recommends that the `_convertToAssets` and `_convertToShares` "MUST NOT be
     * inclusive of any fees that are charged against assets in the Vault."
     * However, all deposit/mint/withdraw/redeem flow will accrue fees before
     * processing user requests, so manager fee must be accounted for to accurately reflect the resulting state.
     * All preview functions will rely on this `WithFees` version of the `_convertTo` function.
     */
    function _convertToAssetsWithFees(uint256 shares, Math.Rounding rounding) internal view returns (uint256) {
        (uint256 feeShares, uint256 newTotalAssets) = _accruedFeeShares();

        return _convertToAssetsWithTotals(shares, totalSupply() + feeShares, newTotalAssets, rounding);
    }

    /**
     * @dev Returns the amount of shares that the vault would exchange for the
     * amount of `assets` provided. This function is used to calculate the
     * conversion between shares and assets with parameterizable total supply
     * and total assets variables.
     */
    function _convertToSharesWithTotals(
        uint256 assets,
        uint256 newTotalSupply,
        uint256 newTotalAssets,
        Math.Rounding rounding
    )
        internal
        view
        returns (uint256)
    {
        return assets.mulDiv(newTotalSupply + 10 ** _decimalsOffset(), newTotalAssets + 1, rounding);
    }

    /**
     * @dev Returns the amount of assets that the vault would exchange for the
     * amount of `shares` provided. This function is used to calculate the
     * conversion between shares and assets with parameterizable total supply
     * and total assets variables.
     */
    function _convertToAssetsWithTotals(
        uint256 shares,
        uint256 newTotalSupply,
        uint256 newTotalAssets,
        Math.Rounding rounding
    )
        internal
        view
        returns (uint256)
    {
        return shares.mulDiv(newTotalAssets + 1, newTotalSupply + 10 ** _decimalsOffset(), rounding);
    }

    function _updateLastTotalAssets(uint256 newLastTotalAssets) internal {
        lastTotalAssets = newLastTotalAssets;
        emit UpdateLastTotalAssets(lastTotalAssets, newLastTotalAssets);
    }

    function _zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        assembly {
            z := mul(gt(x, y), sub(x, y))
        }
    }

    /**
     * @dev Emulates the actual `_withdrawFromIonPool` accounting to predict
     * accurately how much of the input assets will be left after withdrawing as much as it can. The
     * difference between this return value and the input `assets` is the exact
     * amount that will be withdrawn.
     * @return The remaining assets to be withdrawn. NOT the amount of assets that were withdrawn.
     */
    function _simulateWithdrawIon(uint256 assets) internal view returns (uint256) {
        uint256 withdrawQueueLength = withdrawQueue.length;
        for (uint256 i; i != withdrawQueueLength;) {
            IIonPool pool = withdrawQueue[i];

            uint256 withdrawable = pool == IDLE ? BASE_ASSET.balanceOf(address(this)) : _withdrawable(pool);

            uint256 toWithdraw = Math.min(withdrawable, assets);
            assets -= toWithdraw;

            if (assets == 0) break;

            unchecked {
                ++i;
            }
        }

        return assets; // the remaining assets after withdraw
    }

    /**
     * @dev The max amount of assets withdrawable from a given IonPool
     * considering the vault's claim and the available liquidity. A minimum of
     * this contract's total claim on the underlying and the available liquidity
     * in the pool.
     * @return The max amount of assets withdrawable from this IonPool.
     */
    function _withdrawable(IIonPool pool) internal view returns (uint256) {
        if (pool.paused()) return 0;

        uint256 currentSupplied = pool.balanceOf(address(this));

        uint256 availableLiquidity = uint256(pool.extsload(ION_POOL_LIQUIDITY_SLOT));
        return Math.min(currentSupplied, availableLiquidity);
    }

    /**
     * @dev The max amount of assets depositable to a given IonPool. Depositing
     * the minimum between the two diffs ensures that the deposit will not
     * violate the allocation cap or the supply cap.
     * @return The max amount of assets depositable to this IonPool.
     */
    function _depositable(IIonPool pool) internal view returns (uint256) {
        if (pool.paused()) return 0;

        uint256 allocationCapDiff = _zeroFloorSub(caps[pool], pool.balanceOf(address(this)));
        uint256 supplyCapDiff = _zeroFloorSub(uint256(pool.extsload(ION_POOL_SUPPLY_CAP_SLOT)), pool.totalSupply());

        return Math.min(allocationCapDiff, supplyCapDiff);
    }

    // --- EnumerableSet.Address Getters ---

    /**
     * @notice Returns the array representation of the `supportedMarkets` set.
     * @return Array of supported IonPools.
     */
    function getSupportedMarkets() external view returns (address[] memory) {
        return supportedMarkets.values();
    }

    /**
     * @notice Returns whether the market is part of the `supportedMarkets` set.
     * @param pool The address of the IonPool to be checked.
     * @return The pool is supported if true. If not, false.
     */
    function containsSupportedMarket(address pool) external view returns (bool) {
        return supportedMarkets.contains(pool);
    }

    /**
     * @notice Returns the element in the array representation of
     * `supportedMarkets`. `index` must be strictly less than the length of the
     * array.
     * @param index The index to be queried on the `supportedMarkets` array.
     * @return Address at the index of `supportedMarkets`.
     */
    function supportedMarketsAt(uint256 index) external view returns (address) {
        return supportedMarkets.at(index);
    }

    /**
     * @notice Returns the index of the specified market in the array representation of `supportedMarkets`.
     * @dev The `_positions` mapping inside the `EnumerableSet.Set` returns the
     * index of the element in the `_values` array plus 1. The `_positions`
     * value of 0 means that the value is not in the set. If the value is not in
     * the set, this call will revert. Otherwise, it will return the `position -
     * 1` value to return the index of the element in the array.
     * @param pool The address of the IonPool to be queried.
     * @return The index of the pool's location in the array. The return value
     * will always be greater than zero as this function would revert if the
     * market is not part of the set.
     */
    function supportedMarketsIndexOf(address pool) external view returns (uint256) {
        return _supportedMarketsIndexOf(pool);
    }

    /**
     * @notice Length of the array representation of `supportedMarkets`.
     * @return The length of the `supportedMarkets` array.
     */
    function supportedMarketsLength() external view returns (uint256) {
        return supportedMarkets.length();
    }

    function _supportedMarketsIndexOf(address pool) internal view returns (uint256) {
        bytes32 key = bytes32(uint256(uint160(pool)));
        uint256 position = supportedMarkets._inner._positions[key];
        if (position == 0) revert MarketNotSupported(IIonPool(pool));
        return --position;
    }
}

File 2 of 26 : IIonPool.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

interface IIonPool {
    error AccessControlBadConfirmation();
    error AccessControlEnforcedDefaultAdminDelay(uint48 schedule);
    error AccessControlEnforcedDefaultAdminRules();
    error AccessControlInvalidDefaultAdmin(address defaultAdmin);
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
    error AddressEmptyCode(address target);
    error AddressInsufficientBalance(address account);
    error ArithmeticError();
    error CeilingExceeded(uint256 newDebt, uint256 debtCeiling);
    error DepositSurpassesSupplyCap(uint256 depositAmount, uint256 supplyCap);
    error EnforcedPause();
    error ExpectedPause();
    error FailedInnerCall();
    error GemTransferWithoutConsent(uint8 ilkIndex, address user, address unconsentedOperator);
    error IlkAlreadyAdded(address ilkAddress);
    error IlkNotInitialized(uint256 ilkIndex);
    error InsufficientBalance(address account, uint256 balance, uint256 needed);
    error InvalidBurnAmount();
    error InvalidIlkAddress();
    error InvalidInitialization();
    error InvalidInterestRateModule(address invalidInterestRateModule);
    error InvalidMintAmount();
    error InvalidReceiver(address receiver);
    error InvalidSender(address sender);
    error InvalidTreasuryAddress();
    error InvalidUnderlyingAddress();
    error InvalidWhitelist();
    error MathOverflowedMulDiv();
    error MaxIlksReached();
    error NotInitializing();
    error NotScalingUp(uint256 from, uint256 to);
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
    error SafeCastOverflowedUintToInt(uint256 value);
    error SafeERC20FailedOperation(address token);
    error TakingWethWithoutConsent(address payer, address unconsentedOperator);
    error UnsafePositionChange(uint256 newTotalDebtInVault, uint256 collateral, uint256 spot);
    error UnsafePositionChangeWithoutConsent(uint8 ilkIndex, address user, address unconsentedOperator);
    error UseOfCollateralWithoutConsent(uint8 ilkIndex, address depositor, address unconsentedOperator);
    error VaultCannotBeDusty(uint256 amountLeft, uint256 dust);

    event AddOperator(address indexed user, address indexed operator);
    event Borrow(
        uint8 indexed ilkIndex,
        address indexed user,
        address indexed recipient,
        uint256 amountOfNormalizedDebt,
        uint256 ilkRate,
        uint256 totalDebt
    );
    event ConfiscateVault(
        uint8 indexed ilkIndex,
        address indexed u,
        address v,
        address indexed w,
        int256 changeInCollateral,
        int256 changeInNormalizedDebt
    );
    event DefaultAdminDelayChangeCanceled();
    event DefaultAdminDelayChangeScheduled(uint48 newDelay, uint48 effectSchedule);
    event DefaultAdminTransferCanceled();
    event DefaultAdminTransferScheduled(address indexed newAdmin, uint48 acceptSchedule);
    event DepositCollateral(uint8 indexed ilkIndex, address indexed user, address indexed depositor, uint256 amount);
    event IlkDebtCeilingUpdated(uint8 indexed ilkIndex, uint256 newDebtCeiling);
    event IlkDustUpdated(uint8 indexed ilkIndex, uint256 newDust);
    event IlkInitialized(uint8 indexed ilkIndex, address indexed ilkAddress);
    event IlkSpotUpdated(uint8 indexed ilkIndex, address newSpot);
    event Initialized(uint64 version);
    event InterestRateModuleUpdated(address newModule);
    event MintAndBurnGem(uint8 indexed ilkIndex, address indexed usr, int256 wad);
    event MintToTreasury(address indexed treasury, uint256 amount, uint256 supplyFactor);
    event Paused(address account);
    event RemoveOperator(address indexed user, address indexed operator);
    event Repay(
        uint8 indexed ilkIndex,
        address indexed user,
        address indexed payer,
        uint256 amountOfNormalizedDebt,
        uint256 ilkRate,
        uint256 totalDebt
    );
    event RepayBadDebt(address indexed user, address indexed payer, uint256 rad);
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
    event Supply(
        address indexed user, address indexed underlyingFrom, uint256 amount, uint256 supplyFactor, uint256 newDebt
    );
    event SupplyCapUpdated(uint256 newSupplyCap);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event TransferGem(uint8 indexed ilkIndex, address indexed src, address indexed dst, uint256 wad);
    event TreasuryUpdate(address treasury);
    event Unpaused(address account);
    event WhitelistUpdated(address newWhitelist);
    event Withdraw(address indexed user, address indexed target, uint256 amount, uint256 supplyFactor, uint256 newDebt);
    event WithdrawCollateral(uint8 indexed ilkIndex, address indexed user, address indexed recipient, uint256 amount);

    function DEFAULT_ADMIN_ROLE() external view returns (bytes32);
    function GEM_JOIN_ROLE() external view returns (bytes32);
    function ION() external view returns (bytes32);
    function LIQUIDATOR_ROLE() external view returns (bytes32);
    function PAUSE_ROLE() external view returns (bytes32);
    function acceptDefaultAdminTransfer() external;
    function accrueInterest() external returns (uint256 newTotalDebt);
    function addOperator(address operator) external;
    function addressContains(address ilk) external view returns (bool);
    function balanceOf(address user) external view returns (uint256);
    function beginDefaultAdminTransfer(address newAdmin) external;
    function borrow(
        uint8 ilkIndex,
        address user,
        address recipient,
        uint256 amountOfNormalizedDebt,
        bytes32[] memory proof
    )
        external;
    function calculateRewardAndDebtDistribution()
        external
        view
        returns (
            uint256 totalSupplyFactorIncrease,
            uint256 totalTreasuryMintAmount,
            uint104[] memory rateIncreases,
            uint256 totalDebtIncrease,
            uint48[] memory timestampIncreases
        );
    function calculateRewardAndDebtDistributionForIlk(uint8 ilkIndex)
        external
        view
        returns (uint104 newRateIncrease, uint48 timestampIncrease);
    function cancelDefaultAdminTransfer() external;
    function changeDefaultAdminDelay(uint48 newDelay) external;
    function collateral(uint8 ilkIndex, address user) external view returns (uint256);
    function confiscateVault(
        uint8 ilkIndex,
        address u,
        address v,
        address w,
        int256 changeInCollateral,
        int256 changeInNormalizedDebt
    )
        external;
    function debt() external view returns (uint256);
    function debtCeiling(uint8 ilkIndex) external view returns (uint256);
    function debtUnaccrued() external view returns (uint256);
    function decimals() external view returns (uint8);
    function defaultAdmin() external view returns (address);
    function defaultAdminDelay() external view returns (uint48);
    function defaultAdminDelayIncreaseWait() external view returns (uint48);
    function depositCollateral(
        uint8 ilkIndex,
        address user,
        address depositor,
        uint256 amount,
        bytes32[] memory proof
    )
        external;
    function dust(uint8 ilkIndex) external view returns (uint256);
    function gem(uint8 ilkIndex, address user) external view returns (uint256);
    function getCurrentBorrowRate(uint8 ilkIndex) external view returns (uint256 borrowRate, uint256 reserveFactor);
    function getIlkAddress(uint256 ilkIndex) external view returns (address);
    function getIlkIndex(address ilkAddress) external view returns (uint8);
    function getRoleAdmin(bytes32 role) external view returns (bytes32);
    function grantRole(bytes32 role, address account) external;
    function hasRole(bytes32 role, address account) external view returns (bool);
    function ilkCount() external view returns (uint256);
    function implementation() external view returns (address);
    function initialize(
        address _underlying,
        address _treasury,
        uint8 decimals_,
        string memory name_,
        string memory symbol_,
        address initialDefaultAdmin,
        address _interestRateModule,
        address _whitelist
    )
        external;
    function initializeIlk(address ilkAddress) external;
    function interestRateModule() external view returns (address);
    function isAllowed(address user, address operator) external view returns (bool);
    function isOperator(address user, address operator) external view returns (bool);
    function lastRateUpdate(uint8 ilkIndex) external view returns (uint256);
    function mintAndBurnGem(uint8 ilkIndex, address usr, int256 wad) external;
    function name() external view returns (string memory);
    function normalizedBalanceOf(address user) external view returns (uint256);
    function normalizedDebt(uint8 ilkIndex, address user) external view returns (uint256);
    function normalizedTotalSupply() external view returns (uint256);
    function normalizedTotalSupplyUnaccrued() external view returns (uint256);
    function owner() external view returns (address);
    function pause() external;
    function paused() external view returns (bool);
    function pendingDefaultAdmin() external view returns (address newAdmin, uint48 schedule);
    function pendingDefaultAdminDelay() external view returns (uint48 newDelay, uint48 schedule);
    function rate(uint8 ilkIndex) external view returns (uint256);
    function rateUnaccrued(uint8 ilkIndex) external view returns (uint256);
    function removeOperator(address operator) external;
    function renounceRole(bytes32 role, address account) external;
    function repay(uint8 ilkIndex, address user, address payer, uint256 amountOfNormalizedDebt) external;
    function repayBadDebt(address user, uint256 rad) external;
    function revokeRole(bytes32 role, address account) external;
    function rollbackDefaultAdminDelay() external;
    function spot(uint8 ilkIndex) external view returns (address);
    function supply(address user, uint256 amount, bytes32[] memory proof) external;
    function supplyFactor() external view returns (uint256);
    function supplyFactorUnaccrued() external view returns (uint256);
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
    function symbol() external view returns (string memory);
    function totalNormalizedDebt(uint8 ilkIndex) external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function totalSupplyUnaccrued() external view returns (uint256);
    function totalUnbackedDebt() external view returns (uint256);
    function transferGem(uint8 ilkIndex, address src, address dst, uint256 wad) external;
    function treasury() external view returns (address);
    function unbackedDebt(address user) external view returns (uint256);
    function underlying() external view returns (address);
    function unpause() external;
    function updateIlkDebtCeiling(uint8 ilkIndex, uint256 newCeiling) external;
    function updateIlkDust(uint8 ilkIndex, uint256 newDust) external;
    function updateIlkSpot(uint8 ilkIndex, address newSpot) external;
    function updateInterestRateModule(address _interestRateModule) external;
    function updateSupplyCap(uint256 newSupplyCap) external;
    function updateTreasury(address newTreasury) external;
    function updateWhitelist(address _whitelist) external;
    function vault(uint8 ilkIndex, address user) external view returns (uint256, uint256);
    function weth() external view returns (uint256);
    function whitelist() external view returns (address);
    function withdraw(address receiverOfUnderlying, uint256 amount) external;
    function withdrawCollateral(uint8 ilkIndex, address user, address recipient, uint256 amount) external;

    function getTotalUnderlyingClaims() external view returns (uint256);
    function getUnderlyingClaimOf(address user) external view returns (uint256);
    function extsload(bytes32 slot) external view returns (bytes32);
    function balanceOfUnaccrued(address user) external view returns (uint256);
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";

uint256 constant WAD = 1e18;
uint256 constant RAY = 1e27;
uint256 constant RAD = 1e45;

/**
 * @title WadRayMath
 *
 * @notice This library provides mul/div[up/down] functionality for WAD, RAY and
 * RAD with phantom overflow protection as well as scale[up/down] functionality
 * for WAD, RAY and RAD.
 *
 * @custom:security-contact [email protected]
 */
library WadRayMath {
    using Math for uint256;

    error NotScalingUp(uint256 from, uint256 to);
    error NotScalingDown(uint256 from, uint256 to);

    /**
     * @notice Multiplies two WAD numbers and returns the result as a WAD
     * rounding the result down.
     * @param a Multiplicand.
     * @param b Multiplier.
     */
    function wadMulDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(b, WAD);
    }

    /**
     * @notice Multiplies two WAD numbers and returns the result as a WAD
     * rounding the result up.
     * @param a Multiplicand.
     * @param b Multiplier.
     */
    function wadMulUp(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(b, WAD, Math.Rounding.Ceil);
    }

    /**
     * @notice Divides two WAD numbers and returns the result as a WAD rounding
     * the result down.
     * @param a Dividend.
     * @param b Divisor.
     */
    function wadDivDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(WAD, b);
    }

    /**
     * @notice Divides two WAD numbers and returns the result as a WAD rounding
     * the result up.
     * @param a Dividend.
     * @param b Divisor.
     */
    function wadDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(WAD, b, Math.Rounding.Ceil);
    }

    /**
     * @notice Multiplies two RAY numbers and returns the result as a RAY
     * rounding the result down.
     * @param a Multiplicand
     * @param b Multiplier
     */
    function rayMulDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(b, RAY);
    }

    /**
     * @notice Multiplies two RAY numbers and returns the result as a RAY
     * rounding the result up.
     * @param a Multiplicand
     * @param b Multiplier
     */
    function rayMulUp(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(b, RAY, Math.Rounding.Ceil);
    }

    /**
     * @notice Divides two RAY numbers and returns the result as a RAY
     * rounding the result down.
     * @param a Dividend
     * @param b Divisor
     */
    function rayDivDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(RAY, b);
    }

    /**
     * @notice Divides two RAY numbers and returns the result as a RAY
     * rounding the result up.
     * @param a Dividend
     * @param b Divisor
     */
    function rayDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(RAY, b, Math.Rounding.Ceil);
    }

    /**
     * @notice Multiplies two RAD numbers and returns the result as a RAD
     * rounding the result down.
     * @param a Multiplicand
     * @param b Multiplier
     */
    function radMulDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(b, RAD);
    }

    /**
     * @notice Multiplies two RAD numbers and returns the result as a RAD
     * rounding the result up.
     * @param a Multiplicand
     * @param b Multiplier
     */
    function radMulUp(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(b, RAD, Math.Rounding.Ceil);
    }

    /**
     * @notice Divides two RAD numbers and returns the result as a RAD rounding
     * the result down.
     * @param a Dividend
     * @param b Divisor
     */
    function radDivDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(RAD, b);
    }

    /**
     * @notice Divides two RAD numbers and returns the result as a RAD rounding
     * the result up.
     * @param a Dividend
     * @param b Divisor
     */
    function radDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mulDiv(RAD, b, Math.Rounding.Ceil);
    }

    // --- Scalers ---

    /**
     * @notice Scales a value up from WAD. NOTE: The `scale` value must be
     * less than 18.
     * @param value to scale up.
     * @param scale of the returned value.
     */
    function scaleUpToWad(uint256 value, uint256 scale) internal pure returns (uint256) {
        return scaleUp(value, scale, 18);
    }

    /**
     * @notice Scales a value up from RAY. NOTE: The `scale` value must be
     * less than 27.
     * @param value to scale up.
     * @param scale of the returned value.
     */
    function scaleUpToRay(uint256 value, uint256 scale) internal pure returns (uint256) {
        return scaleUp(value, scale, 27);
    }

    /**
     * @notice Scales a value up from RAD. NOTE: The `scale` value must be
     * less than 45.
     * @param value to scale up.
     * @param scale of the returned value.
     */
    function scaleUpToRad(uint256 value, uint256 scale) internal pure returns (uint256) {
        return scaleUp(value, scale, 45);
    }

    /**
     * @notice Scales a value down to WAD. NOTE: The `scale` value must be
     * greater than 18.
     * @param value to scale down.
     * @param scale of the returned value.
     */
    function scaleDownToWad(uint256 value, uint256 scale) internal pure returns (uint256) {
        return scaleDown(value, scale, 18);
    }

    /**
     * @notice Scales a value down to RAY. NOTE: The `scale` value must be
     * greater than 27.
     * @param value to scale down.
     * @param scale of the returned value.
     */
    function scaleDownToRay(uint256 value, uint256 scale) internal pure returns (uint256) {
        return scaleDown(value, scale, 27);
    }

    /**
     * @notice Scales a value down to RAD. NOTE: The `scale` value must be
     * greater than 45.
     * @param value to scale down.
     * @param scale of the returned value.
     */
    function scaleDownToRad(uint256 value, uint256 scale) internal pure returns (uint256) {
        return scaleDown(value, scale, 45);
    }

    /**
     * @notice Scales a value up from one fixed-point precision to another.
     * @param value to scale up.
     * @param from Precision to scale from.
     * @param to Precision to scale to.
     */
    function scaleUp(uint256 value, uint256 from, uint256 to) internal pure returns (uint256) {
        if (from >= to) revert NotScalingUp(from, to);
        return value * (10 ** (to - from));
    }

    /**
     * @notice Scales a value down from one fixed-point precision to another.
     * @param value to scale down.
     * @param from Precision to scale from.
     * @param to Precision to scale to.
     */
    function scaleDown(uint256 value, uint256 from, uint256 to) internal pure returns (uint256) {
        if (from <= to) revert NotScalingDown(from, to);
        return value / (10 ** (from - to));
    }
}

File 4 of 26 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20Metadata.sol)

pragma solidity ^0.8.20;

import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC4626.sol)

pragma solidity ^0.8.20;

import {IERC20, IERC20Metadata, ERC20} from "../ERC20.sol";
import {SafeERC20} from "../utils/SafeERC20.sol";
import {IERC4626} from "../../../interfaces/IERC4626.sol";
import {Math} from "../../../utils/math/Math.sol";

/**
 * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
 *
 * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
 * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
 * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
 * contract and not the "assets" token which is an independent contract.
 *
 * [CAUTION]
 * ====
 * In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning
 * with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation
 * attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial
 * deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may
 * similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by
 * verifying the amount received is as expected, using a wrapper that performs these checks such as
 * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router].
 *
 * Since v4.9, this implementation uses virtual assets and shares to mitigate that risk. The `_decimalsOffset()`
 * corresponds to an offset in the decimal representation between the underlying asset's decimals and the vault
 * decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which itself
 * determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default offset
 * (0) makes it non-profitable, as a result of the value being captured by the virtual shares (out of the attacker's
 * donation) matching the attacker's expected gains. With a larger offset, the attack becomes orders of magnitude more
 * expensive than it is profitable. More details about the underlying math can be found
 * xref:erc4626.adoc#inflation-attack[here].
 *
 * The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued
 * to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets
 * will cause the first user to exit to experience reduced losses in detriment to the last users that will experience
 * bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the
 * `_convertToShares` and `_convertToAssets` functions.
 *
 * To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
 * ====
 */
abstract contract ERC4626 is ERC20, IERC4626 {
    using Math for uint256;

    IERC20 private immutable _asset;
    uint8 private immutable _underlyingDecimals;

    /**
     * @dev Attempted to deposit more assets than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxDeposit(address receiver, uint256 assets, uint256 max);

    /**
     * @dev Attempted to mint more shares than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxMint(address receiver, uint256 shares, uint256 max);

    /**
     * @dev Attempted to withdraw more assets than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxWithdraw(address owner, uint256 assets, uint256 max);

    /**
     * @dev Attempted to redeem more shares than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max);

    /**
     * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
     */
    constructor(IERC20 asset_) {
        (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
        _underlyingDecimals = success ? assetDecimals : 18;
        _asset = asset_;
    }

    /**
     * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
     */
    function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
        (bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
            abi.encodeCall(IERC20Metadata.decimals, ())
        );
        if (success && encodedDecimals.length >= 32) {
            uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
            if (returnedDecimals <= type(uint8).max) {
                return (true, uint8(returnedDecimals));
            }
        }
        return (false, 0);
    }

    /**
     * @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This
     * "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the
     * asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals.
     *
     * See {IERC20Metadata-decimals}.
     */
    function decimals() public view virtual override(IERC20Metadata, ERC20) returns (uint8) {
        return _underlyingDecimals + _decimalsOffset();
    }

    /** @dev See {IERC4626-asset}. */
    function asset() public view virtual returns (address) {
        return address(_asset);
    }

    /** @dev See {IERC4626-totalAssets}. */
    function totalAssets() public view virtual returns (uint256) {
        return _asset.balanceOf(address(this));
    }

    /** @dev See {IERC4626-convertToShares}. */
    function convertToShares(uint256 assets) public view virtual returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Floor);
    }

    /** @dev See {IERC4626-convertToAssets}. */
    function convertToAssets(uint256 shares) public view virtual returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Floor);
    }

    /** @dev See {IERC4626-maxDeposit}. */
    function maxDeposit(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxMint}. */
    function maxMint(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxWithdraw}. */
    function maxWithdraw(address owner) public view virtual returns (uint256) {
        return _convertToAssets(balanceOf(owner), Math.Rounding.Floor);
    }

    /** @dev See {IERC4626-maxRedeem}. */
    function maxRedeem(address owner) public view virtual returns (uint256) {
        return balanceOf(owner);
    }

    /** @dev See {IERC4626-previewDeposit}. */
    function previewDeposit(uint256 assets) public view virtual returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Floor);
    }

    /** @dev See {IERC4626-previewMint}. */
    function previewMint(uint256 shares) public view virtual returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Ceil);
    }

    /** @dev See {IERC4626-previewWithdraw}. */
    function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Ceil);
    }

    /** @dev See {IERC4626-previewRedeem}. */
    function previewRedeem(uint256 shares) public view virtual returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Floor);
    }

    /** @dev See {IERC4626-deposit}. */
    function deposit(uint256 assets, address receiver) public virtual returns (uint256) {
        uint256 maxAssets = maxDeposit(receiver);
        if (assets > maxAssets) {
            revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets);
        }

        uint256 shares = previewDeposit(assets);
        _deposit(_msgSender(), receiver, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-mint}.
     *
     * As opposed to {deposit}, minting is allowed even if the vault is in a state where the price of a share is zero.
     * In this case, the shares will be minted without requiring any assets to be deposited.
     */
    function mint(uint256 shares, address receiver) public virtual returns (uint256) {
        uint256 maxShares = maxMint(receiver);
        if (shares > maxShares) {
            revert ERC4626ExceededMaxMint(receiver, shares, maxShares);
        }

        uint256 assets = previewMint(shares);
        _deposit(_msgSender(), receiver, assets, shares);

        return assets;
    }

    /** @dev See {IERC4626-withdraw}. */
    function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256) {
        uint256 maxAssets = maxWithdraw(owner);
        if (assets > maxAssets) {
            revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets);
        }

        uint256 shares = previewWithdraw(assets);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-redeem}. */
    function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256) {
        uint256 maxShares = maxRedeem(owner);
        if (shares > maxShares) {
            revert ERC4626ExceededMaxRedeem(owner, shares, maxShares);
        }

        uint256 assets = previewRedeem(shares);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return assets;
    }

    /**
     * @dev Internal conversion function (from assets to shares) with support for rounding direction.
     */
    function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
        return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
    }

    /**
     * @dev Internal conversion function (from shares to assets) with support for rounding direction.
     */
    function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256) {
        return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding);
    }

    /**
     * @dev Deposit/mint common workflow.
     */
    function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
        // If _asset is ERC777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
        // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
        // assets are transferred and before the shares are minted, which is a valid state.
        // slither-disable-next-line reentrancy-no-eth
        SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
        _mint(receiver, shares);

        emit Deposit(caller, receiver, assets, shares);
    }

    /**
     * @dev Withdraw/redeem common workflow.
     */
    function _withdraw(
        address caller,
        address receiver,
        address owner,
        uint256 assets,
        uint256 shares
    ) internal virtual {
        if (caller != owner) {
            _spendAllowance(owner, caller, shares);
        }

        // If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
        // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
        // shares are burned and after the assets are transferred, which is a valid state.
        _burn(owner, shares);
        SafeERC20.safeTransfer(_asset, receiver, assets);

        emit Withdraw(caller, receiver, owner, assets, shares);
    }

    function _decimalsOffset() internal view virtual returns (uint8) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

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

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

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @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 towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (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 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                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.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 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.

            uint256 twos = denominator & (0 - denominator);
            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 (unsignedRoundsUp(rounding) && 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
     * towards zero.
     *
     * 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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * 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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * 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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

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

pragma solidity ^0.8.20;

/**
 * @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 is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(bytes32 value => uint256) _positions;
    }

    /**
     * @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._positions[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 cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 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 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

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

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[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._positions[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 10 of 26 : Multicall.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Multicall.sol)

pragma solidity ^0.8.20;

import {Address} from "./Address.sol";
import {Context} from "./Context.sol";

/**
 * @dev Provides a function to batch together multiple calls in a single external call.
 *
 * Consider any assumption about calldata validation performed by the sender may be violated if it's not especially
 * careful about sending transactions invoking {multicall}. For example, a relay address that filters function
 * selectors won't filter calls nested within a {multicall} operation.
 *
 * NOTE: Since 5.0.1 and 4.9.4, this contract identifies non-canonical contexts (i.e. `msg.sender` is not {_msgSender}).
 * If a non-canonical context is identified, the following self `delegatecall` appends the last bytes of `msg.data`
 * to the subcall. This makes it safe to use with {ERC2771Context}. Contexts that don't affect the resolution of
 * {_msgSender} are not propagated to subcalls.
 */
abstract contract Multicall is Context {
    /**
     * @dev Receives and executes a batch of function calls on this contract.
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
        bytes memory context = msg.sender == _msgSender()
            ? new bytes(0)
            : msg.data[msg.data.length - _contextSuffixLength():];

        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), bytes.concat(data[i], context));
        }
        return results;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    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
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // 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 v5.0.0) (access/extensions/AccessControlDefaultAdminRules.sol)

pragma solidity ^0.8.20;

import {IAccessControlDefaultAdminRules} from "./IAccessControlDefaultAdminRules.sol";
import {AccessControl, IAccessControl} from "../AccessControl.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Math} from "../../utils/math/Math.sol";
import {IERC5313} from "../../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
 *    ) {}
 * }
 * ```
 */
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) {
        if (initialDefaultAdmin == address(0)) {
            revert AccessControlInvalidDefaultAdmin(address(0));
        }
        _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) {
        if (role == DEFAULT_ADMIN_ROLE) {
            revert AccessControlEnforcedDefaultAdminRules();
        }
        super.grantRole(role, account);
    }

    /**
     * @dev See {AccessControl-revokeRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function revokeRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
        if (role == DEFAULT_ADMIN_ROLE) {
            revert AccessControlEnforcedDefaultAdminRules();
        }
        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();
            if (newDefaultAdmin != address(0) || !_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
                revert AccessControlEnforcedDefaultAdminDelay(schedule);
            }
            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 returns (bool) {
        if (role == DEFAULT_ADMIN_ROLE) {
            if (defaultAdmin() != address(0)) {
                revert AccessControlEnforcedDefaultAdminRules();
            }
            _currentDefaultAdmin = account;
        }
        return super._grantRole(role, account);
    }

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

    /**
     * @dev See {AccessControl-_setRoleAdmin}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual override {
        if (role == DEFAULT_ADMIN_ROLE) {
            revert AccessControlEnforcedDefaultAdminRules();
        }
        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();
        if (_msgSender() != newDefaultAdmin) {
            // Enforce newDefaultAdmin explicit acceptance.
            revert AccessControlInvalidDefaultAdmin(_msgSender());
        }
        _acceptDefaultAdminTransfer();
    }

    /**
     * @dev See {acceptDefaultAdminTransfer}.
     *
     * Internal function without access restriction.
     */
    function _acceptDefaultAdminTransfer() internal virtual {
        (address newAdmin, uint48 schedule) = pendingDefaultAdmin();
        if (!_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
            revert AccessControlEnforcedDefaultAdminDelay(schedule);
        }
        _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;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC4626.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";

/**
 * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

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

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
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 v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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 An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, 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);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

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

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

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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(token).code.length > 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) 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 FailedInnerCall();
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlDefaultAdminRules.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "../IAccessControl.sol";

/**
 * @dev External interface of AccessControlDefaultAdminRules declared to support ERC165 detection.
 */
interface IAccessControlDefaultAdminRules is IAccessControl {
    /**
     * @dev The new default admin is not a valid default admin.
     */
    error AccessControlInvalidDefaultAdmin(address defaultAdmin);

    /**
     * @dev At least one of the following rules was violated:
     *
     * - The `DEFAULT_ADMIN_ROLE` must only be managed by itself.
     * - The `DEFAULT_ADMIN_ROLE` must only be held by one account at the time.
     * - Any `DEFAULT_ADMIN_ROLE` transfer must be in two delayed steps.
     */
    error AccessControlEnforcedDefaultAdminRules();

    /**
     * @dev The delay for transferring the default admin delay is enforced and
     * the operation must wait until `schedule`.
     *
     * NOTE: `schedule` can be 0 indicating there's no transfer scheduled.
     */
    error AccessControlEnforcedDefaultAdminDelay(uint48 schedule);

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

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

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../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 account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    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 returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @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 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 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 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 `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @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 Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}

File 21 of 26 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @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.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @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
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        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
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        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
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        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
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        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
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        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
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        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
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        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
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        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
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        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
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        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
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        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
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        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
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        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
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        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
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        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
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        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
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        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
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        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
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        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
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        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
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        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
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        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
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        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
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        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
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        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
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        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
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        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
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        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
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        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
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        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
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        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
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }
}

File 22 of 26 : IERC5313.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5313.sol)

pragma solidity ^0.8.20;

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @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.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
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].
     *
     * CAUTION: See Security Considerations above.
     */
    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 v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @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.
     */
    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 `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./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);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

Settings
{
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@balancer-labs/v2-interfaces/=lib/balancer-v2-monorepo/pkg/interfaces/",
    "@balancer-labs/v2-pool-stable/=lib/balancer-v2-monorepo/pkg/pool-stable/",
    "@chainlink/contracts/=lib/chainlink/contracts/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "balancer-v2-monorepo/=lib/balancer-v2-monorepo/",
    "chainlink/=lib/chainlink/",
    "ds-test/=lib/forge-safe/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-safe/=lib/forge-safe/src/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solady/=lib/solady/",
    "solidity-stringutils/=lib/forge-safe/lib/surl/lib/solidity-stringutils/",
    "solmate/=lib/forge-safe/lib/solmate/src/",
    "surl/=lib/forge-safe/lib/surl/",
    "v3-core/=lib/v3-core/",
    "v3-periphery/=lib/v3-periphery/contracts/",
    "solarray/=lib/solarray/src/",
    "pendle-core-v2-public/=lib/pendle-core-v2-public/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "shanghai",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IERC20","name":"_baseAsset","type":"address"},{"internalType":"address","name":"_feeRecipient","type":"address"},{"internalType":"uint256","name":"_feePercentage","type":"uint256"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint48","name":"initialDelay","type":"uint48"},{"internalType":"address","name":"initialDefaultAdmin","type":"address"},{"components":[{"internalType":"contract IIonPool[]","name":"marketsToAdd","type":"address[]"},{"internalType":"uint256[]","name":"allocationCaps","type":"uint256[]"},{"internalType":"contract IIonPool[]","name":"newSupplyQueue","type":"address[]"},{"internalType":"contract IIonPool[]","name":"newWithdrawQueue","type":"address[]"}],"internalType":"struct Vault.MarketsArgs","name":"marketsArgs","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"uint48","name":"schedule","type":"uint48"}],"name":"AccessControlEnforcedDefaultAdminDelay","type":"error"},{"inputs":[],"name":"AccessControlEnforcedDefaultAdminRules","type":"error"},{"inputs":[{"internalType":"address","name":"defaultAdmin","type":"address"}],"name":"AccessControlInvalidDefaultAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"AllSupplyCapsReached","type":"error"},{"inputs":[{"internalType":"uint256","name":"resultingSupplied","type":"uint256"},{"internalType":"uint256","name":"allocationCap","type":"uint256"}],"name":"AllocationCapExceeded","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxDeposit","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxMint","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxRedeem","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxWithdraw","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidFeePercentage","type":"error"},{"inputs":[],"name":"InvalidFeeRecipient","type":"error"},{"inputs":[],"name":"InvalidIdleMarketRemovalNonZeroBalance","type":"error"},{"inputs":[{"internalType":"contract IIonPool","name":"pool","type":"address"}],"name":"InvalidIonPoolDecimals","type":"error"},{"inputs":[{"internalType":"contract IIonPool","name":"pool","type":"address"}],"name":"InvalidMarketRemovalNonZeroSupply","type":"error"},{"inputs":[],"name":"InvalidQueueContainsDuplicates","type":"error"},{"inputs":[{"internalType":"uint256","name":"queueLength","type":"uint256"},{"internalType":"uint256","name":"supportedMarketsLength","type":"uint256"}],"name":"InvalidQueueLength","type":"error"},{"inputs":[{"internalType":"uint256","name":"totalSupplied","type":"uint256"},{"internalType":"uint256","name":"totalWithdrawn","type":"uint256"}],"name":"InvalidReallocation","type":"error"},{"inputs":[{"internalType":"contract IIonPool","name":"pool","type":"address"}],"name":"InvalidUnderlyingAsset","type":"error"},{"inputs":[],"name":"IonPoolsArrayAndNewCapsArrayMustBeOfEqualLength","type":"error"},{"inputs":[{"internalType":"contract IIonPool","name":"pool","type":"address"}],"name":"MarketAlreadySupported","type":"error"},{"inputs":[{"internalType":"contract IIonPool","name":"pool","type":"address"}],"name":"MarketNotSupported","type":"error"},{"inputs":[],"name":"MarketsAndAllocationCapLengthMustBeEqual","type":"error"},{"inputs":[],"name":"MathOverflowedMulDiv","type":"error"},{"inputs":[],"name":"MaxSupportedMarketsReached","type":"error"},{"inputs":[],"name":"NotEnoughLiquidityToWithdraw","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IIonPool[]","name":"marketsAdded","type":"address[]"}],"name":"AddSupportedMarkets","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","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":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feeShares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTotalAssets","type":"uint256"}],"name":"FeeAccrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IIonPool","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"ReallocateSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IIonPool","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"ReallocateWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IIonPool[]","name":"marketsRemoved","type":"address[]"}],"name":"RemoveSupportedMarkets","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":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IIonPool[]","name":"ionPools","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"newCaps","type":"uint256[]"}],"name":"UpdateAllocationCaps","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newFeePercentage","type":"uint256"}],"name":"UpdateFeePercentage","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"UpdateFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"lastTotalAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLastTotalAssets","type":"uint256"}],"name":"UpdateLastTotalAssets","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"contract IIonPool[]","name":"newSupplyQueue","type":"address[]"}],"name":"UpdateSupplyQueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"contract IIonPool[]","name":"newWithdrawQueue","type":"address[]"}],"name":"UpdateWithdrawQueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"ALLOCATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BASE_ASSET","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DECIMALS_OFFSET","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IDLE","outputs":[{"internalType":"contract IIonPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ION_POOL_LIQUIDITY_SLOT","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ION_POOL_SUPPLY_CAP_SLOT","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_SUPPORTED_MARKETS","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OWNER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"accrueFee","outputs":[{"internalType":"uint256","name":"newTotalAssets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IIonPool[]","name":"marketsToAdd","type":"address[]"},{"internalType":"uint256[]","name":"allocationCaps","type":"uint256[]"},{"internalType":"contract IIonPool[]","name":"newSupplyQueue","type":"address[]"},{"internalType":"contract IIonPool[]","name":"newWithdrawQueue","type":"address[]"}],"name":"addSupportedMarkets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"beginDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IIonPool","name":"","type":"address"}],"name":"caps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"}],"name":"changeDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"containsSupportedMarket","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","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":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"getSupportedMarkets","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":"lastTotalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IIonPool","name":"pool","type":"address"},{"internalType":"int256","name":"assets","type":"int256"}],"internalType":"struct Vault.MarketAllocation[]","name":"allocations","type":"tuple[]"}],"name":"reallocate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IIonPool[]","name":"marketsToRemove","type":"address[]"},{"internalType":"contract IIonPool[]","name":"newSupplyQueue","type":"address[]"},{"internalType":"contract IIonPool[]","name":"newWithdrawQueue","type":"address[]"}],"name":"removeSupportedMarkets","outputs":[],"stateMutability":"nonpayable","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":"uint256","name":"","type":"uint256"}],"name":"supplyQueue","outputs":[{"internalType":"contract IIonPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"supportedMarketsAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"supportedMarketsIndexOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"supportedMarketsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IIonPool[]","name":"ionPools","type":"address[]"},{"internalType":"uint256[]","name":"newCaps","type":"uint256[]"}],"name":"updateAllocationCaps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feePercentage","type":"uint256"}],"name":"updateFeePercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeRecipient","type":"address"}],"name":"updateFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IIonPool[]","name":"newSupplyQueue","type":"address[]"}],"name":"updateSupplyQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IIonPool[]","name":"newWithdrawQueue","type":"address[]"}],"name":"updateWithdrawQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"withdrawQueue","outputs":[{"internalType":"contract IIonPool","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

61010060405234801562000011575f80fd5b5060405162005c6f38038062005c6f833981016040819052620000349162000dd8565b8282898787600362000047838262000f43565b50600462000056828262000f43565b5050505f806200006c836200021160201b60201c565b91509150816200007e57601262000080565b805b60ff1660a05250506001600160a01b039081166080528116620000c3575f604051636116401160e11b8152600401620000ba91906200100b565b60405180910390fd5b600680546001600160d01b0316600160d01b65ffffffffffff851602179055620000ee5f82620002f0565b50506001600855506001600160a01b03881660e0526b033b2e3c9fd0803ce8000000861115620001315760405163390edff560e11b815260040160405180910390fd5b6001600160a01b0387166200015957604051630ed1b8b360e31b815260040160405180910390fd5b600e869055600d80546001600160a01b0319166001600160a01b038916179055600460c05280516020820151604083015160608401516200019d9392919062000364565b6040518681527ff5c230c0f5a5bb324c05594113d2e5fe9977833d5b555d47b056acf21049501d9060200160405180910390a16040516001600160a01b038816907f6632de8ab33c46549f7bb29f647ea0d751157b25fe6a14b1bcc7527cdfbeb79c905f90a2505050505050505062001140565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f918291829182916001600160a01b0387169162000259916200101f565b5f60405180830381855afa9150503d805f811462000293576040519150601f19603f3d011682016040523d82523d5f602084013e62000298565b606091505b5091509150818015620002ad57506020815110155b15620002e4575f81806020019051810190620002ca91906200103c565b905060ff8111620002e2576001969095509350505050565b505b505f9485945092505050565b5f826200034f575f6200030b6007546001600160a01b031690565b6001600160a01b0316146200033357604051631fe1e13d60e11b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0384161790555b6200035b8383620006f3565b90505b92915050565b8251845114620003875760405163db78979f60e01b815260040160405180910390fd5b5f845190505f60e0516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015620003cc573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620003f2919062001054565b90505f5b8281146200066d575f8782815181106200041457620004146200107d565b602002602001015190507f2c625cc13e052290a6cbb35e9b1d53b1b3f4341f63626c17606a025fe7b17b1a5f1c6001600160a01b0316816001600160a01b031614620005fb578260ff16816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200049b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620004c1919062001054565b60ff1614620004e75780604051632a9d2b9360e21b8152600401620000ba91906200100b565b60e0516001600160a01b0316816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000530573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000556919062001091565b6001600160a01b031614620005825780604051631717aff760e11b8152600401620000ba91906200100b565b60e05160405163095ea7b360e01b81526001600160a01b0383811660048301525f1960248301529091169063095ea7b3906044016020604051808303815f875af1158015620005d3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620005f99190620010af565b505b62000608600982620007a2565b6200062a57806040516303bbdb0560e61b8152600401620000ba91906200100b565b8682815181106200063f576200063f6200107d565b6020908102919091018101516001600160a01b039092165f90815260109091526040902055600101620003f6565b5060206200067c6009620007b8565b11156200069c5760405163abc6e9c960e01b815260040160405180910390fd5b620006a784620007c2565b620006b28362000829565b7ff893e2645bae0bc2d2ab1ce62fb949ede3945df8cfd07ce22d9a421c9943da6386604051620006e39190620010d0565b60405180910390a1505050505050565b5f8281526005602090815260408083206001600160a01b038516845290915281205460ff166200079a575f8381526005602090815260408083206001600160a01b03861684529091529020805460ff19166001179055620007513390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016200035e565b505f6200035e565b5f6200035b836001600160a01b03841662000885565b5f6200035e825490565b620007cd81620008cc565b8051620007e290600b90602084019062000a5a565b50336001600160a01b03167f823a01301c8a565de5c9d7aa034ab0841b6bfb2c3a497218fa6226b9c65d3550826040516200081e9190620010d0565b60405180910390a250565b6200083481620008cc565b80516200084990600c90602084019062000a5a565b50336001600160a01b03167fc618a15cb59b7ae9a202a339c6d0b97c4752b6e1a27e06f7b7e7b1d062f6688f826040516200081e9190620010d0565b5f8181526001830160205260408120546200079a57508154600181810184555f8481526020808220909301849055845484825282860190935260409020919091556200035e565b5f620008d96009620007b8565b82519091508082146200090a576040516319376e2160e01b81526004810182905260248101839052604401620000ba565b5f816001600160401b0381111562000926576200092662000b02565b60405190808252806020026020018201604052801562000950578160200160208202803683370190505b5090505f5b82811462000a00575f6200098b8683815181106200097757620009776200107d565b602002602001015162000a0760201b60201c565b9050828181518110620009a257620009a26200107d565b602002602001015115156001151503620009cf5760405163233b822f60e11b815260040160405180910390fd5b6001838281518110620009e657620009e66200107d565b911515602092830291909101909101525060010162000955565b5050505050565b6001600160a01b0381165f818152600a602052604081205490919080830362000a475783604051633c94b11560e01b8152600401620000ba91906200100b565b62000a52816200111e565b949350505050565b828054828255905f5260205f2090810192821562000ab0579160200282015b8281111562000ab057825182546001600160a01b0319166001600160a01b0390911617825560209092019160019091019062000a79565b5062000abe92915062000ac2565b5090565b5b8082111562000abe575f815560010162000ac3565b6001600160a01b038116811462000aed575f80fd5b50565b805162000afd8162000ad8565b919050565b634e487b7160e01b5f52604160045260245ffd5b604051608081016001600160401b038111828210171562000b3b5762000b3b62000b02565b60405290565b604051601f8201601f191681016001600160401b038111828210171562000b6c5762000b6c62000b02565b604052919050565b5f5b8381101562000b9057818101518382015260200162000b76565b50505f910152565b5f82601f83011262000ba8575f80fd5b81516001600160401b0381111562000bc45762000bc462000b02565b62000bd9601f8201601f191660200162000b41565b81815284602083860101111562000bee575f80fd5b62000a5282602083016020870162000b74565b805165ffffffffffff8116811462000afd575f80fd5b5f6001600160401b0382111562000c325762000c3262000b02565b5060051b60200190565b5f82601f83011262000c4c575f80fd5b8151602062000c6562000c5f8362000c17565b62000b41565b82815260059290921b8401810191818101908684111562000c84575f80fd5b8286015b8481101562000cac57805162000c9e8162000ad8565b835291830191830162000c88565b509695505050505050565b5f82601f83011262000cc7575f80fd5b8151602062000cda62000c5f8362000c17565b82815260059290921b8401810191818101908684111562000cf9575f80fd5b8286015b8481101562000cac578051835291830191830162000cfd565b5f6080828403121562000d27575f80fd5b62000d3162000b16565b82519091506001600160401b038082111562000d4b575f80fd5b62000d598583860162000c3c565b8352602084015191508082111562000d6f575f80fd5b62000d7d8583860162000cb7565b6020840152604084015191508082111562000d96575f80fd5b62000da48583860162000c3c565b6040840152606084015191508082111562000dbd575f80fd5b5062000dcc8482850162000c3c565b60608301525092915050565b5f805f805f805f80610100898b03121562000df1575f80fd5b62000dfc8962000af0565b975062000e0c60208a0162000af0565b60408a015160608b015191985096506001600160401b038082111562000e30575f80fd5b62000e3e8c838d0162000b98565b965060808b015191508082111562000e54575f80fd5b62000e628c838d0162000b98565b955062000e7260a08c0162000c01565b945062000e8260c08c0162000af0565b935060e08b015191508082111562000e98575f80fd5b5062000ea78b828c0162000d16565b9150509295985092959890939650565b600181811c9082168062000ecc57607f821691505b60208210810362000eeb57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111562000f3e575f81815260208120601f850160051c8101602086101562000f195750805b601f850160051c820191505b8181101562000f3a5782815560010162000f25565b5050505b505050565b81516001600160401b0381111562000f5f5762000f5f62000b02565b62000f778162000f70845462000eb7565b8462000ef1565b602080601f83116001811462000fad575f841562000f955750858301515b5f19600386901b1c1916600185901b17855562000f3a565b5f85815260208120601f198616915b8281101562000fdd5788860151825594840194600190910190840162000fbc565b508582101562000ffb57878501515f19600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160a01b0391909116815260200190565b5f82516200103281846020870162000b74565b9190910192915050565b5f602082840312156200104d575f80fd5b5051919050565b5f6020828403121562001065575f80fd5b815160ff8116811462001076575f80fd5b9392505050565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215620010a2575f80fd5b8151620010768162000ad8565b5f60208284031215620010c0575f80fd5b8151801515811462001076575f80fd5b602080825282518282018190525f9190848201906040850190845b81811015620011125783516001600160a01b031683529284019291840191600101620010eb565b50909695505050505050565b5f816200113957634e487b7160e01b5f52601160045260245ffd5b505f190190565b60805160a05160c05160e051614a99620011d65f395f818161071e0152818161096701528181610f45015281816114600152818161159901528181611d3101528181611e8801528181611f50015281816121bc0152818161308001528181613489015261376701525f81816106b601526127d101525f6120cb01525f818161049f0152818161300601526136730152614a995ff3fe608060405234801561000f575f80fd5b5060043610610336575f3560e01c806301e1d1141461033a57806301ffc9a714610355578063022d63fb1461037857806306fdde031461038a57806307a2d13a1461039f578063095ea7b3146103b25780630a28a477146103c55780630aa6220b146103d857806313983f27146103e257806318160ddd146103f557806323b872dd146103fd578063248a9ca31461041057806325dd173a1461042357806325f3c822146104365780632cac95ef146104495780632f2ff15d1461045d578063313ce5671461047057806336568abe1461048a57806338d52e0f1461049d578063402d267d146104cc57806346904840146104df5780634cdad506146104f25780635478786c14610505578063568efc0714610519578063593f58de146105225780635cb3bcfd1461053557806362518ddf14610548578063634e93da1461055b578063649a5ec71461056e57806364aa5ea91461058157806366d97b21146105895780636cad3fb0146105a85780636e553f65146105bb57806370a08231146105ce57806384ef8ffc146105e1578063854f4d80146105e95780638da5cb5b146105fc5780638ef977141461060457806391d148541461061757806394bf804d1461062a57806395d89b411461063d578063a001ecdd14610645578063a1872ee61461064e578063a1eda53c14610661578063a217fddf14610677578063a9059cbb1461067e578063ac9650d814610691578063aea70acc146106b1578063b26cc394146106d8578063b3d7f6b9146106e0578063b460af94146106f3578063ba08765214610706578063c55ed10e14610719578063c63d75b614610740578063c6e6f59214610753578063c81cbaa114610766578063cc8463c81461077a578063ce96cb7714610782578063cefc142914610795578063cf6eefb71461079d578063d547741f146107cb578063d602b9fd146107de578063d905777e146107e6578063dd62ed3e146107f9578063e58378bb1461080c578063e6cd317d14610820578063ebfc48e914610833578063ee6a47f814610847578063ef8b30f71461084f578063f160d36914610862578063f7d1852114610875578063f947629014610888575b5f80fd5b61034261089d565b6040519081526020015b60405180910390f35b610368610363366004613e25565b6109fb565b604051901515815260200161034c565b620697805b60405161034c9190613e4c565b610392610a25565b60405161034c9190613eac565b6103426103ad366004613ebe565b610ab5565b6103686103c0366004613ee9565b610ac0565b6103426103d3366004613ebe565b610ad7565b6103e0610ae3565b005b6103686103f0366004613f13565b610af8565b600254610342565b61036861040b366004613f2e565b610b04565b61034261041e366004613ebe565b610b29565b6103e0610431366004613fb3565b610b3d565b6103e06104443660046140f0565b610c61565b6103425f80516020614a4483398151915281565b6103e061046b3660046141e7565b610c8b565b610478610cb7565b60405160ff909116815260200161034c565b6103e06104983660046141e7565b610cc5565b7f00000000000000000000000000000000000000000000000000000000000000005b60405161034c9190614215565b6103426104da366004613f13565b610d6c565b600d546104bf906001600160a01b031681565b610342610500366004613ebe565b610d75565b6104bf5f805160206149a483398151915281565b610342600f5481565b6104bf610530366004613ebe565b610d80565b6103e0610543366004614229565b610d8c565b6104bf610556366004613ebe565b610dac565b6103e0610569366004613f13565b610dd4565b6103e061057c36600461425a565b610de7565b610342610dfa565b610342610597366004613f13565b60106020525f908152604090205481565b6103e06105b6366004613ebe565b610e05565b6103426105c93660046141e7565b610e8e565b6103426105dc366004613f13565b610ecf565b6104bf610ee9565b6103e06105f7366004614229565b610ef8565b6104bf610f18565b6103e061061236600461427f565b610f21565b6103686106253660046141e7565b611369565b6103426106383660046141e7565b611393565b6103926113ca565b610342600e5481565b6103e061065c3660046142ed565b6113d9565b610669611715565b60405161034c92919061437f565b6103425f81565b61036861068c366004613ee9565b61176b565b6106a461069f366004614398565b611778565b60405161034c91906143d6565b6104787f000000000000000000000000000000000000000000000000000000000000000081565b610342611868565b6103426106ee366004613ebe565b61188f565b610342610701366004614436565b61189b565b610342610714366004614436565b6118f2565b6104bf7f000000000000000000000000000000000000000000000000000000000000000081565b61034261074e366004613f13565b611936565b610342610761366004613ebe565b61194c565b6103425f805160206149e483398151915281565b61037d611957565b610342610790366004613f13565b6119b6565b6103e06119c9565b6107a5611a08565b604080516001600160a01b03909316835265ffffffffffff90911660208301520161034c565b6103e06107d93660046141e7565b611a29565b6103e0611a51565b6103426107f4366004613f13565b611a63565b610342610807366004614475565b611a8b565b6103425f805160206149c483398151915281565b61034261082e366004613f13565b611ab5565b6103425f80516020614a2483398151915281565b610478602081565b61034261085d366004613ebe565b611abf565b6103e0610870366004613f13565b611aca565b6104bf610883366004613ebe565b611b52565b610890611b61565b60405161034c91906144a1565b5f806108a96009611b6d565b90505f5b8181146109f6575f6108c0600983611b76565b90505f6001600160a01b0382165f80516020614a0483398151915214610950576040516370a0823160e01b81526001600160a01b038316906370a082319061090c903090600401614215565b602060405180830381865afa158015610927573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061094b91906144ed565b6109db565b6040516370a0823160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319061099c903090600401614215565b602060405180830381865afa1580156109b7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109db91906144ed565b90506109e78186614518565b945082600101925050506108ad565b505090565b5f6001600160e01b031982166318a4c3c360e11b1480610a1f5750610a1f82611b81565b92915050565b606060038054610a349061452b565b80601f0160208091040260200160405190810160405280929190818152602001828054610a609061452b565b8015610aab5780601f10610a8257610100808354040283529160200191610aab565b820191905f5260205f20905b815481529060010190602001808311610a8e57829003601f168201915b5050505050905090565b5f610a1f825f611bb5565b5f33610acd818585611bf5565b5060019392505050565b5f610a1f826001611c02565b5f610aed81611c30565b610af5611c3a565b50565b5f610a1f600983611c46565b5f33610b11858285611c5a565b610b1c858585611caa565b60019150505b9392505050565b5f9081526005602052604090206001015490565b5f805160206149c4833981519152610b5481611c30565b83828114610b7557604051638078aee560e01b815260040160405180910390fd5b5f5b818114610c1b575f878783818110610b9157610b91614563565b9050602002016020810190610ba69190613f13565b9050610bb3600982611c46565b610bdb5780604051633c94b11560e01b8152600401610bd29190614215565b60405180910390fd5b858583818110610bed57610bed614563565b6001600160a01b039093165f9081526010602090815260409091209302919091013590915550600101610b77565b507f074514c11ea4ae3662be1e996c6b9c077250a155a17f430475f9721403472bba86868686604051610c5194939291906145be565b60405180910390a1505050505050565b5f805160206149c4833981519152610c7881611c30565b610c8485858585611d07565b5050505050565b81610ca957604051631fe1e13d60e11b815260040160405180910390fd5b610cb382826120a0565b5050565b5f610cc06120bc565b905090565b81158015610ceb5750610cd6610ee9565b6001600160a01b0316816001600160a01b0316145b15610d62575f80610cfa611a08565b90925090506001600160a01b038216151580610d1c5750610d1a816120ef565b155b80610d2d5750610d2b816120fc565b155b15610d4d57806040516319ca5ebb60e01b8152600401610bd29190613e4c565b50506006805465ffffffffffff60a01b191690555b610cb3828261210b565b5f610a1f61213e565b5f610a1f825f612254565b5f610a1f600983611b76565b5f805160206149e4833981519152610da381611c30565b610cb382612282565b600c8181548110610dbb575f80fd5b5f918252602090912001546001600160a01b0316905081565b5f610dde81611c30565b610cb3826122e3565b5f610df181611c30565b610cb382612350565b5f610cc06009611b6d565b5f805160206149c4833981519152610e1c81611c30565b676765c793fa10079d601b1b821115610e485760405163390edff560e11b815260040160405180910390fd5b610e506123aa565b50600e8290556040518281527ff5c230c0f5a5bb324c05594113d2e5fe9977833d5b555d47b056acf21049501d906020015b60405180910390a15050565b5f610e9761241a565b5f610ea06123aa565b9050610eb684610eaf60025490565b835f612444565b9150610ec433848685612479565b50610a1f6001600855565b6001600160a01b03165f9081526020819052604090205490565b6007546001600160a01b031690565b5f805160206149e4833981519152610f0f81611c30565b610cb38261249f565b5f610cc0610ee9565b5f805160206149e4833981519152610f3881611c30565b610f4061241a565b5f805f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610f8f9190614215565b602060405180830381865afa158015610faa573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fce91906144ed565b9050845f5b8181146113315736888883818110610fed57610fed614563565b6040029190910191505f90506110066020830183613f13565b9050611011816124f5565b505f6001600160a01b0382165f80516020614a04833981519152146110a0576040516370a0823160e01b81526001600160a01b038316906370a082319061105c903090600401614215565b602060405180830381865afa158015611077573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061109b91906144ed565b6110a2565b855b905060208301355f808212156111ae57600160ff1b82036110c45750816110d0565b6110cd82614608565b90505b6001600160a01b0384165f80516020614a048339815191521461114d5760405163f3fef3a360e01b81526001600160a01b0385169063f3fef3a39061111b9030908590600401614622565b5f604051808303815f87803b158015611132575f80fd5b505af1158015611144573d5f803e3d5ffd5b5050505061115a565b611157818961463b565b97505b611164818a614518565b9850836001600160a01b03167fa2c440e4b34ac79fe297e62c2b414893528a4bb036f157263a3f41066a2a895f826040516111a191815260200190565b60405180910390a2611321565b5f821315611321576001600160ff1b0382036111cb5750876111ce565b50805b5f6111d98285614518565b6001600160a01b0386165f908152601060205260409020549091508082111561121957818160405163ed4e62f360e01b8152600401610bd292919061464e565b6001600160a01b0386165f80516020614a04833981519152146112c2576001600160a01b038616637ca5643d30855f604051908082528060200260200182016040528015611271578160200160208202803683370190505b506040518463ffffffff1660e01b81526004016112909392919061465c565b5f604051808303815f87803b1580156112a7575f80fd5b505af11580156112b9573d5f803e3d5ffd5b505050506112cf565b6112cc838b614518565b99505b6112d9838d614518565b9b50856001600160a01b03167fa4625590959c192f7dca76cee1966d35131f8eb159f85a513b4b0d6093a7b0548460405161131691815260200190565b60405180910390a250505b8560010195505050505050610fd3565b508284146113565783836040516318e7456560e21b8152600401610bd292919061464e565b505050506113646001600855565b505050565b5f9182526005602090815260408084206001600160a01b0393909316845291905290205460ff1690565b5f61139c61241a565b5f6113a56123aa565b90506113bc846113b460025490565b836001612543565b9150610ec433848487612479565b606060048054610a349061452b565b5f805160206149c48339815191526113f081611c30565b855f5b81811461165b575f89898381811061140d5761140d614563565b90506020020160208101906114229190613f13565b9050739b1d53b1b3f4341f63626c17606a025fe7b17b19196001600160a01b038216016114f7576040516370a0823160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190611495903090600401614215565b602060405180830381865afa1580156114b0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d491906144ed565b156114f257604051631ea9a9e360e31b815260040160405180910390fd5b611612565b60405163023da9f960e01b81526001600160a01b0382169063023da9f990611523903090600401614215565b602060405180830381865afa15801561153e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061156291906144ed565b1561158257806040516325dce25160e21b8152600401610bd29190614215565b60405163095ea7b360e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063095ea7b3906115d09084905f90600401614622565b6020604051808303815f875af11580156115ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061161091906146b8565b505b61161d60098261256f565b61163c5780604051633c94b11560e01b8152600401610bd29190614215565b6001600160a01b03165f908152601060205260408120556001016113f3565b506116978686808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061228292505050565b6116d28484808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061249f92505050565b7fdb8fabacb902a02141e8855f3dfecd70fdb0b1d389bd24cb976b7de67259470488886040516117039291906146d7565b60405180910390a15050505050505050565b6007545f90600160d01b900465ffffffffffff16611732816120ef565b80156117445750611742816120fc565b155b61174f575f80611763565b600754600160a01b900465ffffffffffff16815b915091509091565b5f33610acd818585611caa565b604080515f815260208101909152606090826001600160401b038111156117a1576117a1614019565b6040519080825280602002602001820160405280156117d457816020015b60608152602001906001900390816117bf5790505b5091505f5b8381101561186057611830308686848181106117f7576117f7614563565b905060200281019061180991906146ea565b8560405160200161181c9392919061472c565b604051602081830303815290604052612583565b83828151811061184257611842614563565b6020026020010181905250808061185890614751565b9150506117d9565b505092915050565b5f5f805160206149c483398151915261188081611c30565b6118886123aa565b91505b5090565b5f610a1f826001612254565b5f6118a461241a565b5f6118ad6123aa565b90506118c4856118bc60025490565b836001612444565b91506118da858203868311026125ec565b6125ec565b6118e7338585888661262e565b50610b226001600855565b5f6118fb61241a565b5f6119046123aa565b905061191a8561191360025490565b835f612543565b91506119296118d5838361463b565b6118e7338585858961262e565b5f8061194061213e565b9050610b22815f611c02565b5f610a1f825f612644565b6007545f90600160d01b900465ffffffffffff16611974816120ef565b80156119845750611984816120fc565b61199f57600654600160d01b900465ffffffffffff16611888565b5050600754600160a01b900465ffffffffffff1690565b5f6119c08261267b565b50909392505050565b5f6119d2611a08565b509050336001600160a01b03821614611a005733604051636116401160e11b8152600401610bd29190614215565b610af56126fd565b6006546001600160a01b03811691600160a01b90910465ffffffffffff1690565b81611a4757604051631fe1e13d60e11b815260040160405180910390fd5b610cb38282612777565b5f611a5b81611c30565b610af5612793565b5f805f80611a708561267b565b925092509250611a828383835f612444565b95945050505050565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b5f610a1f826124f5565b5f610a1f825f611c02565b5f805160206149c4833981519152611ae181611c30565b6001600160a01b038216611b0857604051630ed1b8b360e31b815260040160405180910390fd5b600d80546001600160a01b0319166001600160a01b0384169081179091556040517f6632de8ab33c46549f7bb29f647ea0d751157b25fe6a14b1bcc7527cdfbeb79c905f90a25050565b600b8181548110610dbb575f80fd5b6060610cc0600961279d565b5f610a1f825490565b5f610b2283836127a9565b5f6001600160e01b03198216637965db0b60e01b1480610a1f57506301ffc9a760e01b6001600160e01b0319831614610a1f565b5f610b22611bc161089d565b611bcc906001614518565b611bd46127cf565b611bdf90600a614849565b600254611bec9190614518565b859190856127f3565b6113648383836001612840565b5f805f611c0d612912565b91509150611a828583611c1f60025490565b611c299190614518565b8387612444565b610af5813361298a565b611c445f806129b5565b565b5f610b22836001600160a01b038416612a7a565b5f611c658484611a8b565b90505f198114611ca45781811015611c9657828183604051637dc7a0d960e11b8152600401610bd293929190614857565b611ca484848484035f612840565b50505050565b6001600160a01b038316611cd3575f604051634b637e8f60e11b8152600401610bd29190614215565b6001600160a01b038216611cfc575f60405163ec442f0560e01b8152600401610bd29190614215565b611364838383612a91565b8251845114611d295760405163db78979f60e01b815260040160405180910390fd5b5f845190505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d8b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611daf9190614878565b90505f5b828114612033575f878281518110611dcd57611dcd614563565b602002602001015190505f805160206149a48339815191525f1c6001600160a01b0316816001600160a01b031614611fca578260ff16816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e3f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e639190614878565b60ff1614611e865780604051632a9d2b9360e21b8152600401610bd29190614215565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eec573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f109190614898565b6001600160a01b031614611f395780604051631717aff760e11b8152600401610bd29190614215565b60405163095ea7b360e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063095ea7b390611f889084905f1990600401614622565b6020604051808303815f875af1158015611fa4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fc891906146b8565b505b611fd5600982612ba4565b611ff457806040516303bbdb0560e61b8152600401610bd29190614215565b86828151811061200657612006614563565b6020908102919091018101516001600160a01b039092165f90815260109091526040902055600101611db3565b5060206120406009611b6d565b111561205f5760405163abc6e9c960e01b815260040160405180910390fd5b61206884612282565b6120718361249f565b7ff893e2645bae0bc2d2ab1ce62fb949ede3945df8cfd07ce22d9a421c9943da6386604051610c5191906144a1565b6120a982610b29565b6120b281611c30565b611ca48383612bb8565b5f6120c56127cf565b610cc0907f00000000000000000000000000000000000000000000000000000000000000006148b3565b65ffffffffffff16151590565b4265ffffffffffff9091161090565b6001600160a01b03811633146121345760405163334bd91960e11b815260040160405180910390fd5b6113648282612c14565b5f8061214a6009611b6d565b90505f5b8181146109f6575f612161600983611b76565b90505f6001600160a01b0382165f80516020614a048339815191521461218f5761218a82612c5b565b612239565b6001600160a01b038083165f90815260106020526040908190205490516370a0823160e01b8152612239927f000000000000000000000000000000000000000000000000000000000000000016906370a08231906121f1903090600401614215565b602060405180830381865afa15801561220c573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061223091906144ed565b80821191030290565b90506122458186614518565b9450826001019250505061214e565b5f805f61225f612912565b91509150611a82858361227160025490565b61227b9190614518565b8387612543565b61228b81612dcd565b805161229e90600b906020840190613db7565b50336001600160a01b03167f823a01301c8a565de5c9d7aa034ab0841b6bfb2c3a497218fa6226b9c65d3550826040516122d891906144a1565b60405180910390a250565b5f6122ec611957565b6122f542612edf565b6122ff91906148cc565b905061230b8282612f11565b816001600160a01b03167f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed6826040516123449190613e4c565b60405180910390a25050565b5f61235a82612f86565b61236342612edf565b61236d91906148cc565b905061237982826129b5565b7ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b8282604051610e8292919061437f565b5f806123b4612912565b9250905080156123d457600d546123d4906001600160a01b031682612fcd565b6123dd826125ec565b7fb2195cd5fcca9daf7d719d0466344f2078e77914d0edb599d6d50985697af99d818360405161240e92919061464e565b60405180910390a15090565b60026008540361243d57604051633ee5aeb560e01b815260040160405180910390fd5b6002600855565b5f611a826124506127cf565b61245b90600a614849565b6124659086614518565b612470856001614518565b879190856127f3565b61248584848484613001565b61248e8261307c565b611ca482600f546118d59190614518565b6124a881612dcd565b80516124bb90600c906020840190613db7565b50336001600160a01b03167fc618a15cb59b7ae9a202a339c6d0b97c4752b6e1a27e06f7b7e7b1d062f6688f826040516122d891906144a1565b6001600160a01b0381165f818152600a60205260408120549091908083036125325783604051633c94b11560e01b8152600401610bd29190614215565b61253b816148eb565b949350505050565b5f611a82612552846001614518565b61255a6127cf565b61256590600a614849565b6124709087614518565b5f610b22836001600160a01b038416613338565b60605f80846001600160a01b03168460405161259f9190614900565b5f60405180830381855af49150503d805f81146125d7576040519150601f19603f3d011682016040523d82523d5f602084013e6125dc565b606091505b5091509150611a82858383613422565b600f8190556040517f348e3f4755df402c99d6e3ba0b948083686ad2a43908f164baf843ca5c9008b290612623908390819061464e565b60405180910390a150565b61263782613470565b610c848585858585613640565b5f610b226126506127cf565b61265b90600a614849565b6002546126689190614518565b61267061089d565b611bec906001614518565b5f805f80612687612912565b925090508061269560025490565b61269f9190614518565b92505f6126ab86610ecf565b600d549091506001600160a01b03908116908716036126d1576126ce8282614518565b90505b6126dd8185855f612543565b94506126e8856136f7565b6126f2908661463b565b945050509193909250565b5f80612707611a08565b91509150612714816120ef565b15806127265750612724816120fc565b155b1561274657806040516319ca5ebb60e01b8152600401610bd29190613e4c565b6127575f612752610ee9565b612c14565b506127625f83612bb8565b5050600680546001600160d01b031916905550565b61278082610b29565b61278981611c30565b611ca48383612c14565b611c445f80612f11565b60605f610b228361381b565b5f825f0182815481106127be576127be614563565b905f5260205f200154905092915050565b7f000000000000000000000000000000000000000000000000000000000000000090565b5f80612800868686613874565b905061280b83613933565b801561282657505f84806128215761282161491b565b868809115b15611a8257612836600182614518565b9695505050505050565b6001600160a01b038416612869575f60405163e602df0560e01b8152600401610bd29190614215565b6001600160a01b038316612892575f604051634a1406b160e11b8152600401610bd29190614215565b6001600160a01b038085165f9081526001602090815260408083209387168352929052208290558015611ca457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161290491815260200190565b60405180910390a350505050565b5f8061291c61089d565b90505f61292f82600f5480821191030290565b905080158015906129415750600e5415155b1561298557600e545f90612962908390676765c793fa10079d601b1b613874565b90506129818161297160025490565b61297b848761463b565b5f612444565b9350505b509091565b6129948282611369565b610cb357808260405163e2517d3f60e01b8152600401610bd2929190614622565b600754600160d01b900465ffffffffffff166129d0816120ef565b15612a3d576129de816120fc565b15612a1457600754600680546001600160d01b0316600160a01b90920465ffffffffffff16600160d01b02919091179055612a3d565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec5905f90a15b50600780546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b5f9081526001919091016020526040902054151590565b6001600160a01b038316612abb578060025f828254612ab09190614518565b90915550612b189050565b6001600160a01b0383165f9081526020819052604090205481811015612afa5783818360405163391434e360e21b8152600401610bd293929190614857565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b038216612b3457600280548290039055612b52565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051612b9791815260200190565b60405180910390a3505050565b5f610b22836001600160a01b03841661395f565b5f82612c0a575f612bc7610ee9565b6001600160a01b031614612bee57604051631fe1e13d60e11b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0384161790555b610b2283836139a6565b5f82158015612c3b5750612c26610ee9565b6001600160a01b0316826001600160a01b0316145b15612c5157600780546001600160a01b03191690555b610b228383613a30565b5f816001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c98573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612cbc91906146b8565b15612cc857505f919050565b6001600160a01b0382165f818152601060205260408082205490516370a0823160e01b81529192612d07926370a08231906121f1903090600401614215565b604051631e2eaeaf60e01b81525f80516020614a4483398151915260048201529091505f90612dc1906001600160a01b03861690631e2eaeaf90602401602060405180830381865afa158015612d5f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d8391906144ed565b5f1c856001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561220c573d5f803e3d5ffd5b905061253b8282613a9b565b5f612dd86009611b6d565b8251909150808214612e015780826040516319376e2160e01b8152600401610bd292919061464e565b5f816001600160401b03811115612e1a57612e1a614019565b604051908082528060200260200182016040528015612e43578160200160208202803683370190505b5090505f5b828114610c84575f612e72868381518110612e6557612e65614563565b60200260200101516124f5565b9050828181518110612e8657612e86614563565b602002602001015115156001151503612eb25760405163233b822f60e11b815260040160405180910390fd5b6001838281518110612ec657612ec6614563565b9115156020928302919091019091015250600101612e48565b5f65ffffffffffff82111561188b576040516306dfcc6560e41b81526030600482015260248101839052604401610bd2565b5f612f1a611a08565b6006805465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b038816171790559150612f549050816120ef565b15611364576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a9605109905f90a1505050565b5f80612f90611957565b90508065ffffffffffff168365ffffffffffff1611612fb857612fb3838261492f565b610b22565b610b2265ffffffffffff841662069780613a9b565b6001600160a01b038216612ff6575f60405163ec442f0560e01b8152600401610bd29190614215565b610cb35f8383612a91565b61302d7f0000000000000000000000000000000000000000000000000000000000000000853085613ab0565b6130378382612fcd565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7848460405161290492919061464e565b5f817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016130ca9190614215565b602060405180830381865afa1580156130e5573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061310991906144ed565b613113919061463b565b600b549091505f5b818114613318575f600b828154811061313657613136614563565b5f9182526020822001546001600160a01b031691505f80516020614a04833981519152821461316d5761316882612c5b565b61318d565b6001600160a01b0382165f90815260106020526040902054858103908610025b9050801561330e575f6131a08288613a9b565b90506001600160a01b0383165f80516020614a04833981519152146132ef575f613237676765c793fa10079d601b1b856001600160a01b031663070a96456040518163ffffffff1660e01b8152600401602060405180830381865afa15801561320b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061322f91906144ed565b849190613874565b90508782148015613246575080155b15613255575050505050505050565b6001600160a01b038416637ca5643d30845f604051908082528060200260200182016040528015613290578160200160208202803683370190505b506040518463ffffffff1660e01b81526004016132af9392919061465c565b5f604051808303815f87803b1580156132c6575f80fd5b505af19250505080156132d7575060015b156132e9576132e6828961463b565b97505b506132fc565b6132f9818861463b565b96505b865f0361330c5750505050505050565b505b505060010161311b565b5082156113645760405163b1513a2f60e01b815260040160405180910390fd5b5f8181526001830160205260408120548015613412575f61335a60018361463b565b85549091505f9061336d9060019061463b565b90508082146133cc575f865f01828154811061338b5761338b614563565b905f5260205f200154905080875f0184815481106133ab576133ab614563565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806133dd576133dd61494e565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610a1f565b5f915050610a1f565b5092915050565b60608261343257612fb382613b17565b815115801561344957506001600160a01b0384163b155b156134695783604051639996b31560e01b8152600401610bd29190614215565b5080610b22565b6040516370a0823160e01b81525f906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a08231906134be903090600401614215565b602060405180830381865afa1580156134d9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906134fd91906144ed565b600c549091505f5b818114613620575f600c828154811061352057613520614563565b5f9182526020822001546001600160a01b031691505f80516020614a0483398151915282146135575761355282613b40565b613559565b845b90508015613616575f61356c8288613a9b565b90506001600160a01b0383165f80516020614a04833981519152146135f75760405163f3fef3a360e01b81526001600160a01b0384169063f3fef3a3906135b99030908590600401614622565b5f604051808303815f87803b1580156135d0575f80fd5b505af19250505080156135e1575060015b15613604576135f0818861463b565b9650613604565b613601818861463b565b96505b865f036136145750505050505050565b505b5050600101613505565b508215611364576040516322d95ee960e01b815260040160405180910390fd5b826001600160a01b0316856001600160a01b03161461366457613664838683611c5a565b61366e8382613c92565b6136997f00000000000000000000000000000000000000000000000000000000000000008584613cc6565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db85856040516136e892919061464e565b60405180910390a45050505050565b600c545f90815b818114613813575f600c828154811061371957613719614563565b5f9182526020822001546001600160a01b031691505f80516020614a0483398151915282146137505761374b82613b40565b6137db565b6040516370a0823160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319061379c903090600401614215565b602060405180830381865afa1580156137b7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137db91906144ed565b90505f6137e88288613a9b565b90506137f4818861463b565b9650865f0361380557505050613813565b8360010193505050506136fe565b509192915050565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561386857602002820191905f5260205f20905b815481526020019060010190808311613854575b50505050509050919050565b5f838302815f1985870982811083820303915050805f036138a85783828161389e5761389e61491b565b0492505050610b22565b8084116138c85760405163227bc15360e01b815260040160405180910390fd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f600282600381111561394857613948614962565b6139529190614976565b60ff166001149050919050565b5f61396a8383612a7a565b61399f57508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610a1f565b505f610a1f565b5f6139b18383611369565b61399f575f8381526005602090815260408083206001600160a01b03861684529091529020805460ff191660011790556139e83390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001610a1f565b5f613a3b8383611369565b1561399f575f8381526005602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4506001610a1f565b5f818310613aa95781610b22565b5090919050565b6040516001600160a01b038481166024830152838116604483015260648201839052611ca49186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613cec565b805115613b275780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b5f816001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613b7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613ba191906146b8565b15613bad57505f919050565b6040516370a0823160e01b81525f906001600160a01b038416906370a0823190613bdb903090600401614215565b602060405180830381865afa158015613bf6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c1a91906144ed565b604051631e2eaeaf60e01b81525f80516020614a2483398151915260048201529091505f906001600160a01b03851690631e2eaeaf90602401602060405180830381865afa158015613c6e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612dc191906144ed565b6001600160a01b038216613cbb575f604051634b637e8f60e11b8152600401610bd29190614215565b610cb3825f83612a91565b61136483846001600160a01b031663a9059cbb8585604051602401613ae5929190614622565b5f613d006001600160a01b03841683613d44565b905080515f14158015613d24575080806020019051810190613d2291906146b8565b155b156113645782604051635274afe760e01b8152600401610bd29190614215565b6060610b2283835f845f80856001600160a01b03168486604051613d689190614900565b5f6040518083038185875af1925050503d805f8114613da2576040519150601f19603f3d011682016040523d82523d5f602084013e613da7565b606091505b5091509150612836868383613422565b828054828255905f5260205f20908101928215613e0a579160200282015b82811115613e0a57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190613dd5565b5061188b9291505b8082111561188b575f8155600101613e12565b5f60208284031215613e35575f80fd5b81356001600160e01b031981168114610b22575f80fd5b65ffffffffffff91909116815260200190565b5f5b83811015613e79578181015183820152602001613e61565b50505f910152565b5f8151808452613e98816020860160208601613e5f565b601f01601f19169290920160200192915050565b602081525f610b226020830184613e81565b5f60208284031215613ece575f80fd5b5035919050565b6001600160a01b0381168114610af5575f80fd5b5f8060408385031215613efa575f80fd5b8235613f0581613ed5565b946020939093013593505050565b5f60208284031215613f23575f80fd5b8135610b2281613ed5565b5f805f60608486031215613f40575f80fd5b8335613f4b81613ed5565b92506020840135613f5b81613ed5565b929592945050506040919091013590565b5f8083601f840112613f7c575f80fd5b5081356001600160401b03811115613f92575f80fd5b6020830191508360208260051b8501011115613fac575f80fd5b9250929050565b5f805f8060408587031215613fc6575f80fd5b84356001600160401b0380821115613fdc575f80fd5b613fe888838901613f6c565b90965094506020870135915080821115614000575f80fd5b5061400d87828801613f6c565b95989497509550505050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b038111828210171561405557614055614019565b604052919050565b5f6001600160401b0382111561407557614075614019565b5060051b60200190565b5f82601f83011261408e575f80fd5b813560206140a361409e8361405d565b61402d565b82815260059290921b840181019181810190868411156140c1575f80fd5b8286015b848110156140e55780356140d881613ed5565b83529183019183016140c5565b509695505050505050565b5f805f8060808587031215614103575f80fd5b84356001600160401b0380821115614119575f80fd5b6141258883890161407f565b955060209150818701358181111561413b575f80fd5b8701601f8101891361414b575f80fd5b803561415961409e8261405d565b81815260059190911b8201840190848101908b831115614177575f80fd5b928501925b828410156141955783358252928501929085019061417c565b975050505060408701359150808211156141ad575f80fd5b6141b98883890161407f565b935060608701359150808211156141ce575f80fd5b506141db8782880161407f565b91505092959194509250565b5f80604083850312156141f8575f80fd5b82359150602083013561420a81613ed5565b809150509250929050565b6001600160a01b0391909116815260200190565b5f60208284031215614239575f80fd5b81356001600160401b0381111561424e575f80fd5b61253b8482850161407f565b5f6020828403121561426a575f80fd5b813565ffffffffffff81168114610b22575f80fd5b5f8060208385031215614290575f80fd5b82356001600160401b03808211156142a6575f80fd5b818501915085601f8301126142b9575f80fd5b8135818111156142c7575f80fd5b8660208260061b85010111156142db575f80fd5b60209290920196919550909350505050565b5f805f805f8060608789031215614302575f80fd5b86356001600160401b0380821115614318575f80fd5b6143248a838b01613f6c565b9098509650602089013591508082111561433c575f80fd5b6143488a838b01613f6c565b90965094506040890135915080821115614360575f80fd5b5061436d89828a01613f6c565b979a9699509497509295939492505050565b65ffffffffffff92831681529116602082015260400190565b5f80602083850312156143a9575f80fd5b82356001600160401b038111156143be575f80fd5b6143ca85828601613f6c565b90969095509350505050565b5f602080830181845280855180835260408601915060408160051b87010192508387015f5b8281101561442957603f19888603018452614417858351613e81565b945092850192908501906001016143fb565b5092979650505050505050565b5f805f60608486031215614448575f80fd5b83359250602084013561445a81613ed5565b9150604084013561446a81613ed5565b809150509250925092565b5f8060408385031215614486575f80fd5b823561449181613ed5565b9150602083013561420a81613ed5565b602080825282518282018190525f9190848201906040850190845b818110156144e15783516001600160a01b0316835292840192918401916001016144bc565b50909695505050505050565b5f602082840312156144fd575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610a1f57610a1f614504565b600181811c9082168061453f57607f821691505b60208210810361455d57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52603260045260245ffd5b8183525f60208085019450825f5b858110156145b357813561459881613ed5565b6001600160a01b031687529582019590820190600101614585565b509495945050505050565b604081525f6145d1604083018688614577565b82810360208401528381526001600160fb1b038411156145ef575f80fd5b8360051b80866020840137016020019695505050505050565b5f600160ff1b820161461c5761461c614504565b505f0390565b6001600160a01b03929092168252602082015260400190565b81810381811115610a1f57610a1f614504565b918252602082015260400190565b6001600160a01b0384168152602080820184905260606040830181905283519083018190525f91848101916080850190845b818110156146aa5784518352938301939183019160010161468e565b509098975050505050505050565b5f602082840312156146c8575f80fd5b81518015158114610b22575f80fd5b602081525f61253b602083018486614577565b5f808335601e198436030181126146ff575f80fd5b8301803591506001600160401b03821115614718575f80fd5b602001915036819003821315613fac575f80fd5b828482375f8382015f81528351614747818360208801613e5f565b0195945050505050565b5f6001820161476257614762614504565b5060010190565b600181815b808511156147a357815f190482111561478957614789614504565b8085161561479657918102915b93841c939080029061476e565b509250929050565b5f826147b957506001610a1f565b816147c557505f610a1f565b81600181146147db57600281146147e557614801565b6001915050610a1f565b60ff8411156147f6576147f6614504565b50506001821b610a1f565b5060208310610133831016604e8410600b8410161715614824575081810a610a1f565b61482e8383614769565b805f190482111561484157614841614504565b029392505050565b5f610b2260ff8416836147ab565b6001600160a01b039390931683526020830191909152604082015260600190565b5f60208284031215614888575f80fd5b815160ff81168114610b22575f80fd5b5f602082840312156148a8575f80fd5b8151610b2281613ed5565b60ff8181168382160190811115610a1f57610a1f614504565b65ffffffffffff81811683821601908082111561341b5761341b614504565b5f816148f9576148f9614504565b505f190190565b5f8251614911818460208701613e5f565b9190910192915050565b634e487b7160e01b5f52601260045260245ffd5b65ffffffffffff82811682821603908082111561341b5761341b614504565b634e487b7160e01b5f52603160045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b5f60ff83168061499457634e487b7160e01b5f52601260045260245ffd5b8060ff8416069150509291505056fe2c625cc13e052290a6cbb35e9b1d53b1b3f4341f63626c17606a025fe7b17b1ab19546dff01e856fb3f010c267a7b1c60363cf8a4664e21cc89c26224620214e68bf109b95a5c15fb2bb99041323c27d15f8675e11bf7420a1cd6ad64c394f460000000000000000000000009b1d53b1b3f4341f63626c17606a025fe7b17b1aceba3d526b4d5afd91d1b752bf1fd37917c20a6daf576bcb41dd1c57c1f67e08ceba3d526b4d5afd91d1b752bf1fd37917c20a6daf576bcb41dd1c57c1f67e09a26469706673582212201c0c8611cdfa8eb586fef4401ca03b8ac32007d663ba6ab58613aed47a31fc0d64736f6c634300081500330000000000000000000000004200000000000000000000000000000000000006000000000000000000000000e5a5f3a6c88b894710992e1c2626be0deb99566e00000000000000000000000000000000000000000052b7d2dcc80cd2e4000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e5a5f3a6c88b894710992e1c2626be0deb99566e0000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000000d496f6e204c5254205661756c7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d496f6e204c5254205661756c7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000000000000000000000000000a2a15d09519be00000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d

Deployed Bytecode

0x608060405234801561000f575f80fd5b5060043610610336575f3560e01c806301e1d1141461033a57806301ffc9a714610355578063022d63fb1461037857806306fdde031461038a57806307a2d13a1461039f578063095ea7b3146103b25780630a28a477146103c55780630aa6220b146103d857806313983f27146103e257806318160ddd146103f557806323b872dd146103fd578063248a9ca31461041057806325dd173a1461042357806325f3c822146104365780632cac95ef146104495780632f2ff15d1461045d578063313ce5671461047057806336568abe1461048a57806338d52e0f1461049d578063402d267d146104cc57806346904840146104df5780634cdad506146104f25780635478786c14610505578063568efc0714610519578063593f58de146105225780635cb3bcfd1461053557806362518ddf14610548578063634e93da1461055b578063649a5ec71461056e57806364aa5ea91461058157806366d97b21146105895780636cad3fb0146105a85780636e553f65146105bb57806370a08231146105ce57806384ef8ffc146105e1578063854f4d80146105e95780638da5cb5b146105fc5780638ef977141461060457806391d148541461061757806394bf804d1461062a57806395d89b411461063d578063a001ecdd14610645578063a1872ee61461064e578063a1eda53c14610661578063a217fddf14610677578063a9059cbb1461067e578063ac9650d814610691578063aea70acc146106b1578063b26cc394146106d8578063b3d7f6b9146106e0578063b460af94146106f3578063ba08765214610706578063c55ed10e14610719578063c63d75b614610740578063c6e6f59214610753578063c81cbaa114610766578063cc8463c81461077a578063ce96cb7714610782578063cefc142914610795578063cf6eefb71461079d578063d547741f146107cb578063d602b9fd146107de578063d905777e146107e6578063dd62ed3e146107f9578063e58378bb1461080c578063e6cd317d14610820578063ebfc48e914610833578063ee6a47f814610847578063ef8b30f71461084f578063f160d36914610862578063f7d1852114610875578063f947629014610888575b5f80fd5b61034261089d565b6040519081526020015b60405180910390f35b610368610363366004613e25565b6109fb565b604051901515815260200161034c565b620697805b60405161034c9190613e4c565b610392610a25565b60405161034c9190613eac565b6103426103ad366004613ebe565b610ab5565b6103686103c0366004613ee9565b610ac0565b6103426103d3366004613ebe565b610ad7565b6103e0610ae3565b005b6103686103f0366004613f13565b610af8565b600254610342565b61036861040b366004613f2e565b610b04565b61034261041e366004613ebe565b610b29565b6103e0610431366004613fb3565b610b3d565b6103e06104443660046140f0565b610c61565b6103425f80516020614a4483398151915281565b6103e061046b3660046141e7565b610c8b565b610478610cb7565b60405160ff909116815260200161034c565b6103e06104983660046141e7565b610cc5565b7f00000000000000000000000042000000000000000000000000000000000000065b60405161034c9190614215565b6103426104da366004613f13565b610d6c565b600d546104bf906001600160a01b031681565b610342610500366004613ebe565b610d75565b6104bf5f805160206149a483398151915281565b610342600f5481565b6104bf610530366004613ebe565b610d80565b6103e0610543366004614229565b610d8c565b6104bf610556366004613ebe565b610dac565b6103e0610569366004613f13565b610dd4565b6103e061057c36600461425a565b610de7565b610342610dfa565b610342610597366004613f13565b60106020525f908152604090205481565b6103e06105b6366004613ebe565b610e05565b6103426105c93660046141e7565b610e8e565b6103426105dc366004613f13565b610ecf565b6104bf610ee9565b6103e06105f7366004614229565b610ef8565b6104bf610f18565b6103e061061236600461427f565b610f21565b6103686106253660046141e7565b611369565b6103426106383660046141e7565b611393565b6103926113ca565b610342600e5481565b6103e061065c3660046142ed565b6113d9565b610669611715565b60405161034c92919061437f565b6103425f81565b61036861068c366004613ee9565b61176b565b6106a461069f366004614398565b611778565b60405161034c91906143d6565b6104787f000000000000000000000000000000000000000000000000000000000000000481565b610342611868565b6103426106ee366004613ebe565b61188f565b610342610701366004614436565b61189b565b610342610714366004614436565b6118f2565b6104bf7f000000000000000000000000420000000000000000000000000000000000000681565b61034261074e366004613f13565b611936565b610342610761366004613ebe565b61194c565b6103425f805160206149e483398151915281565b61037d611957565b610342610790366004613f13565b6119b6565b6103e06119c9565b6107a5611a08565b604080516001600160a01b03909316835265ffffffffffff90911660208301520161034c565b6103e06107d93660046141e7565b611a29565b6103e0611a51565b6103426107f4366004613f13565b611a63565b610342610807366004614475565b611a8b565b6103425f805160206149c483398151915281565b61034261082e366004613f13565b611ab5565b6103425f80516020614a2483398151915281565b610478602081565b61034261085d366004613ebe565b611abf565b6103e0610870366004613f13565b611aca565b6104bf610883366004613ebe565b611b52565b610890611b61565b60405161034c91906144a1565b5f806108a96009611b6d565b90505f5b8181146109f6575f6108c0600983611b76565b90505f6001600160a01b0382165f80516020614a0483398151915214610950576040516370a0823160e01b81526001600160a01b038316906370a082319061090c903090600401614215565b602060405180830381865afa158015610927573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061094b91906144ed565b6109db565b6040516370a0823160e01b81526001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616906370a082319061099c903090600401614215565b602060405180830381865afa1580156109b7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109db91906144ed565b90506109e78186614518565b945082600101925050506108ad565b505090565b5f6001600160e01b031982166318a4c3c360e11b1480610a1f5750610a1f82611b81565b92915050565b606060038054610a349061452b565b80601f0160208091040260200160405190810160405280929190818152602001828054610a609061452b565b8015610aab5780601f10610a8257610100808354040283529160200191610aab565b820191905f5260205f20905b815481529060010190602001808311610a8e57829003601f168201915b5050505050905090565b5f610a1f825f611bb5565b5f33610acd818585611bf5565b5060019392505050565b5f610a1f826001611c02565b5f610aed81611c30565b610af5611c3a565b50565b5f610a1f600983611c46565b5f33610b11858285611c5a565b610b1c858585611caa565b60019150505b9392505050565b5f9081526005602052604090206001015490565b5f805160206149c4833981519152610b5481611c30565b83828114610b7557604051638078aee560e01b815260040160405180910390fd5b5f5b818114610c1b575f878783818110610b9157610b91614563565b9050602002016020810190610ba69190613f13565b9050610bb3600982611c46565b610bdb5780604051633c94b11560e01b8152600401610bd29190614215565b60405180910390fd5b858583818110610bed57610bed614563565b6001600160a01b039093165f9081526010602090815260409091209302919091013590915550600101610b77565b507f074514c11ea4ae3662be1e996c6b9c077250a155a17f430475f9721403472bba86868686604051610c5194939291906145be565b60405180910390a1505050505050565b5f805160206149c4833981519152610c7881611c30565b610c8485858585611d07565b5050505050565b81610ca957604051631fe1e13d60e11b815260040160405180910390fd5b610cb382826120a0565b5050565b5f610cc06120bc565b905090565b81158015610ceb5750610cd6610ee9565b6001600160a01b0316816001600160a01b0316145b15610d62575f80610cfa611a08565b90925090506001600160a01b038216151580610d1c5750610d1a816120ef565b155b80610d2d5750610d2b816120fc565b155b15610d4d57806040516319ca5ebb60e01b8152600401610bd29190613e4c565b50506006805465ffffffffffff60a01b191690555b610cb3828261210b565b5f610a1f61213e565b5f610a1f825f612254565b5f610a1f600983611b76565b5f805160206149e4833981519152610da381611c30565b610cb382612282565b600c8181548110610dbb575f80fd5b5f918252602090912001546001600160a01b0316905081565b5f610dde81611c30565b610cb3826122e3565b5f610df181611c30565b610cb382612350565b5f610cc06009611b6d565b5f805160206149c4833981519152610e1c81611c30565b676765c793fa10079d601b1b821115610e485760405163390edff560e11b815260040160405180910390fd5b610e506123aa565b50600e8290556040518281527ff5c230c0f5a5bb324c05594113d2e5fe9977833d5b555d47b056acf21049501d906020015b60405180910390a15050565b5f610e9761241a565b5f610ea06123aa565b9050610eb684610eaf60025490565b835f612444565b9150610ec433848685612479565b50610a1f6001600855565b6001600160a01b03165f9081526020819052604090205490565b6007546001600160a01b031690565b5f805160206149e4833981519152610f0f81611c30565b610cb38261249f565b5f610cc0610ee9565b5f805160206149e4833981519152610f3881611c30565b610f4061241a565b5f805f7f00000000000000000000000042000000000000000000000000000000000000066001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610f8f9190614215565b602060405180830381865afa158015610faa573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fce91906144ed565b9050845f5b8181146113315736888883818110610fed57610fed614563565b6040029190910191505f90506110066020830183613f13565b9050611011816124f5565b505f6001600160a01b0382165f80516020614a04833981519152146110a0576040516370a0823160e01b81526001600160a01b038316906370a082319061105c903090600401614215565b602060405180830381865afa158015611077573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061109b91906144ed565b6110a2565b855b905060208301355f808212156111ae57600160ff1b82036110c45750816110d0565b6110cd82614608565b90505b6001600160a01b0384165f80516020614a048339815191521461114d5760405163f3fef3a360e01b81526001600160a01b0385169063f3fef3a39061111b9030908590600401614622565b5f604051808303815f87803b158015611132575f80fd5b505af1158015611144573d5f803e3d5ffd5b5050505061115a565b611157818961463b565b97505b611164818a614518565b9850836001600160a01b03167fa2c440e4b34ac79fe297e62c2b414893528a4bb036f157263a3f41066a2a895f826040516111a191815260200190565b60405180910390a2611321565b5f821315611321576001600160ff1b0382036111cb5750876111ce565b50805b5f6111d98285614518565b6001600160a01b0386165f908152601060205260409020549091508082111561121957818160405163ed4e62f360e01b8152600401610bd292919061464e565b6001600160a01b0386165f80516020614a04833981519152146112c2576001600160a01b038616637ca5643d30855f604051908082528060200260200182016040528015611271578160200160208202803683370190505b506040518463ffffffff1660e01b81526004016112909392919061465c565b5f604051808303815f87803b1580156112a7575f80fd5b505af11580156112b9573d5f803e3d5ffd5b505050506112cf565b6112cc838b614518565b99505b6112d9838d614518565b9b50856001600160a01b03167fa4625590959c192f7dca76cee1966d35131f8eb159f85a513b4b0d6093a7b0548460405161131691815260200190565b60405180910390a250505b8560010195505050505050610fd3565b508284146113565783836040516318e7456560e21b8152600401610bd292919061464e565b505050506113646001600855565b505050565b5f9182526005602090815260408084206001600160a01b0393909316845291905290205460ff1690565b5f61139c61241a565b5f6113a56123aa565b90506113bc846113b460025490565b836001612543565b9150610ec433848487612479565b606060048054610a349061452b565b5f805160206149c48339815191526113f081611c30565b855f5b81811461165b575f89898381811061140d5761140d614563565b90506020020160208101906114229190613f13565b9050739b1d53b1b3f4341f63626c17606a025fe7b17b19196001600160a01b038216016114f7576040516370a0823160e01b81526001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616906370a0823190611495903090600401614215565b602060405180830381865afa1580156114b0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d491906144ed565b156114f257604051631ea9a9e360e31b815260040160405180910390fd5b611612565b60405163023da9f960e01b81526001600160a01b0382169063023da9f990611523903090600401614215565b602060405180830381865afa15801561153e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061156291906144ed565b1561158257806040516325dce25160e21b8152600401610bd29190614215565b60405163095ea7b360e01b81526001600160a01b037f0000000000000000000000004200000000000000000000000000000000000006169063095ea7b3906115d09084905f90600401614622565b6020604051808303815f875af11580156115ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061161091906146b8565b505b61161d60098261256f565b61163c5780604051633c94b11560e01b8152600401610bd29190614215565b6001600160a01b03165f908152601060205260408120556001016113f3565b506116978686808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061228292505050565b6116d28484808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061249f92505050565b7fdb8fabacb902a02141e8855f3dfecd70fdb0b1d389bd24cb976b7de67259470488886040516117039291906146d7565b60405180910390a15050505050505050565b6007545f90600160d01b900465ffffffffffff16611732816120ef565b80156117445750611742816120fc565b155b61174f575f80611763565b600754600160a01b900465ffffffffffff16815b915091509091565b5f33610acd818585611caa565b604080515f815260208101909152606090826001600160401b038111156117a1576117a1614019565b6040519080825280602002602001820160405280156117d457816020015b60608152602001906001900390816117bf5790505b5091505f5b8381101561186057611830308686848181106117f7576117f7614563565b905060200281019061180991906146ea565b8560405160200161181c9392919061472c565b604051602081830303815290604052612583565b83828151811061184257611842614563565b6020026020010181905250808061185890614751565b9150506117d9565b505092915050565b5f5f805160206149c483398151915261188081611c30565b6118886123aa565b91505b5090565b5f610a1f826001612254565b5f6118a461241a565b5f6118ad6123aa565b90506118c4856118bc60025490565b836001612444565b91506118da858203868311026125ec565b6125ec565b6118e7338585888661262e565b50610b226001600855565b5f6118fb61241a565b5f6119046123aa565b905061191a8561191360025490565b835f612543565b91506119296118d5838361463b565b6118e7338585858961262e565b5f8061194061213e565b9050610b22815f611c02565b5f610a1f825f612644565b6007545f90600160d01b900465ffffffffffff16611974816120ef565b80156119845750611984816120fc565b61199f57600654600160d01b900465ffffffffffff16611888565b5050600754600160a01b900465ffffffffffff1690565b5f6119c08261267b565b50909392505050565b5f6119d2611a08565b509050336001600160a01b03821614611a005733604051636116401160e11b8152600401610bd29190614215565b610af56126fd565b6006546001600160a01b03811691600160a01b90910465ffffffffffff1690565b81611a4757604051631fe1e13d60e11b815260040160405180910390fd5b610cb38282612777565b5f611a5b81611c30565b610af5612793565b5f805f80611a708561267b565b925092509250611a828383835f612444565b95945050505050565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b5f610a1f826124f5565b5f610a1f825f611c02565b5f805160206149c4833981519152611ae181611c30565b6001600160a01b038216611b0857604051630ed1b8b360e31b815260040160405180910390fd5b600d80546001600160a01b0319166001600160a01b0384169081179091556040517f6632de8ab33c46549f7bb29f647ea0d751157b25fe6a14b1bcc7527cdfbeb79c905f90a25050565b600b8181548110610dbb575f80fd5b6060610cc0600961279d565b5f610a1f825490565b5f610b2283836127a9565b5f6001600160e01b03198216637965db0b60e01b1480610a1f57506301ffc9a760e01b6001600160e01b0319831614610a1f565b5f610b22611bc161089d565b611bcc906001614518565b611bd46127cf565b611bdf90600a614849565b600254611bec9190614518565b859190856127f3565b6113648383836001612840565b5f805f611c0d612912565b91509150611a828583611c1f60025490565b611c299190614518565b8387612444565b610af5813361298a565b611c445f806129b5565b565b5f610b22836001600160a01b038416612a7a565b5f611c658484611a8b565b90505f198114611ca45781811015611c9657828183604051637dc7a0d960e11b8152600401610bd293929190614857565b611ca484848484035f612840565b50505050565b6001600160a01b038316611cd3575f604051634b637e8f60e11b8152600401610bd29190614215565b6001600160a01b038216611cfc575f60405163ec442f0560e01b8152600401610bd29190614215565b611364838383612a91565b8251845114611d295760405163db78979f60e01b815260040160405180910390fd5b5f845190505f7f00000000000000000000000042000000000000000000000000000000000000066001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d8b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611daf9190614878565b90505f5b828114612033575f878281518110611dcd57611dcd614563565b602002602001015190505f805160206149a48339815191525f1c6001600160a01b0316816001600160a01b031614611fca578260ff16816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e3f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e639190614878565b60ff1614611e865780604051632a9d2b9360e21b8152600401610bd29190614215565b7f00000000000000000000000042000000000000000000000000000000000000066001600160a01b0316816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eec573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f109190614898565b6001600160a01b031614611f395780604051631717aff760e11b8152600401610bd29190614215565b60405163095ea7b360e01b81526001600160a01b037f0000000000000000000000004200000000000000000000000000000000000006169063095ea7b390611f889084905f1990600401614622565b6020604051808303815f875af1158015611fa4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fc891906146b8565b505b611fd5600982612ba4565b611ff457806040516303bbdb0560e61b8152600401610bd29190614215565b86828151811061200657612006614563565b6020908102919091018101516001600160a01b039092165f90815260109091526040902055600101611db3565b5060206120406009611b6d565b111561205f5760405163abc6e9c960e01b815260040160405180910390fd5b61206884612282565b6120718361249f565b7ff893e2645bae0bc2d2ab1ce62fb949ede3945df8cfd07ce22d9a421c9943da6386604051610c5191906144a1565b6120a982610b29565b6120b281611c30565b611ca48383612bb8565b5f6120c56127cf565b610cc0907f00000000000000000000000000000000000000000000000000000000000000126148b3565b65ffffffffffff16151590565b4265ffffffffffff9091161090565b6001600160a01b03811633146121345760405163334bd91960e11b815260040160405180910390fd5b6113648282612c14565b5f8061214a6009611b6d565b90505f5b8181146109f6575f612161600983611b76565b90505f6001600160a01b0382165f80516020614a048339815191521461218f5761218a82612c5b565b612239565b6001600160a01b038083165f90815260106020526040908190205490516370a0823160e01b8152612239927f000000000000000000000000420000000000000000000000000000000000000616906370a08231906121f1903090600401614215565b602060405180830381865afa15801561220c573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061223091906144ed565b80821191030290565b90506122458186614518565b9450826001019250505061214e565b5f805f61225f612912565b91509150611a82858361227160025490565b61227b9190614518565b8387612543565b61228b81612dcd565b805161229e90600b906020840190613db7565b50336001600160a01b03167f823a01301c8a565de5c9d7aa034ab0841b6bfb2c3a497218fa6226b9c65d3550826040516122d891906144a1565b60405180910390a250565b5f6122ec611957565b6122f542612edf565b6122ff91906148cc565b905061230b8282612f11565b816001600160a01b03167f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed6826040516123449190613e4c565b60405180910390a25050565b5f61235a82612f86565b61236342612edf565b61236d91906148cc565b905061237982826129b5565b7ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b8282604051610e8292919061437f565b5f806123b4612912565b9250905080156123d457600d546123d4906001600160a01b031682612fcd565b6123dd826125ec565b7fb2195cd5fcca9daf7d719d0466344f2078e77914d0edb599d6d50985697af99d818360405161240e92919061464e565b60405180910390a15090565b60026008540361243d57604051633ee5aeb560e01b815260040160405180910390fd5b6002600855565b5f611a826124506127cf565b61245b90600a614849565b6124659086614518565b612470856001614518565b879190856127f3565b61248584848484613001565b61248e8261307c565b611ca482600f546118d59190614518565b6124a881612dcd565b80516124bb90600c906020840190613db7565b50336001600160a01b03167fc618a15cb59b7ae9a202a339c6d0b97c4752b6e1a27e06f7b7e7b1d062f6688f826040516122d891906144a1565b6001600160a01b0381165f818152600a60205260408120549091908083036125325783604051633c94b11560e01b8152600401610bd29190614215565b61253b816148eb565b949350505050565b5f611a82612552846001614518565b61255a6127cf565b61256590600a614849565b6124709087614518565b5f610b22836001600160a01b038416613338565b60605f80846001600160a01b03168460405161259f9190614900565b5f60405180830381855af49150503d805f81146125d7576040519150601f19603f3d011682016040523d82523d5f602084013e6125dc565b606091505b5091509150611a82858383613422565b600f8190556040517f348e3f4755df402c99d6e3ba0b948083686ad2a43908f164baf843ca5c9008b290612623908390819061464e565b60405180910390a150565b61263782613470565b610c848585858585613640565b5f610b226126506127cf565b61265b90600a614849565b6002546126689190614518565b61267061089d565b611bec906001614518565b5f805f80612687612912565b925090508061269560025490565b61269f9190614518565b92505f6126ab86610ecf565b600d549091506001600160a01b03908116908716036126d1576126ce8282614518565b90505b6126dd8185855f612543565b94506126e8856136f7565b6126f2908661463b565b945050509193909250565b5f80612707611a08565b91509150612714816120ef565b15806127265750612724816120fc565b155b1561274657806040516319ca5ebb60e01b8152600401610bd29190613e4c565b6127575f612752610ee9565b612c14565b506127625f83612bb8565b5050600680546001600160d01b031916905550565b61278082610b29565b61278981611c30565b611ca48383612c14565b611c445f80612f11565b60605f610b228361381b565b5f825f0182815481106127be576127be614563565b905f5260205f200154905092915050565b7f000000000000000000000000000000000000000000000000000000000000000490565b5f80612800868686613874565b905061280b83613933565b801561282657505f84806128215761282161491b565b868809115b15611a8257612836600182614518565b9695505050505050565b6001600160a01b038416612869575f60405163e602df0560e01b8152600401610bd29190614215565b6001600160a01b038316612892575f604051634a1406b160e11b8152600401610bd29190614215565b6001600160a01b038085165f9081526001602090815260408083209387168352929052208290558015611ca457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161290491815260200190565b60405180910390a350505050565b5f8061291c61089d565b90505f61292f82600f5480821191030290565b905080158015906129415750600e5415155b1561298557600e545f90612962908390676765c793fa10079d601b1b613874565b90506129818161297160025490565b61297b848761463b565b5f612444565b9350505b509091565b6129948282611369565b610cb357808260405163e2517d3f60e01b8152600401610bd2929190614622565b600754600160d01b900465ffffffffffff166129d0816120ef565b15612a3d576129de816120fc565b15612a1457600754600680546001600160d01b0316600160a01b90920465ffffffffffff16600160d01b02919091179055612a3d565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec5905f90a15b50600780546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b5f9081526001919091016020526040902054151590565b6001600160a01b038316612abb578060025f828254612ab09190614518565b90915550612b189050565b6001600160a01b0383165f9081526020819052604090205481811015612afa5783818360405163391434e360e21b8152600401610bd293929190614857565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b038216612b3457600280548290039055612b52565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051612b9791815260200190565b60405180910390a3505050565b5f610b22836001600160a01b03841661395f565b5f82612c0a575f612bc7610ee9565b6001600160a01b031614612bee57604051631fe1e13d60e11b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0384161790555b610b2283836139a6565b5f82158015612c3b5750612c26610ee9565b6001600160a01b0316826001600160a01b0316145b15612c5157600780546001600160a01b03191690555b610b228383613a30565b5f816001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c98573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612cbc91906146b8565b15612cc857505f919050565b6001600160a01b0382165f818152601060205260408082205490516370a0823160e01b81529192612d07926370a08231906121f1903090600401614215565b604051631e2eaeaf60e01b81525f80516020614a4483398151915260048201529091505f90612dc1906001600160a01b03861690631e2eaeaf90602401602060405180830381865afa158015612d5f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d8391906144ed565b5f1c856001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561220c573d5f803e3d5ffd5b905061253b8282613a9b565b5f612dd86009611b6d565b8251909150808214612e015780826040516319376e2160e01b8152600401610bd292919061464e565b5f816001600160401b03811115612e1a57612e1a614019565b604051908082528060200260200182016040528015612e43578160200160208202803683370190505b5090505f5b828114610c84575f612e72868381518110612e6557612e65614563565b60200260200101516124f5565b9050828181518110612e8657612e86614563565b602002602001015115156001151503612eb25760405163233b822f60e11b815260040160405180910390fd5b6001838281518110612ec657612ec6614563565b9115156020928302919091019091015250600101612e48565b5f65ffffffffffff82111561188b576040516306dfcc6560e41b81526030600482015260248101839052604401610bd2565b5f612f1a611a08565b6006805465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b038816171790559150612f549050816120ef565b15611364576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a9605109905f90a1505050565b5f80612f90611957565b90508065ffffffffffff168365ffffffffffff1611612fb857612fb3838261492f565b610b22565b610b2265ffffffffffff841662069780613a9b565b6001600160a01b038216612ff6575f60405163ec442f0560e01b8152600401610bd29190614215565b610cb35f8383612a91565b61302d7f0000000000000000000000004200000000000000000000000000000000000006853085613ab0565b6130378382612fcd565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7848460405161290492919061464e565b5f817f00000000000000000000000042000000000000000000000000000000000000066001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016130ca9190614215565b602060405180830381865afa1580156130e5573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061310991906144ed565b613113919061463b565b600b549091505f5b818114613318575f600b828154811061313657613136614563565b5f9182526020822001546001600160a01b031691505f80516020614a04833981519152821461316d5761316882612c5b565b61318d565b6001600160a01b0382165f90815260106020526040902054858103908610025b9050801561330e575f6131a08288613a9b565b90506001600160a01b0383165f80516020614a04833981519152146132ef575f613237676765c793fa10079d601b1b856001600160a01b031663070a96456040518163ffffffff1660e01b8152600401602060405180830381865afa15801561320b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061322f91906144ed565b849190613874565b90508782148015613246575080155b15613255575050505050505050565b6001600160a01b038416637ca5643d30845f604051908082528060200260200182016040528015613290578160200160208202803683370190505b506040518463ffffffff1660e01b81526004016132af9392919061465c565b5f604051808303815f87803b1580156132c6575f80fd5b505af19250505080156132d7575060015b156132e9576132e6828961463b565b97505b506132fc565b6132f9818861463b565b96505b865f0361330c5750505050505050565b505b505060010161311b565b5082156113645760405163b1513a2f60e01b815260040160405180910390fd5b5f8181526001830160205260408120548015613412575f61335a60018361463b565b85549091505f9061336d9060019061463b565b90508082146133cc575f865f01828154811061338b5761338b614563565b905f5260205f200154905080875f0184815481106133ab576133ab614563565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806133dd576133dd61494e565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610a1f565b5f915050610a1f565b5092915050565b60608261343257612fb382613b17565b815115801561344957506001600160a01b0384163b155b156134695783604051639996b31560e01b8152600401610bd29190614215565b5080610b22565b6040516370a0823160e01b81525f906001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616906370a08231906134be903090600401614215565b602060405180830381865afa1580156134d9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906134fd91906144ed565b600c549091505f5b818114613620575f600c828154811061352057613520614563565b5f9182526020822001546001600160a01b031691505f80516020614a0483398151915282146135575761355282613b40565b613559565b845b90508015613616575f61356c8288613a9b565b90506001600160a01b0383165f80516020614a04833981519152146135f75760405163f3fef3a360e01b81526001600160a01b0384169063f3fef3a3906135b99030908590600401614622565b5f604051808303815f87803b1580156135d0575f80fd5b505af19250505080156135e1575060015b15613604576135f0818861463b565b9650613604565b613601818861463b565b96505b865f036136145750505050505050565b505b5050600101613505565b508215611364576040516322d95ee960e01b815260040160405180910390fd5b826001600160a01b0316856001600160a01b03161461366457613664838683611c5a565b61366e8382613c92565b6136997f00000000000000000000000042000000000000000000000000000000000000068584613cc6565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db85856040516136e892919061464e565b60405180910390a45050505050565b600c545f90815b818114613813575f600c828154811061371957613719614563565b5f9182526020822001546001600160a01b031691505f80516020614a0483398151915282146137505761374b82613b40565b6137db565b6040516370a0823160e01b81526001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616906370a082319061379c903090600401614215565b602060405180830381865afa1580156137b7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137db91906144ed565b90505f6137e88288613a9b565b90506137f4818861463b565b9650865f0361380557505050613813565b8360010193505050506136fe565b509192915050565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561386857602002820191905f5260205f20905b815481526020019060010190808311613854575b50505050509050919050565b5f838302815f1985870982811083820303915050805f036138a85783828161389e5761389e61491b565b0492505050610b22565b8084116138c85760405163227bc15360e01b815260040160405180910390fd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f600282600381111561394857613948614962565b6139529190614976565b60ff166001149050919050565b5f61396a8383612a7a565b61399f57508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610a1f565b505f610a1f565b5f6139b18383611369565b61399f575f8381526005602090815260408083206001600160a01b03861684529091529020805460ff191660011790556139e83390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001610a1f565b5f613a3b8383611369565b1561399f575f8381526005602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4506001610a1f565b5f818310613aa95781610b22565b5090919050565b6040516001600160a01b038481166024830152838116604483015260648201839052611ca49186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613cec565b805115613b275780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b5f816001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613b7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613ba191906146b8565b15613bad57505f919050565b6040516370a0823160e01b81525f906001600160a01b038416906370a0823190613bdb903090600401614215565b602060405180830381865afa158015613bf6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c1a91906144ed565b604051631e2eaeaf60e01b81525f80516020614a2483398151915260048201529091505f906001600160a01b03851690631e2eaeaf90602401602060405180830381865afa158015613c6e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612dc191906144ed565b6001600160a01b038216613cbb575f604051634b637e8f60e11b8152600401610bd29190614215565b610cb3825f83612a91565b61136483846001600160a01b031663a9059cbb8585604051602401613ae5929190614622565b5f613d006001600160a01b03841683613d44565b905080515f14158015613d24575080806020019051810190613d2291906146b8565b155b156113645782604051635274afe760e01b8152600401610bd29190614215565b6060610b2283835f845f80856001600160a01b03168486604051613d689190614900565b5f6040518083038185875af1925050503d805f8114613da2576040519150601f19603f3d011682016040523d82523d5f602084013e613da7565b606091505b5091509150612836868383613422565b828054828255905f5260205f20908101928215613e0a579160200282015b82811115613e0a57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190613dd5565b5061188b9291505b8082111561188b575f8155600101613e12565b5f60208284031215613e35575f80fd5b81356001600160e01b031981168114610b22575f80fd5b65ffffffffffff91909116815260200190565b5f5b83811015613e79578181015183820152602001613e61565b50505f910152565b5f8151808452613e98816020860160208601613e5f565b601f01601f19169290920160200192915050565b602081525f610b226020830184613e81565b5f60208284031215613ece575f80fd5b5035919050565b6001600160a01b0381168114610af5575f80fd5b5f8060408385031215613efa575f80fd5b8235613f0581613ed5565b946020939093013593505050565b5f60208284031215613f23575f80fd5b8135610b2281613ed5565b5f805f60608486031215613f40575f80fd5b8335613f4b81613ed5565b92506020840135613f5b81613ed5565b929592945050506040919091013590565b5f8083601f840112613f7c575f80fd5b5081356001600160401b03811115613f92575f80fd5b6020830191508360208260051b8501011115613fac575f80fd5b9250929050565b5f805f8060408587031215613fc6575f80fd5b84356001600160401b0380821115613fdc575f80fd5b613fe888838901613f6c565b90965094506020870135915080821115614000575f80fd5b5061400d87828801613f6c565b95989497509550505050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b038111828210171561405557614055614019565b604052919050565b5f6001600160401b0382111561407557614075614019565b5060051b60200190565b5f82601f83011261408e575f80fd5b813560206140a361409e8361405d565b61402d565b82815260059290921b840181019181810190868411156140c1575f80fd5b8286015b848110156140e55780356140d881613ed5565b83529183019183016140c5565b509695505050505050565b5f805f8060808587031215614103575f80fd5b84356001600160401b0380821115614119575f80fd5b6141258883890161407f565b955060209150818701358181111561413b575f80fd5b8701601f8101891361414b575f80fd5b803561415961409e8261405d565b81815260059190911b8201840190848101908b831115614177575f80fd5b928501925b828410156141955783358252928501929085019061417c565b975050505060408701359150808211156141ad575f80fd5b6141b98883890161407f565b935060608701359150808211156141ce575f80fd5b506141db8782880161407f565b91505092959194509250565b5f80604083850312156141f8575f80fd5b82359150602083013561420a81613ed5565b809150509250929050565b6001600160a01b0391909116815260200190565b5f60208284031215614239575f80fd5b81356001600160401b0381111561424e575f80fd5b61253b8482850161407f565b5f6020828403121561426a575f80fd5b813565ffffffffffff81168114610b22575f80fd5b5f8060208385031215614290575f80fd5b82356001600160401b03808211156142a6575f80fd5b818501915085601f8301126142b9575f80fd5b8135818111156142c7575f80fd5b8660208260061b85010111156142db575f80fd5b60209290920196919550909350505050565b5f805f805f8060608789031215614302575f80fd5b86356001600160401b0380821115614318575f80fd5b6143248a838b01613f6c565b9098509650602089013591508082111561433c575f80fd5b6143488a838b01613f6c565b90965094506040890135915080821115614360575f80fd5b5061436d89828a01613f6c565b979a9699509497509295939492505050565b65ffffffffffff92831681529116602082015260400190565b5f80602083850312156143a9575f80fd5b82356001600160401b038111156143be575f80fd5b6143ca85828601613f6c565b90969095509350505050565b5f602080830181845280855180835260408601915060408160051b87010192508387015f5b8281101561442957603f19888603018452614417858351613e81565b945092850192908501906001016143fb565b5092979650505050505050565b5f805f60608486031215614448575f80fd5b83359250602084013561445a81613ed5565b9150604084013561446a81613ed5565b809150509250925092565b5f8060408385031215614486575f80fd5b823561449181613ed5565b9150602083013561420a81613ed5565b602080825282518282018190525f9190848201906040850190845b818110156144e15783516001600160a01b0316835292840192918401916001016144bc565b50909695505050505050565b5f602082840312156144fd575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610a1f57610a1f614504565b600181811c9082168061453f57607f821691505b60208210810361455d57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52603260045260245ffd5b8183525f60208085019450825f5b858110156145b357813561459881613ed5565b6001600160a01b031687529582019590820190600101614585565b509495945050505050565b604081525f6145d1604083018688614577565b82810360208401528381526001600160fb1b038411156145ef575f80fd5b8360051b80866020840137016020019695505050505050565b5f600160ff1b820161461c5761461c614504565b505f0390565b6001600160a01b03929092168252602082015260400190565b81810381811115610a1f57610a1f614504565b918252602082015260400190565b6001600160a01b0384168152602080820184905260606040830181905283519083018190525f91848101916080850190845b818110156146aa5784518352938301939183019160010161468e565b509098975050505050505050565b5f602082840312156146c8575f80fd5b81518015158114610b22575f80fd5b602081525f61253b602083018486614577565b5f808335601e198436030181126146ff575f80fd5b8301803591506001600160401b03821115614718575f80fd5b602001915036819003821315613fac575f80fd5b828482375f8382015f81528351614747818360208801613e5f565b0195945050505050565b5f6001820161476257614762614504565b5060010190565b600181815b808511156147a357815f190482111561478957614789614504565b8085161561479657918102915b93841c939080029061476e565b509250929050565b5f826147b957506001610a1f565b816147c557505f610a1f565b81600181146147db57600281146147e557614801565b6001915050610a1f565b60ff8411156147f6576147f6614504565b50506001821b610a1f565b5060208310610133831016604e8410600b8410161715614824575081810a610a1f565b61482e8383614769565b805f190482111561484157614841614504565b029392505050565b5f610b2260ff8416836147ab565b6001600160a01b039390931683526020830191909152604082015260600190565b5f60208284031215614888575f80fd5b815160ff81168114610b22575f80fd5b5f602082840312156148a8575f80fd5b8151610b2281613ed5565b60ff8181168382160190811115610a1f57610a1f614504565b65ffffffffffff81811683821601908082111561341b5761341b614504565b5f816148f9576148f9614504565b505f190190565b5f8251614911818460208701613e5f565b9190910192915050565b634e487b7160e01b5f52601260045260245ffd5b65ffffffffffff82811682821603908082111561341b5761341b614504565b634e487b7160e01b5f52603160045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b5f60ff83168061499457634e487b7160e01b5f52601260045260245ffd5b8060ff8416069150509291505056fe2c625cc13e052290a6cbb35e9b1d53b1b3f4341f63626c17606a025fe7b17b1ab19546dff01e856fb3f010c267a7b1c60363cf8a4664e21cc89c26224620214e68bf109b95a5c15fb2bb99041323c27d15f8675e11bf7420a1cd6ad64c394f460000000000000000000000009b1d53b1b3f4341f63626c17606a025fe7b17b1aceba3d526b4d5afd91d1b752bf1fd37917c20a6daf576bcb41dd1c57c1f67e08ceba3d526b4d5afd91d1b752bf1fd37917c20a6daf576bcb41dd1c57c1f67e09a26469706673582212201c0c8611cdfa8eb586fef4401ca03b8ac32007d663ba6ab58613aed47a31fc0d64736f6c63430008150033

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

0000000000000000000000004200000000000000000000000000000000000006000000000000000000000000e5a5f3a6c88b894710992e1c2626be0deb99566e00000000000000000000000000000000000000000052b7d2dcc80cd2e4000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e5a5f3a6c88b894710992e1c2626be0deb99566e0000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000000d496f6e204c5254205661756c7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d496f6e204c5254205661756c7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000000000000000000000000000a2a15d09519be00000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d

-----Decoded View---------------
Arg [0] : _baseAsset (address): 0x4200000000000000000000000000000000000006
Arg [1] : _feeRecipient (address): 0xE5a5F3A6C88B894710992e1C2626be0DEB99566E
Arg [2] : _feePercentage (uint256): 100000000000000000000000000
Arg [3] : _name (string): Ion LRT Vault
Arg [4] : _symbol (string): Ion LRT Vault
Arg [5] : initialDelay (uint48): 0
Arg [6] : initialDefaultAdmin (address): 0xE5a5F3A6C88B894710992e1C2626be0DEB99566E
Arg [7] : marketsArgs (tuple):
Arg [1] : marketsToAdd (address[]): 0x00000000000fA8e0FD26b4554d067CF1856De7F5,0x000000000054D04Bd84f465ae7aD3aC39072255D
Arg [2] : allocationCaps (uint256[]): 3000000000000000000000,3000000000000000000000
Arg [3] : newSupplyQueue (address[]): 0x00000000000fA8e0FD26b4554d067CF1856De7F5,0x000000000054D04Bd84f465ae7aD3aC39072255D
Arg [4] : newWithdrawQueue (address[]): 0x00000000000fA8e0FD26b4554d067CF1856De7F5,0x000000000054D04Bd84f465ae7aD3aC39072255D


-----Encoded View---------------
28 Constructor Arguments found :
Arg [0] : 0000000000000000000000004200000000000000000000000000000000000006
Arg [1] : 000000000000000000000000e5a5f3a6c88b894710992e1c2626be0deb99566e
Arg [2] : 00000000000000000000000000000000000000000052b7d2dcc80cd2e4000000
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [6] : 000000000000000000000000e5a5f3a6c88b894710992e1c2626be0deb99566e
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000180
Arg [8] : 000000000000000000000000000000000000000000000000000000000000000d
Arg [9] : 496f6e204c5254205661756c7400000000000000000000000000000000000000
Arg [10] : 000000000000000000000000000000000000000000000000000000000000000d
Arg [11] : 496f6e204c5254205661756c7400000000000000000000000000000000000000
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [13] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [14] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [15] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [16] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [17] : 00000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5
Arg [18] : 000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d
Arg [19] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [20] : 0000000000000000000000000000000000000000000000a2a15d09519be00000
Arg [21] : 0000000000000000000000000000000000000000000000a2a15d09519be00000
Arg [22] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [23] : 00000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5
Arg [24] : 000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d
Arg [25] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [26] : 00000000000000000000000000000000000fa8e0fd26b4554d067cf1856de7f5
Arg [27] : 000000000000000000000000000000000054d04bd84f465ae7ad3ac39072255d


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  ]
[ 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.