ETH Price: $2,802.62 (+1.22%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

TokenTracker

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Redeem238597522025-11-23 6:17:5917 hrs ago1763878679IN
0x50Bd66D5...0D059DD11
0 ETH0.000422460.58640901
Redeem238537422025-11-22 9:57:4737 hrs ago1763805467IN
0x50Bd66D5...0D059DD11
0 ETH0.000421640.56953469
Deposit238495882025-11-21 19:55:592 days ago1763754959IN
0x50Bd66D5...0D059DD11
0 ETH0.000998051.73079898
Deposit238481082025-11-21 14:55:472 days ago1763736947IN
0x50Bd66D5...0D059DD11
0 ETH0.00242654.20796792
Swap238458832025-11-21 7:24:232 days ago1763709863IN
0x50Bd66D5...0D059DD11
0 ETH0.002112.06248613
Redeem238397932025-11-20 10:55:473 days ago1763636147IN
0x50Bd66D5...0D059DD11
0 ETH0.000780471.09928846
Approve238351032025-11-19 19:08:354 days ago1763579315IN
0x50Bd66D5...0D059DD11
0 ETH0.000042430.91249621
Swap238345772025-11-19 17:22:114 days ago1763572931IN
0x50Bd66D5...0D059DD11
0 ETH0.003488014.44075563
Swap238345272025-11-19 17:12:114 days ago1763572331IN
0x50Bd66D5...0D059DD11
0 ETH0.004402565.14110211
Deposit238318102025-11-19 8:02:234 days ago1763539343IN
0x50Bd66D5...0D059DD11
0 ETH0.000419820.7618
Redeem238301052025-11-19 2:17:234 days ago1763518643IN
0x50Bd66D5...0D059DD11
0 ETH0.000118840.1674014
Deposit238272692025-11-18 16:44:235 days ago1763484263IN
0x50Bd66D5...0D059DD11
0 ETH0.000876531.60451426
Deposit238272582025-11-18 16:42:115 days ago1763484131IN
0x50Bd66D5...0D059DD11
0 ETH0.000783521.37898816
Redeem238270002025-11-18 15:50:235 days ago1763481023IN
0x50Bd66D5...0D059DD11
0 ETH0.001952312.74980241
Redeem238269732025-11-18 15:44:475 days ago1763480687IN
0x50Bd66D5...0D059DD11
0 ETH0.002021572.85863719
Redeem238268942025-11-18 15:28:595 days ago1763479739IN
0x50Bd66D5...0D059DD11
0 ETH0.00236253.34073487
Transfer238233462025-11-18 3:30:475 days ago1763436647IN
0x50Bd66D5...0D059DD11
0 ETH0.000037410.79780574
Deposit238233212025-11-18 3:25:475 days ago1763436347IN
0x50Bd66D5...0D059DD11
0 ETH0.000755781.34152106
Deposit238199962025-11-17 16:11:476 days ago1763395907IN
0x50Bd66D5...0D059DD11
0 ETH0.000491150.89909697
Redeem238136012025-11-16 18:41:597 days ago1763318519IN
0x50Bd66D5...0D059DD11
0 ETH0.000222090.31407077
Swap238133802025-11-16 17:57:117 days ago1763315831IN
0x50Bd66D5...0D059DD11
0 ETH0.002917192.24035818
Redeem238090042025-11-16 3:17:117 days ago1763263031IN
0x50Bd66D5...0D059DD11
0 ETH0.00005560.07970396
Deposit238067812025-11-15 19:49:598 days ago1763236199IN
0x50Bd66D5...0D059DD11
0 ETH0.000035440.06465186
Deposit238067352025-11-15 19:40:478 days ago1763235647IN
0x50Bd66D5...0D059DD11
0 ETH0.000997881.76508924
Approve238031202025-11-15 7:32:238 days ago1763191943IN
0x50Bd66D5...0D059DD11
0 ETH0.000001560.06396523
View all transactions

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Method Block
From
To
0x60c06040226391602025-06-05 15:00:11171 days ago1749135611  Contract Creation0 ETH
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
sBold

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {BaseSBold} from "./base/BaseSBold.sol";
import {SpLogic} from "./libraries/logic/SpLogic.sol";
import {SwapLogic} from "./libraries/logic/SwapLogic.sol";
import {QuoteLogic} from "./libraries/logic/QuoteLogic.sol";
import {Constants} from "./libraries/helpers/Constants.sol";
import {Decimals} from "./libraries/helpers/Decimals.sol";
import {TransientStorage} from "./libraries/helpers/TransientStorage.sol";

/// @title sBold Protocol
/// @notice The $BOLD ERC4626 yield-bearing token.
contract sBold is BaseSBold {
    using Math for uint256;

    /// @notice Deploys sBold.
    /// @param _asset The address of the $BOLD instance.
    /// @param _name The name of `this` contract.
    /// @param _symbol The symbol of `this` contract.
    /// @param _sps The Stability Pools memory array.
    /// @param _priceOracle The address of the price oracle adapter.
    /// @param _vault The address of the vault for fee transfers.
    constructor(
        address _asset,
        string memory _name,
        string memory _symbol,
        SPConfig[] memory _sps,
        address _priceOracle,
        address _vault
    ) ERC4626(ERC20(_asset)) ERC20(_name, _symbol) BaseSBold(_sps, _priceOracle, _vault) {
        super.deposit(10 ** decimals(), address(this));
    }

    /*//////////////////////////////////////////////////////////////
                                 LOGIC
    //////////////////////////////////////////////////////////////*/

    /// @notice Deposits $BOLD in SP and mints corresponding $sBOLD.
    /// @param assets The amount of assets to deposit + fee to collect.
    /// @param receiver The address to mint the shares to.
    /// @return The amount of shares.
    function deposit(
        uint256 assets,
        address receiver
    ) public override whenNotPaused nonReentrant execCollateralOps returns (uint256) {
        uint256 maxAssets = _maxDeposit(receiver);
        if (assets > maxAssets) {
            revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets);
        }

        uint256 fee = _feeOnTotal(assets, feeBps);

        uint256 shares = super.previewDeposit(assets - fee);

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

        if (fee > 0) SafeERC20.safeTransfer(IERC20(asset()), vault, fee);

        SpLogic.provideToSP(sps, assets - fee);

        return shares;
    }

    /// @notice Mints shares of $sBOLD and provides corresponding $BOLD to SP.
    /// @param shares The amount of shares to mint.
    /// @param receiver The address to send the shares to.
    /// @return The amount of assets.
    function mint(
        uint256 shares,
        address receiver
    ) public override whenNotPaused nonReentrant execCollateralOps returns (uint256) {
        uint256 maxShares = _maxMint(receiver);
        if (shares > maxShares) {
            revert ERC4626ExceededMaxMint(receiver, shares, maxShares);
        }

        uint256 assets = super.previewMint(shares);

        uint256 fee = _feeOnRaw(assets, feeBps);

        _deposit(_msgSender(), receiver, assets + fee, shares);

        if (fee > 0) SafeERC20.safeTransfer(IERC20(asset()), vault, fee);

        SpLogic.provideToSP(sps, assets);

        return assets + fee;
    }

    /// @notice Redeems shares of $sBOLD in $BOLD and burns $sBOLD.
    /// @param shares The amount of shares to redeem.
    /// @param receiver The address to send the assets to.
    /// @param owner The owner of the shares.
    /// @return The amount of assets.
    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) public override whenNotPaused nonReentrant execCollateralOps returns (uint256) {
        uint256 maxShares = _maxRedeem(owner);
        if (shares > maxShares) {
            revert ERC4626ExceededMaxRedeem(owner, shares, maxShares);
        }

        uint256 assets = super.previewRedeem(shares);

        SpLogic.withdrawFromSP(sps, IERC20(asset()), decimals(), assets, true);

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

        return assets;
    }

    /// @notice Withdraws assets $BOLD from the SP and burns $sBOLD.
    /// @param assets The amount of assets to withdraw.
    /// @param receiver The address to send the shares to.
    /// @param owner The owner of the shares.
    /// @return The amount of shares.
    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) public override whenNotPaused nonReentrant execCollateralOps returns (uint256) {
        uint256 maxAssets = _maxWithdraw(owner);
        if (assets > maxAssets) {
            revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets);
        }

        uint256 shares = super.previewWithdraw(assets);

        SpLogic.withdrawFromSP(sps, IERC20(asset()), decimals(), assets, true);

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

        return shares;
    }

    /// @notice Swaps collateral balances to $BOLD.
    /// @param swapData The swap data.
    /// @param receiver The reward receiver.
    function swap(SwapData[] memory swapData, address receiver) public whenNotPaused nonReentrant {
        address bold = asset();

        // Prepare swap data and claim collateral.
        SwapDataWithColl[] memory swapDataWithColl = SwapLogic.prepareSwap(bold, priceOracle, sps, swapData);
        // Execute swaps for each collateral to $BOLD
        uint256 assets = SwapLogic.swap(bold, swapAdapter, swapDataWithColl, maxSlippage);

        (, uint256 swapFee, uint256 reward) = SwapLogic.applyFees(assets, swapFeeBps, rewardBps);

        IERC20 iBold = IERC20(bold);

        if (swapFee > 0) SafeERC20.safeTransfer(iBold, vault, swapFee);
        if (reward > 0) SafeERC20.safeTransfer(iBold, receiver, reward);

        uint256 assetsInternal = ERC20(bold).balanceOf(address(this));
        uint256 deadShareAmount = 10 ** decimals();

        if (assetsInternal > deadShareAmount) {
            SpLogic.provideToSP(sps, assetsInternal - deadShareAmount);
        }
    }

    /// @notice This function is able to both re-balance in terms of weights and change entirely current SPs.
    /// @param _sps The Stability Pools memory array.
    /// @param _swapData The swap data.
    function rebalanceSPs(SPConfig[] calldata _sps, SwapData[] memory _swapData) external onlyOwner nonReentrant {
        address bold = asset();

        // Prepare swap data and claim collateral.
        SwapDataWithColl[] memory swapDataWithColl = SwapLogic.prepareSwap(bold, priceOracle, sps, _swapData);
        // Execute swaps for each collateral to $BOLD.
        SwapLogic.swap(bold, swapAdapter, swapDataWithColl, maxSlippage);

        _checkCollHealth(true);

        uint256 boldAmount;
        for (uint256 i = 0; i < sps.length; i++) {
            // Add $BOLD compounded deposits from each SP
            boldAmount += SpLogic._getBoldAssetsSP(sps[i].sp);
        }

        // Withdraw all assets from current SPs.
        SpLogic.withdrawFromSP(sps, IERC20(bold), decimals(), boldAmount, false);

        // Sanitize
        delete sps;
        // Set new SPs.
        _setSPs(_sps);

        uint256 assetsInternal = ERC20(bold).balanceOf(address(this));
        uint256 deadShareAmount = 10 ** decimals();

        if (assetsInternal > deadShareAmount) {
            // Provide all assets to new SPs.
            SpLogic.provideToSP(sps, assetsInternal - deadShareAmount);
        }

        emit Rebalance(_sps);
    }

    /*//////////////////////////////////////////////////////////////
                                MAXIMUMS
    //////////////////////////////////////////////////////////////*/

    /// @dev Max deposit function returning result from `_maxDeposit`. See {IERC4626-maxDeposit} and {sBold-_maxDeposit}.
    function maxDeposit(address account) public view virtual override nonReentrantReadOnly returns (uint256) {
        return _maxDeposit(account);
    }

    /// @dev Max deposit function returning result from `_maxMint`. See {IERC4626-maxMint} and {sBold-_maxMint}.
    function maxMint(address account) public view virtual override nonReentrantReadOnly returns (uint256) {
        return _maxMint(account);
    }

    /// @dev Max withdraw function returning result from `_maxWithdraw`. See {IERC4626-maxWithdraw} and {sBold-maxWithdraw}.
    function maxWithdraw(address owner) public view virtual override nonReentrantReadOnly returns (uint256) {
        return _maxWithdraw(owner);
    }

    /// @dev Max redeem function returning result from `_maxRedeem`. See {IERC4626-maxRedeem} and {sBold-_maxRedeem}.
    function maxRedeem(address owner) public view virtual override nonReentrantReadOnly returns (uint256) {
        return _maxRedeem(owner);
    }

    /*//////////////////////////////////////////////////////////////
                               PREVIEWS
    //////////////////////////////////////////////////////////////*/

    /// @dev Preview deducting an entry fee on deposit. See {IERC4626-previewDeposit}.
    function previewDeposit(uint256 assets) public view virtual override nonReentrantReadOnly returns (uint256) {
        uint256 fee = _feeOnTotal(assets, feeBps);

        return super.previewDeposit(assets - fee);
    }

    /// @dev Preview adding an entry fee on mint. See {IERC4626-previewMint}.
    function previewMint(uint256 shares) public view virtual override nonReentrantReadOnly returns (uint256) {
        uint256 assets = super.previewMint(shares);

        return assets + _feeOnRaw(assets, feeBps);
    }

    /// @dev Preview withdraw add readOnly reentrancy check. See {IERC4626-previewWithdraw}.
    function previewWithdraw(uint256 assets) public view virtual override nonReentrantReadOnly returns (uint256) {
        return super.previewWithdraw(assets);
    }

    /// @dev Preview redeem add readOnly reentrancy check. See {IERC4626-previewRedeem}.
    function previewRedeem(uint256 shares) public view virtual override nonReentrantReadOnly returns (uint256) {
        return super.previewRedeem(shares);
    }

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

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

    /// @dev Total underlying assets owned by the sBOLD contract which are utilized in stability pools.
    function totalAssets() public view virtual override nonReentrantReadOnly returns (uint256) {
        (uint256 totalBold, , , ) = _calcFragments();

        return totalBold;
    }

    /*//////////////////////////////////////////////////////////////
                                TRANSIENT
    //////////////////////////////////////////////////////////////*/

    /// @inheritdoc BaseSBold
    function _checkAndStoreCollValueInBold() internal virtual override {
        (, uint256 collValue, uint256 collInBold) = _checkCollHealth(true);
        // Transient store for collaterals and flag
        TransientStorage.storeCollValues(collValue, collInBold);
    }

    /*//////////////////////////////////////////////////////////////
                               GETTERS
    //////////////////////////////////////////////////////////////*/

    /// @notice Calculates the $sBOLD:BOLD rate.
    /// @return The $sBOLD:$BOLD rate.
    function getSBoldRate() public view nonReentrantReadOnly returns (uint256) {
        (uint256 totalBold, , , ) = _calcFragments();

        return (totalBold + 1).mulDiv(10 ** decimals(), totalSupply() + 10 ** _decimalsOffset());
    }

    function calcFragments() public view nonReentrantReadOnly returns (uint256, uint256, uint256, uint256) {
        return _calcFragments();
    }

    /// @dev Max deposit returns 0 if collateral is above max, the contract is paused or call to oracle has failed. See {IERC4626-maxDeposit}.
    function _maxDeposit(address account) private view returns (uint256) {
        (bool success, , ) = _checkCollHealth(false);

        if (!success || paused()) return 0;

        return super.maxDeposit(account);
    }

    /// @dev Max mint returns 0 if collateral is above max, the contract is paused or call to oracle has failed. See {IERC4626-maxMint}.
    function _maxMint(address account) private view returns (uint256) {
        (bool success, , ) = _checkCollHealth(false);

        if (!success || paused()) return 0;

        return super.maxMint(account);
    }

    /// @dev Max withdraw returns 0 if collateral is above max. See {IERC4626-maxWithdraw}.
    /// note: Returns an amount up to the one available in $BOLD.
    function _maxWithdraw(address owner) private view returns (uint256) {
        (bool success, , ) = _checkCollHealth(false);

        if (!success || paused()) return 0;

        uint256 maxWithdrawAssets = super.maxWithdraw(owner);

        uint256 boldAmount = SpLogic.getBoldAssets(sps, IERC20(asset()));

        if (maxWithdrawAssets > boldAmount) {
            uint256 deadShareAmount = 10 ** decimals();

            if (boldAmount < deadShareAmount) return 0;

            return boldAmount - deadShareAmount;
        }

        return maxWithdrawAssets;
    }

    /// @dev Max redeem returns 0 if collateral is above max. See {IERC4626-maxRedeem}.
    /// note: Returns an amount up to the one available in $BOLD, converted in shares.
    function _maxRedeem(address owner) private view returns (uint256) {
        (bool success, , ) = _checkCollHealth(false);

        if (!success || paused()) return 0;

        uint256 maxWithdrawAssets = super.maxWithdraw(owner);

        uint256 boldAmount = SpLogic.getBoldAssets(sps, IERC20(asset()));

        if (maxWithdrawAssets > boldAmount) {
            uint256 deadShareAmount = 10 ** decimals();

            if (boldAmount < deadShareAmount) return 0;

            return _convertToShares(boldAmount - deadShareAmount, Math.Rounding.Floor);
        }

        return super.maxRedeem(owner);
    }

    /// @notice Calculates the total value in $BOLD of the assets in the contract.
    /// @return The total value in USD, $BOLD amount and collateral in USD.
    function _calcFragments() private view returns (uint256, uint256, uint256, uint256) {
        address bold = asset();
        // Get compounded $BOLD amount
        uint256 boldAmount = SpLogic.getBoldAssets(sps, IERC20(bold));
        // Get collateral value in USD and $BOLD
        (, uint256 collValue, uint256 collInBold) = _calcCollValue(bold, true);
        // Calculate based on the minimum amount to be received after swap
        uint256 collToBoldMinOut = SwapLogic.calcMinOut(collInBold, maxSlippage);
        // Apply fees after swap
        (uint256 collInBoldNet, , ) = SwapLogic.applyFees(collToBoldMinOut, swapFeeBps, rewardBps);
        // Calculate total $BOLD value
        uint256 totalBold = boldAmount + collInBoldNet;

        return (totalBold, boldAmount, collValue, collInBold);
    }

    /// @notice Converts the $BOLD assets to shares based on $sBOLD exchange rate.
    /// @return The calculated $sBOLD share, based on the total value held.
    function _convertToShares(uint256 assets, Math.Rounding rounding) internal view override returns (uint256) {
        return
            assets.mulDiv(
                10 ** decimals(),
                _getSBoldRateWithRounding(rounding == Math.Rounding.Floor ? Math.Rounding.Ceil : Math.Rounding.Floor),
                rounding
            );
    }

    /// @notice Converts the $sBOLD shares to $BOLD assets based on $sBOLD exchange rate.
    /// @return The calculated $BOLD assets, based on the total value held.
    function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view override returns (uint256) {
        return shares.mulDiv(_getSBoldRateWithRounding(rounding), 10 ** decimals(), rounding);
    }

    /// @notice Calculates the $sBOLD:BOLD rate with input rounding.
    /// @param rounding Type of rounding on math calculations.
    /// @return The $sBOLD:$BOLD rate.
    function _getSBoldRateWithRounding(Math.Rounding rounding) private view returns (uint256) {
        (uint256 totalBold, , , ) = _calcFragments();

        return (totalBold + 1).mulDiv(10 ** decimals(), totalSupply() + 10 ** _decimalsOffset(), rounding);
    }

    /// @dev Calculates the fees that should be added to an amount `assets` that does not already include fees.
    /// Used in {IERC4626-mint} operations.
    function _feeOnRaw(uint256 assets, uint256 feeBasisPoints) internal pure returns (uint256) {
        return assets.mulDiv(feeBasisPoints, Constants.BPS_DENOMINATOR, Math.Rounding.Ceil);
    }

    /// @dev Calculates the fee part of an amount `assets` that already includes fees.
    /// Used in {IERC4626-deposit} operations.
    function _feeOnTotal(uint256 assets, uint256 feeBasisPoints) internal pure returns (uint256) {
        return assets.mulDiv(feeBasisPoints, feeBasisPoints + Constants.BPS_DENOMINATOR, Math.Rounding.Ceil);
    }

    /// @notice Calculates the collateral value in USD and $BOLD from all SPs.
    /// @param _bold Asset contract address.
    /// @param _revert Indication to revert on errors.
    /// @return success Success result from function.
    /// @return collValue The total collateral value.
    /// @return collInBold The collateral value denominated in $BOLD.
    function _calcCollValue(
        address _bold,
        bool _revert
    ) private view returns (bool success, uint256 collValue, uint256 collInBold) {
        // Return values from transient storage
        if (TransientStorage.loadCollsFlag())
            return (true, TransientStorage.loadCollValue(), TransientStorage.loadCollInBold());

        CollBalance[] memory collBalances = SpLogic.getCollBalances(sps, false);

        (success, collValue) = QuoteLogic.getAggregatedQuote(priceOracle, collBalances, _revert);

        if (success)
            try priceOracle.getQuote(10 ** decimals(), _bold) returns (uint256 boldUnitQuote) {
                collInBold = collValue.mulDiv(10 ** Constants.ORACLE_PRICE_PRECISION, boldUnitQuote);
            } catch (bytes memory data) {
                if (_revert) revert(string(data));

                return (false, collValue, 0);
            }
    }

    /*//////////////////////////////////////////////////////////////
                               VALIDATIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Checks if the collateral value in $BOLD is over the maximum allowed.
    function _checkCollHealth(bool _revert) private view returns (bool, uint256, uint256) {
        (bool success, uint256 collValue, uint256 collValueInBold) = _calcCollValue(asset(), _revert);

        if (!success) return (false, 0, 0);

        if (collValueInBold <= maxCollInBold) return (true, collValue, collValueInBold);

        if (_revert) revert CollOverLimit();

        return (false, collValue, collValueInBold);
    }
}

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

pragma solidity ^0.8.20;

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

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

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

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

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

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 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 ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-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 ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 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.1.0) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

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

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

File 5 of 37 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";

File 6 of 37 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 ERC-4626 "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);
}

File 8 of 37 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.20;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 ERC-20
 * applications.
 */
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}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * 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:
     *
     * ```solidity
     * 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.1.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 ERC-4626 "Tokenized Vault Standard" as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 *
 * This extension allows the minting and burning of "shares" (represented using the ERC-20 inheritance) in exchange for
 * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
 * the ERC-20 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 introduces configurable virtual assets and shares to help developers 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 even if an attacker is able to capture value from multiple user deposits, 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 (ERC-20 or ERC-777).
     */
    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 ok, uint8 assetDecimals) {
        (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}. */
    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 ERC-777, `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 ERC-777, `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.1.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 ERC-20 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.1.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC-20 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.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
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.1.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 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 {
    /**
     * @dev An operation with an ERC-20 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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    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 Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            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 silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

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

pragma solidity ^0.8.20;

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

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @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 Errors.InsufficientBalance(address(this).balance, amount);
        }

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

    /**
     * @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
     * {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
        }
        (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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
     */
    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
            assembly ("memory-safe") {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert Errors.FailedCall();
        }
    }
}

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

File 17 of 37 : Errors.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of common custom errors used in multiple contracts
 *
 * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
 * It is recommended to avoid relying on the error API for critical functionality.
 *
 * _Available since v5.1._
 */
library Errors {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error InsufficientBalance(uint256 balance, uint256 needed);

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

    /**
     * @dev The deployment failed.
     */
    error FailedDeployment();

    /**
     * @dev A necessary precompile is missing.
     */
    error MissingPrecompile(address);
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * 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[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

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

pragma solidity ^0.8.20;

import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    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 success flag (no overflow).
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

    /**
     * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        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 success flag (no division by zero).
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

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

    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * SafeCast.toUint(condition));
        }
    }

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

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return ternary(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.
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }

        // The following calculation ensures accurate ceiling division without overflow.
        // Since a is non-zero, (a - 1) / b will not overflow.
        // The largest possible result occurs when (a - 1) / b is type(uint256).max,
        // but the largest value we can obtain is type(uint256).max - 1, which happens
        // when a = type(uint256).max and b = 1.
        unchecked {
            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
        }
    }

    /**
     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     *
     * 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²⁵⁶ and mod 2²⁵⁶ - 1, then use
            // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2²⁵⁶ + 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²⁵⁶. Also prevents denominator == 0.
            if (denominator <= prod1) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

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

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

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

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

            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²⁵⁶ / 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²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
            // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv ≡ 1 mod 2⁴.
            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⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

            // 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²⁵⁶. Since the preconditions guarantee that the outcome is
            // less than 2²⁵⁶, 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;
        }
    }

    /**
     * @dev 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) {
        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
    }

    /**
     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
     *
     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
     *
     * If the input value is not inversible, 0 is returned.
     *
     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
     */
    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
        unchecked {
            if (n == 0) return 0;

            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
            // Used to compute integers x and y such that: ax + ny = gcd(a, n).
            // When the gcd is 1, then the inverse of a modulo n exists and it's x.
            // ax + ny = 1
            // ax = 1 + (-y)n
            // ax ≡ 1 (mod n) # x is the inverse of a modulo n

            // If the remainder is 0 the gcd is n right away.
            uint256 remainder = a % n;
            uint256 gcd = n;

            // Therefore the initial coefficients are:
            // ax + ny = gcd(a, n) = n
            // 0a + 1n = n
            int256 x = 0;
            int256 y = 1;

            while (remainder != 0) {
                uint256 quotient = gcd / remainder;

                (gcd, remainder) = (
                    // The old remainder is the next gcd to try.
                    remainder,
                    // Compute the next remainder.
                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                    // where gcd is at most n (capped to type(uint256).max)
                    gcd - remainder * quotient
                );

                (x, y) = (
                    // Increment the coefficient of a.
                    y,
                    // Decrement the coefficient of n.
                    // Can overflow, but the result is casted to uint256 so that the
                    // next value of y is "wrapped around" to a value between 0 and n - 1.
                    x - y * int256(quotient)
                );
            }

            if (gcd != 1) return 0; // No inverse exists.
            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
        }
    }

    /**
     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
     *
     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
     *
     * NOTE: this function does NOT check that `p` is a prime greater than `2`.
     */
    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
        unchecked {
            return Math.modExp(a, p - 2, p);
        }
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
     *
     * Requirements:
     * - modulus can't be zero
     * - underlying staticcall to precompile must succeed
     *
     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
     * sure the chain you're using it on supports the precompiled contract for modular exponentiation
     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
     * interpreted as 0.
     */
    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
        (bool success, uint256 result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
     * to operate modulo 0 or if the underlying precompile reverted.
     *
     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
     * of a revert, but the result may be incorrectly interpreted as 0.
     */
    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
        if (m == 0) return (false, 0);
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            // | Offset    | Content    | Content (Hex)                                                      |
            // |-----------|------------|--------------------------------------------------------------------|
            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x60:0x7f | value of b | 0x<.............................................................b> |
            // | 0x80:0x9f | value of e | 0x<.............................................................e> |
            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
            mstore(ptr, 0x20)
            mstore(add(ptr, 0x20), 0x20)
            mstore(add(ptr, 0x40), 0x20)
            mstore(add(ptr, 0x60), b)
            mstore(add(ptr, 0x80), e)
            mstore(add(ptr, 0xa0), m)

            // Given the result < m, it's guaranteed to fit in 32 bytes,
            // so we can use the memory scratch space located at offset 0.
            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
            result := mload(0x00)
        }
    }

    /**
     * @dev Variant of {modExp} that supports inputs of arbitrary length.
     */
    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
        (bool success, bytes memory result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
     */
    function tryModExp(
        bytes memory b,
        bytes memory e,
        bytes memory m
    ) internal view returns (bool success, bytes memory result) {
        if (_zeroBytes(m)) return (false, new bytes(0));

        uint256 mLen = m.length;

        // Encode call args in result and move the free memory pointer
        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);

        assembly ("memory-safe") {
            let dataPtr := add(result, 0x20)
            // Write result on top of args to avoid allocating extra memory.
            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
            // Overwrite the length.
            // result.length > returndatasize() is guaranteed because returndatasize() == m.length
            mstore(result, mLen)
            // Set the memory pointer after the returned data.
            mstore(0x40, add(dataPtr, mLen))
        }
    }

    /**
     * @dev Returns whether the provided byte array is zero.
     */
    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
        for (uint256 i = 0; i < byteArray.length; ++i) {
            if (byteArray[i] != 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
     * using integer operations.
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        unchecked {
            // Take care of easy edge cases when a == 0 or a == 1
            if (a <= 1) {
                return a;
            }

            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
            // the current value as `ε_n = | x_n - sqrt(a) |`.
            //
            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
            // bigger than any uint256.
            //
            // By noticing that
            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
            // to the msb function.
            uint256 aa = a;
            uint256 xn = 1;

            if (aa >= (1 << 128)) {
                aa >>= 128;
                xn <<= 64;
            }
            if (aa >= (1 << 64)) {
                aa >>= 64;
                xn <<= 32;
            }
            if (aa >= (1 << 32)) {
                aa >>= 32;
                xn <<= 16;
            }
            if (aa >= (1 << 16)) {
                aa >>= 16;
                xn <<= 8;
            }
            if (aa >= (1 << 8)) {
                aa >>= 8;
                xn <<= 4;
            }
            if (aa >= (1 << 4)) {
                aa >>= 4;
                xn <<= 2;
            }
            if (aa >= (1 << 2)) {
                xn <<= 1;
            }

            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
            //
            // We can refine our estimation by noticing that the middle of that interval minimizes the error.
            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
            // This is going to be our x_0 (and ε_0)
            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)

            // From here, Newton's method give us:
            // x_{n+1} = (x_n + a / x_n) / 2
            //
            // One should note that:
            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
            //              = ((x_n² + a) / (2 * x_n))² - a
            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
            //              = (x_n² - a)² / (2 * x_n)²
            //              = ((x_n² - a) / (2 * x_n))²
            //              ≥ 0
            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
            //
            // This gives us the proof of quadratic convergence of the sequence:
            // ε_{n+1} = | x_{n+1} - sqrt(a) |
            //         = | (x_n + a / x_n) / 2 - sqrt(a) |
            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
            //         = | (x_n - sqrt(a))² / (2 * x_n) |
            //         = | ε_n² / (2 * x_n) |
            //         = ε_n² / | (2 * x_n) |
            //
            // For the first iteration, we have a special case where x_0 is known:
            // ε_1 = ε_0² / | (2 * x_0) |
            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
            //     ≤ 2**(e-3) / 3
            //     ≤ 2**(e-3-log2(3))
            //     ≤ 2**(e-4.5)
            //
            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
            // ε_{n+1} = ε_n² / | (2 * x_n) |
            //         ≤ (2**(e-k))² / (2 * 2**(e-1))
            //         ≤ 2**(2*e-2*k) / 2**e
            //         ≤ 2**(e-2*k)
            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72

            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
            // sqrt(a) or sqrt(a) + 1.
            return xn - SafeCast.toUint(xn > a / xn);
        }
    }

    /**
     * @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

    /**
     * @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;
        uint256 exp;
        unchecked {
            exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
            value >>= exp;
            result += exp;

            exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
            value >>= exp;
            result += exp;

            exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
            value >>= exp;
            result += exp;

            exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
            value >>= exp;
            result += exp;

            exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
            value >>= exp;
            result += exp;

            exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
            value >>= exp;
            result += exp;

            exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
            value >>= exp;
            result += exp;

            result += SafeCast.toUint(value > 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
        }
    }

    /**
     * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
        }
    }

    /**
     * @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;
        uint256 isGt;
        unchecked {
            isGt = SafeCast.toUint(value > (1 << 128) - 1);
            value >>= isGt * 128;
            result += isGt * 16;

            isGt = SafeCast.toUint(value > (1 << 64) - 1);
            value >>= isGt * 64;
            result += isGt * 8;

            isGt = SafeCast.toUint(value > (1 << 32) - 1);
            value >>= isGt * 32;
            result += isGt * 4;

            isGt = SafeCast.toUint(value > (1 << 16) - 1);
            value >>= isGt * 16;
            result += isGt * 2;

            result += SafeCast.toUint(value > (1 << 8) - 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
        }
    }

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

File 20 of 37 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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/bool 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);
    }

    /**
     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
     */
    function toUint(bool b) internal pure returns (uint256 u) {
        assembly ("memory-safe") {
            u := iszero(iszero(b))
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Helper library for emitting standardized panic codes.
 *
 * ```solidity
 * contract Example {
 *      using Panic for uint256;
 *
 *      // Use any of the declared internal constants
 *      function foo() { Panic.GENERIC.panic(); }
 *
 *      // Alternatively
 *      function foo() { Panic.panic(Panic.GENERIC); }
 * }
 * ```
 *
 * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
 *
 * _Available since v5.1._
 */
// slither-disable-next-line unused-state
library Panic {
    /// @dev generic / unspecified error
    uint256 internal constant GENERIC = 0x00;
    /// @dev used by the assert() builtin
    uint256 internal constant ASSERT = 0x01;
    /// @dev arithmetic underflow or overflow
    uint256 internal constant UNDER_OVERFLOW = 0x11;
    /// @dev division or modulo by zero
    uint256 internal constant DIVISION_BY_ZERO = 0x12;
    /// @dev enum conversion error
    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
    /// @dev invalid encoding in storage
    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
    /// @dev empty array pop
    uint256 internal constant EMPTY_ARRAY_POP = 0x31;
    /// @dev array out of bounds access
    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
    /// @dev resource error (too large allocation or too large array)
    uint256 internal constant RESOURCE_ERROR = 0x41;
    /// @dev calling invalid internal function
    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;

    /// @dev Reverts with a panic code. Recommended to use with
    /// the internal constants with predefined codes.
    function panic(uint256 code) internal pure {
        assembly ("memory-safe") {
            mstore(0x00, 0x4e487b71)
            mstore(0x20, code)
            revert(0x1c, 0x24)
        }
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

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

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

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

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

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

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

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

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

pragma solidity ^0.8.24;

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

/**
 * @dev Variant of {ReentrancyGuard} that uses transient storage.
 *
 * NOTE: This variant only works on networks where EIP-1153 is available.
 *
 * _Available since v5.1._
 */
abstract contract ReentrancyGuardTransient {
    using TransientSlot for *;

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant REENTRANCY_GUARD_STORAGE =
        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

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

    /**
     * @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 (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
    }

    function _nonReentrantAfter() private {
        REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
    }

    /**
     * @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 REENTRANCY_GUARD_STORAGE.asBoolean().tload();
    }
}

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

pragma solidity ^0.8.24;

/**
 * @dev Library for reading and writing value-types to specific transient storage slots.
 *
 * Transient slots are often used to store temporary values that are removed after the current transaction.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 *  * Example reading and writing values using transient storage:
 * ```solidity
 * contract Lock {
 *     using TransientSlot for *;
 *
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
 *
 *     modifier locked() {
 *         require(!_LOCK_SLOT.asBoolean().tload());
 *
 *         _LOCK_SLOT.asBoolean().tstore(true);
 *         _;
 *         _LOCK_SLOT.asBoolean().tstore(false);
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library TransientSlot {
    /**
     * @dev UDVT that represent a slot holding a address.
     */
    type AddressSlot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a AddressSlot.
     */
    function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
        return AddressSlot.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a bool.
     */
    type BooleanSlot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a BooleanSlot.
     */
    function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
        return BooleanSlot.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a bytes32.
     */
    type Bytes32Slot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Bytes32Slot.
     */
    function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
        return Bytes32Slot.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a uint256.
     */
    type Uint256Slot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Uint256Slot.
     */
    function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
        return Uint256Slot.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a int256.
     */
    type Int256Slot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Int256Slot.
     */
    function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
        return Int256Slot.wrap(slot);
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(AddressSlot slot) internal view returns (address value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(AddressSlot slot, address value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(BooleanSlot slot) internal view returns (bool value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(BooleanSlot slot, bool value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Bytes32Slot slot, bytes32 value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Uint256Slot slot) internal view returns (uint256 value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Uint256Slot slot, uint256 value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Int256Slot slot) internal view returns (int256 value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Int256Slot slot, int256 value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }
}

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

import {ERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {ReentrancyGuardTransient} from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import {IStabilityPool} from "../external/IStabilityPool.sol";
import {IPriceOracle} from "../interfaces/IPriceOracle.sol";
import {ISBold} from "../interfaces/ISBold.sol";
import {ICommon} from "../interfaces/ICommon.sol";
import {Constants} from "../libraries/helpers/Constants.sol";
import {Common} from "../libraries/Common.sol";
import {TransientStorage} from "../libraries/helpers/TransientStorage.sol";

/// @title sBold Protocol
/// @notice The $sBOLD represents an ERC4626 yield-bearing token.
abstract contract BaseSBold is ISBold, ICommon, ERC4626, ReentrancyGuardTransient, Pausable, Ownable {
    /// @notice Data for stability pools.
    SP[] public sps;
    /// @notice The fee in basis points.
    uint256 public feeBps;
    /// @notice The fee applied over the swap in basis points.
    uint256 public swapFeeBps;
    /// @notice The reward for the `caller` applied over the swap in basis points.
    uint256 public rewardBps;
    /// @notice The maximum slippage tolerance on swap in basis points.
    uint256 public maxSlippage;
    /// @notice The maximum Coll value aggregated and owned.
    uint256 public maxCollInBold;
    /// @notice Price oracle instance.
    IPriceOracle public priceOracle;
    /// @notice Swap adapter instance.
    address public swapAdapter;
    /// @notice An address to which a fee amount in $BOLD is transferred.
    address public vault;

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

    /// @notice Deploys sBold.
    /// @param _sps The Stability Pools memory array.
    /// @param _priceOracle The address of the price oracle adapter.
    /// @param _vault The address of the vault for fee transfers.
    constructor(SPConfig[] memory _sps, address _priceOracle, address _vault) Ownable(_msgSender()) {
        _setSPs(_sps);
        priceOracle = IPriceOracle(_priceOracle);
        vault = _vault;
    }

    /// @dev Stores and loads collateral in $BOLD value in transient storage.
    /// Operates with three values, the collateral in USD, in $BOLD and a flag.
    modifier execCollateralOps() {
        _checkAndStoreCollValueInBold();
        _;
        TransientStorage.switchOffCollInBoldFlag();
    }

    /// @dev Check for reentrancy on read functions.
    modifier nonReentrantReadOnly() {
        if (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }
        _;
    }

    /*//////////////////////////////////////////////////////////////
                               SETTERS
    //////////////////////////////////////////////////////////////*/

    /// @notice Sets `priceOracle` address which will be used for price derivation.
    /// @param _priceOracle The address of the price oracle.
    function setPriceOracle(address _priceOracle) external onlyOwner {
        Common.revertZeroAddress(_priceOracle);

        priceOracle = IPriceOracle(_priceOracle);

        emit PriceOracleSet(_priceOracle);
    }

    /// @notice Sets `vault` address to which fees will be transferred.
    /// @param _vault The address of the vault.
    function setVault(address _vault) external onlyOwner {
        Common.revertZeroAddress(_vault);
        if (_vault == asset() || _vault == address(this)) revert InvalidAddress();

        vault = _vault;

        emit VaultSet(_vault);
    }

    /// @notice Sets the fee in BPS.
    /// @param _feeBps The fee in BPS.
    /// @param _swapFeeBps The swap fee in BPS.
    function setFees(uint256 _feeBps, uint256 _swapFeeBps) external onlyOwner {
        if (_feeBps > Constants.BPS_MAX_DEPOSIT_FEE || _swapFeeBps > Constants.BPS_MAX_FEE)
            revert InvalidConfiguration();

        feeBps = _feeBps;
        swapFeeBps = _swapFeeBps;

        emit FeesSet(_feeBps, _swapFeeBps);
    }

    /// @notice Sets the reward in BPS.
    /// @param _rewardBps The reward in BPS.
    function setReward(uint256 _rewardBps) external onlyOwner {
        if (_rewardBps > Constants.BPS_MAX_REWARD) revert InvalidConfiguration();

        rewardBps = _rewardBps;

        emit RewardSet(_rewardBps);
    }

    /// @notice Sets the maximum slippage tolerance in BPS.
    /// @param _maxSlippage The maximum slippage tolerance in BPS.
    function setMaxSlippage(uint256 _maxSlippage) external onlyOwner {
        if (_maxSlippage > Constants.BPS_MAX_SLIPPAGE) revert InvalidConfiguration();

        maxSlippage = _maxSlippage;

        emit MaxSlippageSet(_maxSlippage);
    }

    /// @notice Sets the swap adapter address.
    /// @param _swapAdapter The swap adapter address.
    function setSwapAdapter(address _swapAdapter) external onlyOwner {
        Common.revertZeroAddress(_swapAdapter);
        if (_swapAdapter == asset()) revert InvalidAddress();
        for (uint256 i = 0; i < sps.length; i++) {
            if (_swapAdapter == sps[i].sp || _swapAdapter == sps[i].coll) revert InvalidAddress();
        }

        swapAdapter = _swapAdapter;

        emit SwapAdapterSet(_swapAdapter);
    }

    /// @notice Sets the maximum Coll value aggregated and owned.
    /// @param _maxCollInBold The maximum Coll value.
    function setMaxCollInBold(uint256 _maxCollInBold) external onlyOwner {
        if (_maxCollInBold == 0 || _maxCollInBold > Constants.MAX_COLL_IN_BOLD_UPPER_BOUND) {
            revert InvalidConfiguration();
        }

        maxCollInBold = _maxCollInBold;

        emit MaxCollValueSet(_maxCollInBold);
    }

    /*//////////////////////////////////////////////////////////////
                                PAUSE
    //////////////////////////////////////////////////////////////*/

    /// @notice Pauses contract.
    function pause() external onlyOwner {
        _pause();
    }

    /// @notice Unpauses contract.
    function unpause() external onlyOwner {
        _unpause();
    }

    /*//////////////////////////////////////////////////////////////
                                INTERNAL
    //////////////////////////////////////////////////////////////*/

    /// @notice Sets Stability Pools and Coll assets structures.
    /// The total weight of all Stability Pools should be equal to `BPS_DENOMINATOR`.
    /// Each Stability Pool Coll is derived from the pools themselves.
    /// The decimal precision for each Coll is dynamically extracted.
    /// @param _sps Address and weight of Stability Pools.
    function _setSPs(SPConfig[] memory _sps) internal {
        if (_sps.length == 0) revert InvalidSPLength();

        uint256 totalWeight;
        for (uint256 i = 0; i < _sps.length; i++) {
            address spAddress = _sps[i].addr;
            uint96 weight = _sps[i].weight;

            // Verify input
            Common.revertZeroAddress(spAddress);
            if (weight == 0) revert ZeroWeight();
            for (uint256 j = 0; j < _sps.length; j++) {
                if (i != j && spAddress == _sps[j].addr) {
                    revert DuplicateAddress();
                }
            }

            // Update Storage related to SP
            sps.push(SP({sp: spAddress, weight: weight, coll: address(IStabilityPool(spAddress).collToken())}));

            totalWeight += weight;
        }

        if (totalWeight != Constants.BPS_DENOMINATOR) revert InvalidTotalWeight();
    }

    /// @notice Check and store collateral value in $BOLD if transient storage load is not enabled.
    function _checkAndStoreCollValueInBold() internal virtual {}
}

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

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {IERC5267} from "@openzeppelin/contracts/interfaces/IERC5267.sol";

interface IBoldToken is IERC20Metadata, IERC20Permit, IERC5267 {
    function setBranchAddresses(
        address _troveManagerAddress,
        address _stabilityPoolAddress,
        address _borrowerOperationsAddress,
        address _activePoolAddress
    ) external;

    function setCollateralRegistry(address _collateralRegistryAddress) external;

    function mint(address _account, uint256 _amount) external;

    function burn(address _account, uint256 _amount) external;

    function sendToPool(address _sender, address poolAddress, uint256 _amount) external;

    function returnFromPool(address poolAddress, address user, uint256 _amount) external;
}

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

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

/*
 * The Stability Pool holds Bold tokens deposited by Stability Pool depositors.
 *
 * When a trove is liquidated, then depending on system conditions, some of its Bold debt gets offset with
 * Bold in the Stability Pool:  that is, the offset debt evaporates, and an equal amount of Bold tokens in the Stability Pool is burned.
 *
 * Thus, a liquidation causes each depositor to receive a Bold loss, in proportion to their deposit as a share of total deposits.
 * They also receive an Coll gain, as the collateral of the liquidated trove is distributed among Stability depositors,
 * in the same proportion.
 *
 * When a liquidation occurs, it depletes every deposit by the same fraction: for example, a liquidation that depletes 40%
 * of the total Bold in the Stability Pool, depletes 40% of each deposit.
 *
 * A deposit that has experienced a series of liquidations is termed a "compounded deposit": each liquidation depletes the deposit,
 * multiplying it by some factor in range ]0,1[
 *
 * Please see the implementation spec in the proof document, which closely follows on from the compounded deposit / Coll gain derivations:
 * https://github.com/liquity/liquity/blob/master/papers/Scalable_Reward_Distribution_with_Compounding_Stakes.pdf
 *
 */
interface IStabilityPool {
    function collToken() external view returns (IERC20);

    function boldToken() external view returns (IBoldToken);

    /*  provideToSP():
     * - Calculates depositor's Coll gain
     * - Calculates the compounded deposit
     * - Increases deposit, and takes new snapshots of accumulators P and S
     * - Sends depositor's accumulated Coll gains to depositor
     */
    function provideToSP(uint256 _amount, bool _doClaim) external;

    /*  withdrawFromSP():
     * - Calculates depositor's Coll gain
     * - Calculates the compounded deposit
     * - Sends the requested BOLD withdrawal to depositor
     * - (If _amount > userDeposit, the user withdraws all of their compounded deposit)
     * - Decreases deposit by withdrawn amount and takes new snapshots of accumulators P and S
     */
    function withdrawFromSP(uint256 _amount, bool doClaim) external;

    /*
     * Initial checks:
     * - Caller is TroveManager
     * ---
     * Cancels out the specified debt against the Bold contained in the Stability Pool (as far as possible)
     * and transfers the Trove's collateral from ActivePool to StabilityPool.
     * Only called by liquidation functions in the TroveManager.
     */
    function offset(uint256 _debt, uint256 _coll) external;

    function deposits(address _depositor) external view returns (uint256 initialValue);

    function stashedColl(address _depositor) external view returns (uint256);

    /*
     * Returns the total amount of Coll held by the pool, accounted in an internal variable instead of `balance`,
     * to exclude edge cases like Coll received from a self-destruct.
     */
    function getCollBalance() external view returns (uint256);

    /*
     * Returns Bold held in the pool. Changes when users deposit/withdraw, and when Trove debt is offset.
     */
    function getTotalBoldDeposits() external view returns (uint256);

    function getYieldGainsOwed() external view returns (uint256);

    /*
     * Calculates the Coll gain earned by the deposit since its last snapshots were taken.
     */
    function getDepositorCollGain(address _depositor) external view returns (uint256);

    /*
     * Calculates the BOLD yield gain earned by the deposit since its last snapshots were taken.
     */
    function getDepositorYieldGain(address _depositor) external view returns (uint256);

    /*
     * Calculates what `getDepositorYieldGain` will be if interest is minted now.
     */
    function getDepositorYieldGainWithPending(address _depositor) external view returns (uint256);

    /*
     * Return the user's compounded deposit.
     */
    function getCompoundedBoldDeposit(address _depositor) external view returns (uint256);

    function epochToScaleToS(uint128 _epoch, uint128 _scale) external view returns (uint256);

    function epochToScaleToB(uint128 _epoch, uint128 _scale) external view returns (uint256);

    function P() external view returns (uint256);

    function currentScale() external view returns (uint128);

    function currentEpoch() external view returns (uint128);
}

File 28 of 37 : ICommon.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title IPriceOracle

/// @notice PriceOracle interface.
interface ICommon {
    /*//////////////////////////////////////////////////////////////
                                 ERRORS
    //////////////////////////////////////////////////////////////*/

    error InvalidAddress();
}

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

/// @title IPriceOracle
/// @notice PriceOracle interface.
interface IPriceOracle {
    /*//////////////////////////////////////////////////////////////
                                 ERRORS
    //////////////////////////////////////////////////////////////*/

    error InvalidMaxStalenessUpperBound();

    error InvalidMaxStaleness();

    error InvalidMaxConfWidthLowerBound();

    error InvalidFeed();

    error InvalidBaseDecimals();

    error TooStalePrice();

    error TooAheadPrice();

    error InvalidPrice();

    error InvalidPriceExponent();

    error DuplicateFeed();

    /*//////////////////////////////////////////////////////////////
                                 FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Check if the `base` token is supported.
    /// @param base The token that is being priced.
    /// @return The boolean if the token is supported.
    function isBaseSupported(address base) external view returns (bool);

    /// @notice Fetch the latest price and transform it to a quote.
    /// @param inAmount The amount of `base` to convert.
    /// @return outAmount The amount of `quote` that is equivalent to `inAmount` of `base`.
    function getQuote(uint256 inAmount, address base) external view returns (uint256 outAmount);
}

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

interface ISBold {
    /*//////////////////////////////////////////////////////////////
                                STRUCTS
    //////////////////////////////////////////////////////////////*/

    struct SPConfig {
        address addr;
        uint96 weight;
    }

    struct SP {
        address sp;
        uint96 weight;
        address coll;
    }

    struct CollBalance {
        address addr;
        uint256 balance;
    }

    struct SwapDataWithColl {
        address addr;
        uint256 balance;
        uint256 collInBold;
        bytes data;
    }

    struct SwapData {
        address sp;
        uint256 balance;
        bytes data;
    }

    /*//////////////////////////////////////////////////////////////
                                 ERRORS
    //////////////////////////////////////////////////////////////*/

    error InvalidConfiguration();

    error ExecutionFailed(bytes data);

    error CollOverLimit();

    error InsufficientAmount(uint256 amountOut);

    error InvalidDataArray();

    error InvalidSPLength();

    error ZeroWeight();

    error InvalidTotalWeight();

    error DuplicateAddress();

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

    event PriceOracleSet(address addr);

    event VaultSet(address account);

    event FeesSet(uint256 feeBps, uint256 swapFeeBps);

    event MaxCollValueSet(uint256 value);

    event SwapAdapterSet(address addr);

    event RewardSet(uint256 value);

    event MaxSlippageSet(uint256 value);

    event Swap(
        address indexed adapter,
        address indexed src,
        address indexed dst,
        uint256 amountIn,
        uint256 amountOut,
        uint256 minOut
    );

    event Rebalance(SPConfig[] _sps);

    /*//////////////////////////////////////////////////////////////
                                 FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    function setPriceOracle(address _priceOracle) external;

    function setVault(address _vault) external;
}

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

import {ICommon} from "../interfaces/ICommon.sol";

library Common {
    function revertZeroAddress(address _address) internal pure {
        if (_address == address(0)) revert ICommon.InvalidAddress();
    }
}

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

/// @title Constants
/// @notice Presents common constants.
library Constants {
    /// @notice The maximum value in BPS.
    uint256 internal constant BPS_DENOMINATOR = 10_000;
    /// @notice The maximum fee on deposit in BPS.
    uint256 internal constant BPS_MAX_DEPOSIT_FEE = 500;
    /// @notice The maximum fee in BPS.
    uint256 internal constant BPS_MAX_FEE = 250;
    /// @notice The minimum reward in BPS.
    uint256 internal constant BPS_MAX_REWARD = 250;
    /// @notice The upper boundary for maximum slippage tolerance in BPS.
    uint256 internal constant BPS_MAX_SLIPPAGE = 500;
    /// @notice The upper boundary for maximum collateral denominated in $BOLD.
    uint256 internal constant MAX_COLL_IN_BOLD_UPPER_BOUND = 1_000_000e18;
    /// @notice The price precision returned from oracle.
    uint256 internal constant ORACLE_PRICE_PRECISION = 18;
}

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

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

/// @title Decimals
/// @notice Utility library for deriving decimals from assets.
library Decimals {
    /// @dev Returns decimals for asset on success. Defaults to 18 in case the attempt failed in some way.
    function getDecimals(address asset) internal view returns (uint8) {
        (bool success, uint8 decimals) = tryGetDecimals(asset);

        return success ? decimals : 18;
    }

    /// @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
    function tryGetDecimals(address asset) internal view returns (bool, uint8) {
        (bool success, bytes memory encodedDecimals) = 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);
    }
}

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

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

/// @title Transient storage
/// @notice Library for loading and storing data in transient storage.
library TransientStorage {
    using TransientSlot for *;

    // keccak256(abi.encode(uint256(keccak256("sBold.collateralInBold")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 internal constant COLLATERAL_IN_BOLD_STORAGE =
        0x93de9a8576a62ce59fcb637d8053d0e5fadcf7d26694489a7981d83007528a00;
    // keccak256(abi.encode(uint256(keccak256("sBold.collateralValue")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 internal constant COLLATERAL_VALUE_STORAGE =
        0xb9119c9d507ab94e0f4429b4c7bbf0463ef7a3523c74e225b6641cfb04e67a00;
    // keccak256(abi.encode(uint256(keccak256("sBold.collateralInBoldFlag")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 internal constant COLLATERALS_FLAG_STORAGE =
        0x7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df5706900;

    /// @dev Stores the collateral values in transient storage.
    /// @param collValue The collateral in USD value to be stored.
    /// @param collInBold The collateral in $BOLD value to be stored.
    function storeCollValues(uint256 collValue, uint256 collInBold) internal {
        // Transient store for collateral in $BOLD flag
        COLLATERALS_FLAG_STORAGE.asBoolean().tstore(true);
        // Transient store for collateral in USD
        COLLATERAL_VALUE_STORAGE.asUint256().tstore(collValue);
        // Transient store for collateral in $BOLD
        COLLATERAL_IN_BOLD_STORAGE.asUint256().tstore(collInBold);
    }

    /// @dev Clears the collateral in $BOLD value from transient storage.
    function switchOffCollInBoldFlag() internal {
        COLLATERALS_FLAG_STORAGE.asBoolean().tstore(false);
    }

    /// @dev Loads the collaterals flag from transient storage.
    /// @return The boolean flag.
    function loadCollsFlag() internal view returns (bool) {
        return COLLATERALS_FLAG_STORAGE.asBoolean().tload();
    }

    /// @dev Loads the collateral in $BOLD value from transient storage.
    /// @return The value.
    function loadCollInBold() internal view returns (uint256) {
        return COLLATERAL_IN_BOLD_STORAGE.asUint256().tload();
    }

    /// @dev Loads the collateral in USD value from transient storage.
    /// @return The value.
    function loadCollValue() internal view returns (uint256) {
        return COLLATERAL_VALUE_STORAGE.asUint256().tload();
    }
}

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

import {ISBold} from "../../interfaces/ISBold.sol";
import {IPriceOracle} from "../../interfaces/IPriceOracle.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Constants} from "../helpers/Constants.sol";

/// @title QuoteLogic
/// @notice Logic for quotes derivation.
library QuoteLogic {
    using Math for uint256;

    /// @param oracle The oracle to use for getting the quote.
    /// @param balances The collateral balance structs.
    /// @param _revert If the getQuote should revert or not.
    /// @return success The success result of this function.
    /// @return amount The aggregated amount of collateral in USD.
    function getAggregatedQuote(
        IPriceOracle oracle,
        ISBold.CollBalance[] memory balances,
        bool _revert
    ) internal view returns (bool success, uint256 amount) {
        for (uint256 i = 0; i < balances.length; i++) {
            if (balances[i].balance == 0) continue;

            try oracle.getQuote(balances[i].balance, balances[i].addr) returns (uint256 amount_) {
                amount += amount_;
            } catch (bytes memory data) {
                if (_revert) revert(string(data));

                return (false, amount);
            }
        }

        return (true, amount);
    }

    /// @param oracle The oracle to use for getting the quote.
    /// @param bold The address of $BOLD.
    /// @param coll The address of the collateral.
    /// @param balance The balance to return quote for.
    /// @return amount The quote amount of collateral in $BOLD.
    function getInBoldQuote(
        IPriceOracle oracle,
        address bold,
        address coll,
        uint256 balance,
        uint8 decimals
    ) internal view returns (uint256) {
        // Get collateral value in USD
        uint256 collQuote = oracle.getQuote(balance, coll);
        // Get $BOLD value in USD
        uint256 boldUnitQuote = oracle.getQuote(10 ** decimals, bold);
        // Calculate 1 $BOLD * `n` collateral
        return collQuote.mulDiv(10 ** Constants.ORACLE_PRICE_PRECISION, boldUnitQuote);
    }
}

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

import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IStabilityPool} from "../../external/IStabilityPool.sol";
import {ISBold} from "../../interfaces/ISBold.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Constants} from "../../libraries/helpers/Constants.sol";

/// @title SpLogic
/// @notice Manages liquidity in Stability Pools.
library SpLogic {
    using Math for uint256;

    /// @notice Provides $BOLD to SPs, based on the weight of each pool.
    /// @param sps The SPs to provide $BOLD to.
    /// @param assets The $BOLD amount.
    function provideToSP(ISBold.SP[] memory sps, uint256 assets) internal {
        for (uint256 i = 0; i < sps.length; i++) {
            ISBold.SP memory sp = sps[i];
            // Calculate amount for SP, based on the specified weight
            uint256 amount = assets.mulDiv(sp.weight, Constants.BPS_DENOMINATOR);
            if (amount > 0) {
                // Provide amount to SP (accumulated gains are not transferred).
                IStabilityPool(sp.sp).provideToSP(amount, false);
            }
        }
    }

    /// @notice Withdraws $BOLD from SPs.
    /// @param sps The SPs to withdraw $BOLD from.
    /// @param bold The $BOLD instance.
    /// @param decimals The $BOLD decimals.
    /// @param assets The $BOLD assets.
    /// @param shouldProvide Should the withdraw provide leftover assets to current pools
    function withdrawFromSP(
        ISBold.SP[] memory sps,
        IERC20 bold,
        uint8 decimals,
        uint256 assets,
        bool shouldProvide
    ) internal {
        for (uint256 i = 0; i < sps.length; i++) {
            IStabilityPool sp = IStabilityPool(sps[i].sp);
            // Get compounded $BOLD amount from SP
            uint256 amountCompoundedFromSp = sp.getCompoundedBoldDeposit(address(this));
            // Get pending yield gain in $BOLD amount from SP
            uint256 amountPendingFromSp = sp.getDepositorYieldGainWithPending(address(this));

            if (amountCompoundedFromSp == 0 && amountPendingFromSp == 0) continue;
            // Withdraw amount from SP (accumulated gains are transferred).
            sp.withdrawFromSP(amountCompoundedFromSp, true);
        }

        uint256 balanceAfter = bold.balanceOf(address(this));
        uint256 balanceToProvide = balanceAfter - assets;
        uint256 deadShare = 10 ** decimals;

        if (balanceToProvide > deadShare) {
            // Provide the accumulated asset amount back to SPs.
            if (shouldProvide) provideToSP(sps, balanceToProvide - deadShare);
        }
    }

    /// @notice Aggregates $BOLD assets from each pool and returns the total holdings.
    /// @param sps The SPs to get $BOLD from.
    /// @param bold The $BOLD address.
    /// @return amount The aggregated compounded $BOLD deposits.
    function getBoldAssets(ISBold.SP[] memory sps, IERC20 bold) internal view returns (uint256 amount) {
        for (uint256 i = 0; i < sps.length; i++) {
            // Add $BOLD compounded deposits from each SP
            amount += _getBoldAssetsSP(sps[i].sp);
        }
        // Add $BOLD internal balance
        amount += bold.balanceOf(address(this));
    }

    /// @notice Aggregates collateral assets from each pool and returns an array with collateral assets structures.
    /// @param sps The SPs to get collateral from.
    /// @param onlyInternal The flag used to aggregate only internal balances.
    /// @return collBalances The aggregated collateral structs containing address and balance.
    function getCollBalances(
        ISBold.SP[] memory sps,
        bool onlyInternal
    ) internal view returns (ISBold.CollBalance[] memory collBalances) {
        collBalances = new ISBold.CollBalance[](sps.length);

        for (uint256 i = 0; i < sps.length; i++) {
            collBalances[i] = _getCollBalanceSP(sps[i], onlyInternal);
        }
    }

    /// @notice Returns $BOLD assets from SP.
    /// @param _sp The SP address.
    /// @return The aggregated compounded $BOLD deposit from SP.
    function _getBoldAssetsSP(address _sp) internal view returns (uint256) {
        IStabilityPool sp = IStabilityPool(_sp);
        // Accounted yield gains from deposits
        uint256 compoundedBold = sp.getCompoundedBoldDeposit(address(this));
        // Pending yield gains from deposits
        uint256 pendingYield = sp.getDepositorYieldGainWithPending(address(this));

        return compoundedBold + pendingYield;
    }

    /// @notice Returns collateral assets structure from SP.
    /// @param _sp The SP address.
    /// @param _onlyInternal The flag used to aggregate only internal balances.
    /// @return collBalance The collateral struct containing address and balance from SP.
    function _getCollBalanceSP(
        ISBold.SP memory _sp,
        bool _onlyInternal
    ) internal view returns (ISBold.CollBalance memory) {
        // Get collateral balance in contract
        uint256 collInternal = IERC20(_sp.coll).balanceOf(address(this));
        // Return only internal collateral holdings
        if (_onlyInternal) return ISBold.CollBalance({addr: _sp.coll, balance: collInternal});
        // Get collateral accumulated amounts
        uint256 collAccumulatedGains = IStabilityPool(_sp.sp).getDepositorCollGain(address(this));
        // Get collateral accumulated stashed amounts
        uint256 collAccumulatedStashedGains = IStabilityPool(_sp.sp).stashedColl(address(this));
        // Calculate total amount
        uint256 totalBalance = collAccumulatedGains + collAccumulatedStashedGains + collInternal;

        return ISBold.CollBalance({addr: _sp.coll, balance: totalBalance});
    }
}

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

import {ERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ISBold} from "../../interfaces/ISBold.sol";
import {IPriceOracle} from "../../interfaces/IPriceOracle.sol";
import {IStabilityPool} from "../../external/IStabilityPool.sol";
import {Constants} from "../../libraries/helpers/Constants.sol";
import {Decimals} from "../../libraries/helpers/Decimals.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {QuoteLogic} from "./QuoteLogic.sol";
import {SpLogic} from "./SpLogic.sol";

/// @title SwapLogic
/// @notice Logic for swap execution.
library SwapLogic {
    using Math for uint256;

    /// @notice Swaps each SP collateral for $BOLD and returns total swapped amount.
    /// @param dst The unit in which the `src` is swapped.
    /// @param adapter The adapter to use to execute swap
    /// @param swapData The swap data.
    /// @param maxSlippage The minimum amount to receive after the swap.
    /// @return amount The quote amount with subtracted fees.
    function swap(
        address dst,
        address adapter,
        ISBold.SwapDataWithColl[] memory swapData,
        uint256 maxSlippage
    ) internal returns (uint256 amount) {
        // Execute swap for each Coll
        for (uint256 i = 0; i < swapData.length; i++) {
            if (swapData[i].balance == 0) continue;
            // Calculate minimum amount out in $BOLD
            uint256 minOut = calcMinOut(swapData[i].collInBold, maxSlippage);
            // Swap `src` for `bold`
            uint256 amountOut = _execute(adapter, swapData[i].addr, dst, swapData[i].balance, minOut, swapData[i].data);
            // Aggregate total amount of $BOLD received after swap
            amount += amountOut;
            // Emit on each swap
            emit ISBold.Swap(adapter, swapData[i].addr, dst, swapData[i].balance, amountOut, minOut);
        }
    }

    /// @notice Prepare swap data and claim collateral from protocol for each provided SP.
    /// @param bold Address of the underlying asset of the protocol.
    /// @param priceOracle Address of the price oracle.
    /// @param sps The available SPs within the protocol.
    /// @param swapData Input data for swap.
    /// @return swapDataWithColl Prepared data for swap.
    function prepareSwap(
        address bold,
        IPriceOracle priceOracle,
        ISBold.SP[] memory sps,
        ISBold.SwapData[] memory swapData
    ) internal returns (ISBold.SwapDataWithColl[] memory swapDataWithColl) {
        if (swapData.length > sps.length || swapData.length == 0) {
            revert ISBold.InvalidDataArray();
        }

        swapDataWithColl = new ISBold.SwapDataWithColl[](swapData.length);

        // Cycle through the input list of SP data for swap and find matching available SPs in protocol.
        for (uint256 i = 0; i < swapData.length; i++) {
            for (uint256 j = 0; j < sps.length; j++) {
                if (sps[j].sp == swapData[i].sp) {
                    // Claim collateral.
                    IStabilityPool(sps[j].sp).withdrawFromSP(0, true);

                    // If the input balance is not equal to the maximum claimed from SPs, the collateral will stay idle in this contract,
                    // until next swap utilizes the funds.
                    uint256 currentBalance = SpLogic._getCollBalanceSP(sps[j], true).balance;
                    uint256 balance = currentBalance < swapData[i].balance ? currentBalance : swapData[i].balance;

                    // Get collateral in $BOLD.
                    uint256 collInBold = QuoteLogic.getInBoldQuote(
                        priceOracle,
                        bold,
                        sps[j].coll,
                        balance,
                        ERC20(bold).decimals()
                    );
                    // Prepare data for swap by including details regarding collateral.
                    swapDataWithColl[i] = ISBold.SwapDataWithColl({
                        addr: sps[j].coll,
                        balance: balance,
                        collInBold: collInBold,
                        data: swapData[i].data
                    });
                }
            }

            // Revert if input SP address is not matching one of current SPs.
            if (swapDataWithColl[i].addr == address(0)) revert ISBold.InvalidDataArray();
        }
    }

    /// @notice Calculates minimum amount to be returned, based on the maximum slippage set.
    /// @param amount The amount to be swapped.
    /// @param maxSlippage The maximum slippage tolerance on swap in basis points.
    /// @return amount The amount returned by swap adapter after fees.
    function calcMinOut(uint256 amount, uint256 maxSlippage) internal pure returns (uint256) {
        return amount - amount.mulDiv(maxSlippage, Constants.BPS_DENOMINATOR);
    }

    /// @notice Deducts swap fee in BPS and reward for `caller` in BPS.
    /// @param amountOut The amount returned by swap adapter before fees.
    /// @param swapFeeBps The fee applied over the swap in basis points.
    /// @param rewardBps The reward for the `caller` applied over the swap in basis points.
    function applyFees(
        uint256 amountOut,
        uint256 swapFeeBps,
        uint256 rewardBps
    ) internal pure returns (uint256, uint256, uint256) {
        uint256 fee = amountOut.mulDiv(swapFeeBps, Constants.BPS_DENOMINATOR);
        uint256 reward = amountOut.mulDiv(rewardBps, Constants.BPS_DENOMINATOR);
        return (amountOut - fee - reward, fee, reward);
    }

    /// @notice Executes `call()` to swap `inAmount` of `src` token to `dst`.
    /// @param _src The unit that is swapped.
    /// @param _dst The unit in which the `src` is swapped.
    /// @param _inAmount The amount of `base` to be swapped.
    /// @param _minOut The minimum amount to receive after the swap.
    /// @param _swapData The swap data for 1inch router.
    function _execute(
        address _adapter,
        address _src,
        address _dst,
        uint256 _inAmount,
        uint256 _minOut,
        bytes memory _swapData
    ) private returns (uint256) {
        IERC20 dst = IERC20(_dst);
        // Get balance before the swap
        uint256 balance0 = dst.balanceOf(address(this));
        // Approve `_inAmount` for `adapter`
        IERC20(_src).approve(_adapter, _inAmount);
        // Execute swap
        (bool success, bytes memory data) = _adapter.call(_swapData);
        // Revert on failed swap
        if (!success) revert ISBold.ExecutionFailed(data);
        // Get balance after the swap
        uint256 balance1 = dst.balanceOf(address(this));
        // Get the amount received
        uint256 amountOut = balance1 - balance0;
        // Check if the amount received is equal or higher to the minimum
        if (amountOut < _minOut) revert ISBold.InsufficientAmount(amountOut);
        // Return decoded data
        return amountOut;
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint96","name":"weight","type":"uint96"}],"internalType":"struct ISBold.SPConfig[]","name":"_sps","type":"tuple[]"},{"internalType":"address","name":"_priceOracle","type":"address"},{"internalType":"address","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CollOverLimit","type":"error"},{"inputs":[],"name":"DuplicateAddress","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":"EnforcedPause","type":"error"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"ExecutionFailed","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"InsufficientAmount","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidConfiguration","type":"error"},{"inputs":[],"name":"InvalidDataArray","type":"error"},{"inputs":[],"name":"InvalidSPLength","type":"error"},{"inputs":[],"name":"InvalidTotalWeight","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"ZeroWeight","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"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":"feeBps","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"swapFeeBps","type":"uint256"}],"name":"FeesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"MaxCollValueSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"MaxSlippageSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"PriceOracleSet","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint96","name":"weight","type":"uint96"}],"indexed":false,"internalType":"struct ISBold.SPConfig[]","name":"_sps","type":"tuple[]"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"RewardSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"},{"indexed":true,"internalType":"address","name":"src","type":"address"},{"indexed":true,"internalType":"address","name":"dst","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minOut","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"SwapAdapterSet","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":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"VaultSet","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":[{"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":[],"name":"calcFragments","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"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":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSBoldRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxCollInBold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","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":[],"name":"maxSlippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":[],"name":"priceOracle","outputs":[{"internalType":"contract IPriceOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint96","name":"weight","type":"uint96"}],"internalType":"struct ISBold.SPConfig[]","name":"_sps","type":"tuple[]"},{"components":[{"internalType":"address","name":"sp","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct ISBold.SwapData[]","name":"_swapData","type":"tuple[]"}],"name":"rebalanceSPs","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":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feeBps","type":"uint256"},{"internalType":"uint256","name":"_swapFeeBps","type":"uint256"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxCollInBold","type":"uint256"}],"name":"setMaxCollInBold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxSlippage","type":"uint256"}],"name":"setMaxSlippage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_priceOracle","type":"address"}],"name":"setPriceOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardBps","type":"uint256"}],"name":"setReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapAdapter","type":"address"}],"name":"setSwapAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"setVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"sps","outputs":[{"internalType":"address","name":"sp","type":"address"},{"internalType":"uint96","name":"weight","type":"uint96"},{"internalType":"address","name":"coll","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"sp","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct ISBold.SwapData[]","name":"swapData","type":"tuple[]"},{"internalType":"address","name":"receiver","type":"address"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapAdapter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapFeeBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","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":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

60c060405234801562000010575f80fd5b5060405162006432380380620064328339810160408190526200003391620016d6565b828282338989896003620000488382620018d7565b506004620000578282620018d7565b5050505f806200006d836200013b60201b60201c565b91509150816200007f57601262000081565b805b60ff1660a05250506001600160a01b039081166080526005805460ff191690558116620000c857604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b620000d3816200021a565b50620000df8362000273565b600c80546001600160a01b039384166001600160a01b031991821617909155600e8054929093169116179055506200012e6200011a620004ce565b6200012790600a62001ab0565b30620004e4565b5050505050505062001c06565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f918291829182916001600160a01b03871691620001839162001ac0565b5f60405180830381855afa9150503d805f8114620001bd576040519150601f19603f3d011682016040523d82523d5f602084013e620001c2565b606091505b5091509150818015620001d757506020815110155b156200020e575f81806020019051810190620001f4919062001add565b905060ff81116200020c576001969095509350505050565b505b505f9485945092505050565b600580546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b80515f036200029557604051635dc957f360e11b815260040160405180910390fd5b5f805b8251811015620004a6575f838281518110620002b857620002b862001af5565b60200260200101515f015190505f848381518110620002db57620002db62001af5565b6020026020010151602001519050620002fa826200055560201b60201c565b806001600160601b03165f0362000324576040516319a2a9bd60e01b815260040160405180910390fd5b5f5b8551811015620003995780841415801562000371575085818151811062000351576200035162001af5565b60200260200101515f01516001600160a01b0316836001600160a01b0316145b156200039057604051630148f8ab60e31b815260040160405180910390fd5b60010162000326565b5060066040518060600160405280846001600160a01b03168152602001836001600160601b03168152602001846001600160a01b03166331b8c9466040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000402573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000428919062001b09565b6001600160a01b039081169091528254600180820185555f948552602094859020845195850151958416600160a01b6001600160601b039788160217600290930201918255604090930151920180546001600160a01b03191692909116919091179055620004999082168562001b27565b9350505060010162000298565b506127108114620004ca57604051639006dd2760e01b815260040160405180910390fd5b5050565b5f8060a051620004df919062001b3d565b905090565b5f80620004f18362000580565b9050808411156200052f57604051633c8097d960e11b81526001600160a01b03841660048201526024810185905260448101829052606401620000bf565b5f6200053b85620005d5565b90506200054b338587846200064b565b9150505b92915050565b6001600160a01b0381166200057d5760405163e6c4247b60e01b815260040160405180910390fd5b50565b5f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c15620005c257604051633ee5aeb560e01b815260040160405180910390fd5b620005cd82620006c5565b90505b919050565b5f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c156200061757604051633ee5aeb560e01b815260040160405180910390fd5b5f6200062c83600754620006fc60201b60201c565b9050620006446200063e828562001b59565b6200071b565b9392505050565b6080516200065c9085308562000728565b6200066883826200078e565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78484604051620006b7929190918252602082015260400190565b60405180910390a350505050565b5f80620006d281620007c6565b50509050801580620006e6575060055460ff165b15620006f457505f92915050565b5f1962000644565b5f6200064482620007106127108262001b27565b85919060016200084b565b5f620005cd8282620008a1565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b039081166323b872dd60e01b1790915262000788918691620008f616565b50505050565b6001600160a01b038216620007b95760405163ec442f0560e01b81525f6004820152602401620000bf565b620004ca5f838362000967565b5f8080808080620007e1620007da60805190565b8862000a96565b92509250925082620007ff575f805f95509550955050505062000844565b600b5481116200081a57600195509093509150620008449050565b86156200083a5760405163e2b3ade560e01b815260040160405180910390fd5b5f95509093509150505b9193909250565b5f6200087f6200085b8362000cf6565b80156200087a57505f848062000875576200087562001b6f565b868809115b151590565b6200088c86868662000d27565b62000898919062001b27565b95945050505050565b5f62000644620008b0620004ce565b620008bd90600a62001ab0565b620008ec5f856003811115620008d757620008d762001b83565b14620008e4575f62000de5565b600162000de5565b859190856200084b565b5f8060205f8451602086015f885af18062000916576040513d5f823e3d81fd5b50505f513d915081156200092f5780600114156200093c565b6001600160a01b0384163b155b156200078857604051635274afe760e01b81526001600160a01b0385166004820152602401620000bf565b6001600160a01b03831662000995578060025f82825462000989919062001b27565b9091555062000a079050565b6001600160a01b0383165f9081526020819052604090205481811015620009e95760405163391434e360e21b81526001600160a01b03851660048201526024810182905260448101839052606401620000bf565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821662000a255760028054829003905562000a43565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405162000a8991815260200190565b60405180910390a3505050565b5f80807f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df57069005c1562000b11575060019150507fb9119c9d507ab94e0f4429b4c7bbf0463ef7a3523c74e225b6641cfb04e67a005c7f93de9a8576a62ce59fcb637d8053d0e5fadcf7d26694489a7981d83007528a005c62000cef565b5f62000bac6006805480602002602001604051908101604052809291908181526020015f905b8282101562000b9b575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910162000b37565b505050505f62000e4a60201b60201c565b600c5490915062000bc8906001600160a01b0316828762000f1b565b9094509250831562000ced57600c546001600160a01b031663ba86003362000bef620004ce565b62000bfc90600a62001ab0565b6040516001600160e01b031960e084901b16815260048101919091526001600160a01b0389166024820152604401602060405180830381865afa92505050801562000c66575060408051601f3d908101601f1916820190925262000c639181019062001add565b60015b62000cce573d80801562000c96576040519150601f19603f3d011682016040523d82523d5f602084013e62000c9b565b606091505b50851562000cbf578060405162461bcd60e51b8152600401620000bf919062001b97565b505f935083915062000cef9050565b62000ce962000ce06012600a62001bcb565b85908362000d27565b9250505b505b9250925092565b5f600282600381111562000d0e5762000d0e62001b83565b62000d1a919062001bd8565b60ff166001149050919050565b5f838302815f1985870982811083820303915050805f0362000d605783828162000d555762000d5562001b6f565b049250505062000644565b80841162000d7a5762000d7a600385150260111862001099565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f8062000df1620010aa565b50505090506200064462000e0a620004ce60201b60201c565b62000e1790600a62001ab0565b62000e245f600a62001ab0565b60025462000e33919062001b27565b8562000e4185600162001b27565b9291906200084b565b606082516001600160401b0381111562000e685762000e68620015d7565b60405190808252806020026020018201604052801562000eae57816020015b604080518082019091525f808252602082015281526020019060019003908162000e875790505b5090505f5b835181101562000f145762000eeb84828151811062000ed65762000ed662001af5565b602002602001015184620011c160201b60201c565b82828151811062000f005762000f0062001af5565b602090810291909101015260010162000eb3565b5092915050565b5f805f5b84518110156200108b5784818151811062000f3e5762000f3e62001af5565b6020026020010151602001515f03156200108257856001600160a01b031663ba86003386838151811062000f765762000f7662001af5565b60200260200101516020015187848151811062000f975762000f9762001af5565b60200260200101515f01516040518363ffffffff1660e01b815260040162000fd29291909182526001600160a01b0316602082015260400190565b602060405180830381865afa9250505080156200100e575060408051601f3d908101601f191682019092526200100b9181019062001add565b60015b62001072573d8080156200103e576040519150601f19603f3d011682016040523d82523d5f602084013e62001043565b606091505b50841562001067578060405162461bcd60e51b8152600401620000bf919062001b97565b5f9350505062001091565b6200107e818462001b27565b9250505b60010162000f1f565b50600191505b935093915050565b634e487b715f52806020526024601cfd5b5f80808080620010b960805190565b90505f620011566006805480602002602001604051908101604052809291908181526020015f905b8282101562001145575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101620010e1565b50505050836200139760201b60201c565b90505f806200116784600162000a96565b92509250505f6200118182600a546200146160201b60201c565b90505f6200119b826008546009546200147d60201b60201c565b505090505f8186620011ae919062001b27565b9b959a5093985091965092945050505050565b604080518082019091525f808252602082015260408084015190516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa1580156200121d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062001243919062001add565b905082156200127757604051806040016040528085604001516001600160a01b03168152602001828152509150506200054f565b83516040516311faa0d560e21b81523060048201525f916001600160a01b0316906347ea835490602401602060405180830381865afa158015620012bd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620012e3919062001add565b8551604051637b4c628760e01b81523060048201529192505f916001600160a01b0390911690637b4c628790602401602060405180830381865afa1580156200132e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062001354919062001add565b90505f8362001364838562001b27565b62001370919062001b27565b6040805180820182529801516001600160a01b031688526020880152509495945050505050565b5f805b8351811015620013eb57620013d4848281518110620013bd57620013bd62001af5565b60200260200101515f0151620014ca60201b60201c565b620013e0908362001b27565b91506001016200139a565b506040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa1580156200142f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062001455919062001add565b62000644908262001b27565b5f62001471838361271062000d27565b62000644908462001b59565b5f80808062001490878761271062000d27565b90505f620014a2888761271062000d27565b905080620014b1838a62001b59565b620014bd919062001b59565b9891975095509350505050565b60405163065f566d60e01b81523060048201525f90829082906001600160a01b0383169063065f566d90602401602060405180830381865afa15801562001513573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062001539919062001add565b6040516376a1021360e01b81523060048201529091505f906001600160a01b038416906376a1021390602401602060405180830381865afa15801562001581573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620015a7919062001add565b905062000898818362001b27565b6001600160a01b03811681146200057d575f80fd5b8051620005d081620015b5565b634e487b7160e01b5f52604160045260245ffd5b604080519081016001600160401b0381118282101715620016105762001610620015d7565b60405290565b604051601f8201601f191681016001600160401b0381118282101715620016415762001641620015d7565b604052919050565b5f5b83811015620016655781810151838201526020016200164b565b50505f910152565b5f82601f8301126200167d575f80fd5b81516001600160401b03811115620016995762001699620015d7565b620016ae601f8201601f191660200162001616565b818152846020838601011115620016c3575f80fd5b6200054b82602083016020870162001649565b5f805f805f8060c08789031215620016ec575f80fd5b8651620016f981620015b5565b602088810151919750906001600160401b038082111562001718575f80fd5b620017268b838c016200166d565b97506040915060408a0151818111156200173e575f80fd5b6200174c8c828d016200166d565b97505060608a01518181111562001761575f80fd5b8a01601f81018c1362001772575f80fd5b805182811115620017875762001787620015d7565b62001797858260051b0162001616565b818152858101935060069190911b82018501908d821115620017b7575f80fd5b918501915b818310156200181a5784838f031215620017d4575f80fd5b620017de620015eb565b8351620017eb81620015b5565b8152838701516001600160601b038116811462001806575f80fd5b8188015284529285019291840191620017bc565b8098505050505050506200183160808801620015ca565b91506200184160a08801620015ca565b90509295509295509295565b600181811c908216806200186257607f821691505b6020821081036200188157634e487b7160e01b5f52602260045260245ffd5b50919050565b601f821115620018d257805f5260205f20601f840160051c81016020851015620018ae5750805b601f840160051c820191505b81811015620018cf575f8155600101620018ba565b50505b505050565b81516001600160401b03811115620018f357620018f3620015d7565b6200190b816200190484546200184d565b8462001887565b602080601f83116001811462001941575f8415620019295750858301515b5f19600386901b1c1916600185901b1785556200199b565b5f85815260208120601f198616915b82811015620019715788860151825594840194600190910190840162001950565b50858210156200198f57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b634e487b7160e01b5f52601160045260245ffd5b600181815b80851115620019f757815f1904821115620019db57620019db620019a3565b80851615620019e957918102915b93841c9390800290620019bc565b509250929050565b5f8262001a0f575060016200054f565b8162001a1d57505f6200054f565b816001811462001a36576002811462001a415762001a61565b60019150506200054f565b60ff84111562001a555762001a55620019a3565b50506001821b6200054f565b5060208310610133831016604e8410600b841016171562001a86575081810a6200054f565b62001a928383620019b7565b805f190482111562001aa85762001aa8620019a3565b029392505050565b5f6200064460ff841683620019ff565b5f825162001ad381846020870162001649565b9190910192915050565b5f6020828403121562001aee575f80fd5b5051919050565b634e487b7160e01b5f52603260045260245ffd5b5f6020828403121562001b1a575f80fd5b81516200064481620015b5565b808201808211156200054f576200054f620019a3565b60ff81811683821601908111156200054f576200054f620019a3565b818103818111156200054f576200054f620019a3565b634e487b7160e01b5f52601260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b602081525f825180602084015262001bb781604085016020870162001649565b601f01601f19169190910160400192915050565b5f620006448383620019ff565b5f60ff83168062001bf757634e487b7160e01b5f52601260045260245ffd5b8060ff84160691505092915050565b60805160a0516147af62001c835f395f610dc601525f81816104910152818161075b01528181610f7c015281816110be0152818161124101528181611354015281816116c7015281816117a7015281816119ca01528181611b46015281816121db01528181612ac701528181612d9b0152612e4401526147af5ff3fe608060405234801561000f575f80fd5b50600436106102e5575f3560e01c80636e553f6511610195578063b460af94116100e4578063c6e6f5921161009e578063dd62ed3e11610079578063dd62ed3e14610684578063ef8b30f7146106bc578063f2fde38b146106cf578063fbfa77cf146106e2575f80fd5b8063c6e6f5921461064b578063ce96cb771461065e578063d905777e14610671575f80fd5b8063b460af9414610601578063b50bb66914610614578063b826ee541461061c578063ba0876521461062f578063bf2428e614610642578063c63d75b6146104bd575f80fd5b80638c04166f1161014f57806395d89b411161012a57806395d89b41146105c05780639dae2078146105c8578063a9059cbb146105db578063b3d7f6b9146105ee575f80fd5b80638c04166f1461058e5780638da5cb5b1461059757806394bf804d146105ad575f80fd5b80636e553f651461052757806370a082311461053a578063715018a61461056257806377bb1eb91461056a57806382328ffc1461057d5780638456cb5914610586575f80fd5b8063293be456116102515780633f4ba83a1161020b5780634cdad506116101e65780634cdad506146104e3578063530e784f146104f65780635c975abb146105095780636817031b14610514575f80fd5b80633f4ba83a146104b5578063402d267d146104bd57806343f68a49146104d0575f80fd5b8063293be456146104015780632d7fa052146104145780632ffdaf8914610427578063313ce56714610430578063349bc2511461044a57806338d52e0f1461048f575f80fd5b80630b78f9c0116102a25780630b78f9c014610377578063160b71df1461038a57806318160ddd146103b257806323b872dd146103ba57806324a9d853146103cd5780632630c12f146103d6575f80fd5b806301e1d114146102e957806304ad8c751461030457806306fdde031461031957806307a2d13a1461032e578063095ea7b3146103415780630a28a47714610364575b5f80fd5b6102f16106f5565b6040519081526020015b60405180910390f35b610317610312366004614181565b61072f565b005b610321610af4565b6040516102fb919061425d565b6102f161033c36600461426f565b610b84565b61035461034f366004614286565b610bbd565b60405190151581526020016102fb565b6102f161037236600461426f565b610bd6565b6103176103853660046142b0565b610c06565b610392610c83565b6040805194855260208501939093529183015260608201526080016102fb565b6002546102f1565b6103546103c83660046142d0565b610cc3565b6102f160075481565b600c546103e9906001600160a01b031681565b6040516001600160a01b0390911681526020016102fb565b61031761040f36600461426f565b610ce8565b61031761042236600461426f565b610d4e565b6102f160085481565b610438610dbf565b60405160ff90911681526020016102fb565b61045d61045836600461426f565b610def565b604080516001600160a01b0394851681526001600160601b0390931660208401529216918101919091526060016102fb565b7f00000000000000000000000000000000000000000000000000000000000000006103e9565b610317610e38565b6102f16104cb36600461430e565b610e4a565b6103176104de36600461426f565b610e7a565b6102f16104f136600461426f565b610eda565b61031761050436600461430e565b610f0a565b60055460ff16610354565b61031761052236600461430e565b610f69565b6102f1610535366004614329565b61102e565b6102f161054836600461430e565b6001600160a01b03165f9081526020819052604090205490565b610317611199565b600d546103e9906001600160a01b031681565b6102f160095481565b6103176111aa565b6102f1600a5481565b60055461010090046001600160a01b03166103e9565b6102f16105bb366004614329565b6111ba565b610321611319565b6103176105d6366004614357565b611328565b6103546105e9366004614286565b61158a565b6102f16105fc36600461426f565b611597565b6102f161060f36600461439b565b6115e0565b6102f1611719565b61031761062a36600461430e565b611794565b6102f161063d36600461439b565b6118e3565b6102f1600b5481565b6102f161065936600461426f565b611a09565b6102f161066c36600461430e565b611a3a565b6102f161067f36600461430e565b611a6a565b6102f16106923660046143da565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6102f16106ca36600461426f565b611a9a565b6103176106dd36600461430e565b611add565b600e546103e9906001600160a01b031681565b5f6106fe611b1a565b1561071c57604051633ee5aeb560e01b815260040160405180910390fd5b5f610725611b3f565b5091935050505090565b610737611c4f565b61073f611c82565b600c5460068054604080516020808402820181019092528281527f0000000000000000000000000000000000000000000000000000000000000000945f946108019487946001600160a01b039093169392879084015b828210156107f7575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101610795565b5050505086611cd5565b600d54600a549192506108219184916001600160a01b0316908490612054565b5061082c60016121d0565b505f91508190505b600654811015610886576108726006828154811061085457610854614406565b5f9182526020909120600290910201546001600160a01b0316612265565b61087c908361442e565b9150600101610834565b506109216006805480602002602001604051908101604052809291908181526020015f905b8282101561090d575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b031684860152600191820154169183019190915290835290920191016108ab565b505050508461091a610dbf565b845f612351565b61092c60065f613f81565b6109868686808060200260200160405190810160405280939291908181526020015f905b8282101561097c5761096d60408302860136819003810190614457565b81526020019060010190610950565b5050505050612580565b6040516370a0823160e01b81523060048201525f906001600160a01b038516906370a0823190602401602060405180830381865afa1580156109ca573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ee91906144b2565b90505f6109f9610dbf565b610a0490600a6145a9565b905080821115610aa957610aa96006805480602002602001604051908101604052809291908181526020015f905b82821015610a94575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101610a32565b505050508284610aa491906145b7565b6127b8565b7fd8f14e27e09d4320f103ef949a7ceff43acef14cc77d7a1eae937e4fa51764008888604051610ada9291906145ca565b60405180910390a15050505050610aef612876565b505050565b606060038054610b0390614632565b80601f0160208091040260200160405190810160405280929190818152602001828054610b2f90614632565b8015610b7a5780601f10610b5157610100808354040283529160200191610b7a565b820191905f5260205f20905b815481529060010190602001808311610b5d57829003601f168201915b5050505050905090565b5f610b8d611b1a565b15610bab57604051633ee5aeb560e01b815260040160405180910390fd5b610bb5825f6128a0565b90505b919050565b5f33610bca8185856128c9565b60019150505b92915050565b5f610bdf611b1a565b15610bfd57604051633ee5aeb560e01b815260040160405180910390fd5b610bb5826128d6565b610c0e611c4f565b6101f4821180610c1e575060fa81115b15610c3c5760405163c52a9bd360e01b815260040160405180910390fd5b6007829055600881905560408051838152602081018390527f93525d3c7f4fafe56faedbca6d501a13c63f47857d8b30d8282ec2dd806259a7910160405180910390a15050565b5f805f80610c8f611b1a565b15610cad57604051633ee5aeb560e01b815260040160405180910390fd5b610cb5611b3f565b935093509350935090919293565b5f33610cd08582856128e2565b610cdb85858561294a565b60019150505b9392505050565b610cf0611c4f565b60fa811115610d125760405163c52a9bd360e01b815260040160405180910390fd5b60098190556040518181527f4c42db8a799110fdd6a26148a21a5fbe4e581c926bccfd3b2d8a7f3aed4a87c8906020015b60405180910390a150565b610d56611c4f565b801580610d6c575069d3c21bcecceda100000081115b15610d8a5760405163c52a9bd360e01b815260040160405180910390fd5b600b8190556040518181527fd56a98e00f4e2daf46c500c9c64978145275a8f428774c566de8ec9905d595f390602001610d43565b5f610dea817f000000000000000000000000000000000000000000000000000000000000000061466a565b905090565b60068181548110610dfe575f80fd5b5f918252602090912060029091020180546001909101546001600160a01b038083169350600160a01b9092046001600160601b0316911683565b610e40611c4f565b610e486129a7565b565b5f610e53611b1a565b15610e7157604051633ee5aeb560e01b815260040160405180910390fd5b610bb5826129f9565b610e82611c4f565b6101f4811115610ea55760405163c52a9bd360e01b815260040160405180910390fd5b600a8190556040518181527f655eeddda94c0a9de22c1474e6b5aa4f18d3e8048dc9eff185437c7fe3bfb50590602001610d43565b5f610ee3611b1a565b15610f0157604051633ee5aeb560e01b815260040160405180910390fd5b610bb582612a2b565b610f12611c4f565b610f1b81612a36565b600c80546001600160a01b0319166001600160a01b0383169081179091556040519081527f6536690106168bdf4ba72c128a053d817999b1db90cae23f139b293bf862cb7590602001610d43565b610f71611c4f565b610f7a81612a36565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b03161480610fc257506001600160a01b03811630145b15610fe05760405163e6c4247b60e01b815260040160405180910390fd5b600e80546001600160a01b0319166001600160a01b0383169081179091556040519081527fe7ae49f883c825b05681b3e00e8be6fdea9ed2a8a45e4c6ecb9390fc44cce61590602001610d43565b5f611037612a5d565b61103f611c82565b611047612a81565b5f611051836129f9565b90508084111561108357828482604051633c8097d960e11b815260040161107a93929190614683565b60405180910390fd5b5f61109085600754612a9c565b90505f6110a56110a083886145b7565b612ab7565b90506110b333868884612ac2565b81156110ef576110ef7f0000000000000000000000000000000000000000000000000000000000000000600e546001600160a01b031684612b54565b6111856006805480602002602001604051908101604052809291908181526020015f905b82821015611175575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101611113565b505050508388610aa491906145b7565b92505050611191612bb3565b610bd0612876565b6111a1611c4f565b610e485f612bdd565b6111b2611c4f565b610e48612c36565b5f6111c3612a5d565b6111cb611c82565b6111d3612a81565b5f6111dd836129f9565b9050808411156112065782848260405163284ff66760e01b815260040161107a93929190614683565b5f61121085612c73565b90505f61121f82600754612c7f565b90506112363386611230848661442e565b89612ac2565b8015611272576112727f0000000000000000000000000000000000000000000000000000000000000000600e546001600160a01b031683612b54565b6113026006805480602002602001604051908101604052809291908181526020015f905b828210156112f8575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101611296565b50505050836127b8565b61130c818361442e565b9350505050611191612bb3565b606060048054610b0390614632565b611330612a5d565b611338611c82565b600c5460068054604080516020808402820181019092528281527f0000000000000000000000000000000000000000000000000000000000000000945f946113fa9487946001600160a01b039093169392879084015b828210156113f0575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161138e565b5050505087611cd5565b90505f61141f83600d5f9054906101000a90046001600160a01b031684600a54612054565b90505f8061143283600854600954612c8f565b9093509150859050821561145857600e546114589082906001600160a01b031685612b54565b811561146957611469818884612b54565b6040516370a0823160e01b81523060048201525f906001600160a01b038816906370a0823190602401602060405180830381865afa1580156114ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d191906144b2565b90505f6114dc610dbf565b6114e790600a6145a9565b905080821115611576576115766006805480602002602001604051908101604052809291908181526020015f9082821015610a94575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101610a32565b5050505050505050611586612876565b5050565b5f33610bca81858561294a565b5f6115a0611b1a565b156115be57604051633ee5aeb560e01b815260040160405180910390fd5b5f6115c883612c73565b90506115d681600754612c7f565b610ce1908261442e565b5f6115e9612a5d565b6115f1611c82565b6115f9612a81565b5f61160383612cd4565b90508085111561162c57828582604051633fa733bb60e21b815260040161107a93929190614683565b5f611636866128d6565b90506116f96006805480602002602001604051908101604052809291908181526020015f905b828210156116be575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161165c565b505050506116e97f000000000000000000000000000000000000000000000000000000000000000090565b6116f1610dbf565b896001612351565b6117063386868985612e11565b915050611711612bb3565b610ce1612876565b5f611722611b1a565b1561174057604051633ee5aeb560e01b815260040160405180910390fd5b5f611749611b3f565b505050905061178e611759610dbf565b61176490600a6145a9565b61176f5f600a6145a9565b60025461177c919061442e565b61178784600161442e565b9190612ed1565b91505090565b61179c611c4f565b6117a581612a36565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316036117f75760405163e6c4247b60e01b815260040160405180910390fd5b5f5b600654811015611895576006818154811061181657611816614406565b5f9182526020909120600290910201546001600160a01b038381169116148061186f57506006818154811061184d5761184d614406565b5f9182526020909120600160029092020101546001600160a01b038381169116145b1561188d5760405163e6c4247b60e01b815260040160405180910390fd5b6001016117f9565b50600d80546001600160a01b0319166001600160a01b0383169081179091556040519081527e220ce35c24f3b7cebc69ac0be87aecb3dbb78afe13e2bdc053e0d588e5604690602001610d43565b5f6118ec612a5d565b6118f4611c82565b6118fc612a81565b5f61190683612f87565b90508085111561192f57828582604051632e52afbb60e21b815260040161107a93929190614683565b5f61193986612a2b565b90506119fc6006805480602002602001604051908101604052809291908181526020015f905b828210156119c1575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161195f565b505050506119ec7f000000000000000000000000000000000000000000000000000000000000000090565b6119f4610dbf565b846001612351565b611706338686848a612e11565b5f611a12611b1a565b15611a3057604051633ee5aeb560e01b815260040160405180910390fd5b610bb5825f613093565b5f611a43611b1a565b15611a6157604051633ee5aeb560e01b815260040160405180910390fd5b610bb582612cd4565b5f611a73611b1a565b15611a9157604051633ee5aeb560e01b815260040160405180910390fd5b610bb582612f87565b5f611aa3611b1a565b15611ac157604051633ee5aeb560e01b815260040160405180910390fd5b5f611ace83600754612a9c565b9050610ce16110a082856145b7565b611ae5611c4f565b6001600160a01b038116611b0e57604051631e4fbdf760e01b81525f600482015260240161107a565b611b1781612bdd565b50565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c90565b5f808080807f000000000000000000000000000000000000000000000000000000000000000090505f611bf86006805480602002602001604051908101604052809291908181526020015f905b82821015611bee575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101611b8c565b50505050836130d2565b90505f80611c0784600161317e565b92509250505f611c1982600a546133bd565b90505f611c2b82600854600954612c8f565b505090505f8186611c3c919061442e565b9b959a5093985091965092945050505050565b6005546001600160a01b03610100909104163314610e485760405163118cdaa760e01b815233600482015260240161107a565b611c8a611b1a565b15611ca857604051633ee5aeb560e01b815260040160405180910390fd5b610e4860017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005b906133d5565b6060825182511180611ce657508151155b15611d045760405163dd44448560e01b815260040160405180910390fd5b815167ffffffffffffffff811115611d1e57611d1e613fc4565b604051908082528060200260200182016040528015611d8057816020015b611d6d60405180608001604052805f6001600160a01b031681526020015f81526020015f8152602001606081525090565b815260200190600190039081611d3c5790505b5090505f5b825181101561204b575f5b8451811015611ff457838281518110611dab57611dab614406565b60200260200101515f01516001600160a01b0316858281518110611dd157611dd1614406565b60200260200101515f01516001600160a01b031603611fec57848181518110611dfc57611dfc614406565b60209081029190910101515160405163cfddf5f560e01b81525f6004820152600160248201526001600160a01b039091169063cfddf5f5906044015f604051808303815f87803b158015611e4e575f80fd5b505af1158015611e60573d5f803e3d5ffd5b505050505f611e89868381518110611e7a57611e7a614406565b602002602001015160016133dc565b6020015190505f858481518110611ea257611ea2614406565b6020026020010151602001518210611ed757858481518110611ec657611ec6614406565b602002602001015160200151611ed9565b815b90505f611f65898b8a8781518110611ef357611ef3614406565b602002602001015160400151858e6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f3c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f6091906146a4565b6135a3565b90506040518060800160405280898681518110611f8457611f84614406565b6020026020010151604001516001600160a01b03168152602001838152602001828152602001888781518110611fbc57611fbc614406565b602002602001015160400151815250868681518110611fdd57611fdd614406565b60200260200101819052505050505b600101611d90565b505f6001600160a01b031682828151811061201157612011614406565b60200260200101515f01516001600160a01b0316036120435760405163dd44448560e01b815260040160405180910390fd5b600101611d85565b50949350505050565b5f805b835181101561204b5783818151811061207257612072614406565b6020026020010151602001515f03156121c8575f6120ad85838151811061209b5761209b614406565b602002602001015160400151856133bd565b90505f612114878785815181106120c6576120c6614406565b60200260200101515f01518a8987815181106120e4576120e4614406565b602002602001015160200151868b898151811061210357612103614406565b6020026020010151606001516136c5565b9050612120818561442e565b9350876001600160a01b031686848151811061213e5761213e614406565b60200260200101515f01516001600160a01b0316886001600160a01b03167fd6d34547c69c5ee3d2667625c188acf1006abb93e0ee7cf03925c67cf776041389878151811061218f5761218f614406565b60200260200101516020015185876040516121bd939291909283526020830191909152604082015260600190565b60405180910390a450505b600101612057565b5f80808080806122007f00000000000000000000000000000000000000000000000000000000000000008861317e565b9250925092508261221c575f805f95509550955050505061225e565b600b5481116122355760019550909350915061225e9050565b86156122545760405163e2b3ade560e01b815260040160405180910390fd5b5f95509093509150505b9193909250565b60405163065f566d60e01b81523060048201525f90829082906001600160a01b0383169063065f566d90602401602060405180830381865afa1580156122ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122d191906144b2565b6040516376a1021360e01b81523060048201529091505f906001600160a01b038416906376a1021390602401602060405180830381865afa158015612318573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061233c91906144b2565b9050612348818361442e565b95945050505050565b5f5b85518110156124d4575f86828151811061236f5761236f614406565b60209081029190910101515160405163065f566d60e01b81523060048201529091505f906001600160a01b0383169063065f566d90602401602060405180830381865afa1580156123c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123e691906144b2565b6040516376a1021360e01b81523060048201529091505f906001600160a01b038416906376a1021390602401602060405180830381865afa15801561242d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061245191906144b2565b90508115801561245f575080155b1561246c575050506124cc565b60405163cfddf5f560e01b815260048101839052600160248201526001600160a01b0384169063cfddf5f5906044015f604051808303815f87803b1580156124b2575f80fd5b505af11580156124c4573d5f803e3d5ffd5b505050505050505b600101612353565b506040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa158015612519573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061253d91906144b2565b90505f61254a84836145b7565b90505f61255886600a6145a9565b9050808211156125765783156125765761257688610aa483856145b7565b5050505050505050565b80515f036125a157604051635dc957f360e11b815260040160405180910390fd5b5f805b8251811015612795575f8382815181106125c0576125c0614406565b60200260200101515f015190505f8483815181106125e0576125e0614406565b60200260200101516020015190506125f782612a36565b806001600160601b03165f03612620576040516319a2a9bd60e01b815260040160405180910390fd5b5f5b855181101561268e57808414158015612668575085818151811061264857612648614406565b60200260200101515f01516001600160a01b0316836001600160a01b0316145b1561268657604051630148f8ab60e31b815260040160405180910390fd5b600101612622565b5060066040518060600160405280846001600160a01b03168152602001836001600160601b03168152602001846001600160a01b03166331b8c9466040518163ffffffff1660e01b8152600401602060405180830381865afa1580156126f6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061271a91906146c4565b6001600160a01b039081169091528254600180820185555f948552602094859020845195850151958416600160a01b6001600160601b039788160217600290930201918255604090930151920180546001600160a01b031916929091169190911790556127899082168561442e565b935050506001016125a4565b50612710811461158657604051639006dd2760e01b815260040160405180910390fd5b5f5b8251811015610aef575f8382815181106127d6576127d6614406565b602002602001015190505f61280582602001516001600160601b031661271086612ed19092919063ffffffff16565b9050801561286c578151604051630aeb4b9760e41b8152600481018390525f60248201526001600160a01b039091169063aeb4b970906044015f604051808303815f87803b158015612855575f80fd5b505af1158015612867573d5f803e3d5ffd5b505050505b50506001016127ba565b610e485f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00611ccf565b5f610ce16128ad836138ce565b6128b5610dbf565b6128c090600a6145a9565b8591908561391b565b610aef838383600161395d565b5f610bb5826001613093565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198114612944578181101561293657828183604051637dc7a0d960e11b815260040161107a93929190614683565b61294484848484035f61395d565b50505050565b6001600160a01b03831661297357604051634b637e8f60e11b81525f600482015260240161107a565b6001600160a01b03821661299c5760405163ec442f0560e01b81525f600482015260240161107a565b610aef838383613a21565b6129af613b34565b6005805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b5f80612a045f6121d0565b50509050801580612a17575060055460ff165b15612a2457505f92915050565b5f19610ce1565b5f610bb5825f6128a0565b6001600160a01b038116611b175760405163e6c4247b60e01b815260040160405180910390fd5b60055460ff1615610e485760405163d93c066560e01b815260040160405180910390fd5b5f80612a8d60016121d0565b92509250506115868282613b57565b5f610ce182612aad6127108261442e565b859190600161391b565b5f610bb5825f613093565b612aee7f0000000000000000000000000000000000000000000000000000000000000000853085613bd6565b612af88382613c0f565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78484604051612b46929190918252602082015260400190565b60405180910390a350505050565b6040516001600160a01b03838116602483015260448201839052610aef91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613c43565b610e485f7f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df5706900611ccf565b600580546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b612c3e612a5d565b6005805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586129dc3390565b5f610bb58260016128a0565b5f610ce18383612710600161391b565b5f808080612ca08787612710612ed1565b90505f612cb08887612710612ed1565b905080612cbd838a6145b7565b612cc791906145b7565b9891975095509350505050565b5f80612cdf5f6121d0565b50509050801580612cf2575060055460ff165b15612cff57505f92915050565b5f612d0984613caf565b90505f612dc26006805480602002602001604051908101604052809291908181526020015f905b82821015612d92575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101612d30565b50505050612dbd7f000000000000000000000000000000000000000000000000000000000000000090565b6130d2565b905080821115612e09575f612dd5610dbf565b612de090600a6145a9565b905080821015612df557505f95945050505050565b612dff81836145b7565b9695505050505050565b509392505050565b826001600160a01b0316856001600160a01b031614612e3557612e358386836128e2565b612e3f8382613cd1565b612e6a7f00000000000000000000000000000000000000000000000000000000000000008584612b54565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8585604051612ec2929190918252602082015260400190565b60405180910390a45050505050565b5f838302815f1985870982811083820303915050805f03612f0557838281612efb57612efb6146df565b0492505050610ce1565b808411612f1c57612f1c6003851502601118613d05565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f80612f925f6121d0565b50509050801580612fa5575060055460ff165b15612fb257505f92915050565b5f612fbc84613caf565b90505f6130446006805480602002602001604051908101604052809291908181526020015f9082821015612d92575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101612d30565b90508082111561308a575f613057610dbf565b61306290600a6145a9565b90508082101561307757505f95945050505050565b612dff61308482846145b7565b5f613093565b61234885613d16565b5f610ce161309f610dbf565b6130aa90600a6145a9565b6128c05f8560038111156130c0576130c06146f3565b146130cb575f6138ce565b60016138ce565b5f805b8351811015613117576131038482815181106130f3576130f3614406565b60200260200101515f0151612265565b61310d908361442e565b91506001016130d5565b506040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa15801561315a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115d691906144b2565b5f80807f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df57069005c156131f7575060019150507fb9119c9d507ab94e0f4429b4c7bbf0463ef7a3523c74e225b6641cfb04e67a005c7f93de9a8576a62ce59fcb637d8053d0e5fadcf7d26694489a7981d83007528a005c6133b6565b5f6132886006805480602002602001604051908101604052809291908181526020015f905b8282101561327e575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161321c565b505050505f613d33565b600c549091506132a2906001600160a01b03168287613df0565b909450925083156133b457600c546001600160a01b031663ba8600336132c6610dbf565b6132d190600a6145a9565b6040516001600160e01b031960e084901b16815260048101919091526001600160a01b0389166024820152604401602060405180830381865afa925050508015613338575060408051601f3d908101601f19168201909252613335918101906144b2565b60015b613399573d808015613365576040519150601f19603f3d011682016040523d82523d5f602084013e61336a565b606091505b50851561338b578060405162461bcd60e51b815260040161107a919061425d565b505f93508391506133b69050565b6133b06133a86012600a614707565b859083612ed1565b9250505b505b9250925092565b5f6133cb8383612710612ed1565b610ce190846145b7565b80825d5050565b604080518082019091525f808252602082015260408084015190516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa158015613437573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061345b91906144b2565b9050821561348d57604051806040016040528085604001516001600160a01b0316815260200182815250915050610bd0565b83516040516311faa0d560e21b81523060048201525f916001600160a01b0316906347ea835490602401602060405180830381865afa1580156134d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906134f691906144b2565b8551604051637b4c628760e01b81523060048201529192505f916001600160a01b0390911690637b4c628790602401602060405180830381865afa158015613540573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061356491906144b2565b90505f83613572838561442e565b61357c919061442e565b6040805180820182529801516001600160a01b031688526020880152509495945050505050565b60405163ba86003360e01b8152600481018390526001600160a01b0384811660248301525f91829188169063ba86003390604401602060405180830381865afa1580156135f2573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061361691906144b2565b90505f6001600160a01b03881663ba86003361363386600a6145a9565b6040516001600160e01b031960e084901b16815260048101919091526001600160a01b038a166024820152604401602060405180830381865afa15801561367c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136a091906144b2565b90506136b96136b16012600a614707565b839083612ed1565b98975050505050505050565b6040516370a0823160e01b81523060048201525f90859082906001600160a01b038316906370a0823190602401602060405180830381865afa15801561370d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061373191906144b2565b60405163095ea7b360e01b81526001600160a01b038b81166004830152602482018990529192509089169063095ea7b3906044016020604051808303815f875af1158015613781573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137a59190614712565b505f808a6001600160a01b0316866040516137c09190614731565b5f604051808303815f865af19150503d805f81146137f9576040519150601f19603f3d011682016040523d82523d5f602084013e6137fe565b606091505b50915091508161382357806040516315fcd67560e01b815260040161107a919061425d565b6040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa158015613867573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061388b91906144b2565b90505f61389885836145b7565b9050888110156138be576040516377b8dde360e01b81526004810182905260240161107a565b9c9b505050505050505050505050565b5f806138d8611b3f565b5050509050610ce16138e8610dbf565b6138f390600a6145a9565b6138fe5f600a6145a9565b60025461390b919061442e565b8561391785600161442e565b9291905b5f61394861392883613f55565b801561394357505f848061393e5761393e6146df565b868809115b151590565b613953868686612ed1565b612348919061442e565b6001600160a01b0384166139865760405163e602df0560e01b81525f600482015260240161107a565b6001600160a01b0383166139af57604051634a1406b160e11b81525f600482015260240161107a565b6001600160a01b038085165f908152600160209081526040808320938716835292905220829055801561294457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051612b4691815260200190565b6001600160a01b038316613a4b578060025f828254613a40919061442e565b90915550613aa89050565b6001600160a01b0383165f9081526020819052604090205481811015613a8a5783818360405163391434e360e21b815260040161107a93929190614683565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b038216613ac457600280548290039055613ae2565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051613b2791815260200190565b60405180910390a3505050565b60055460ff16610e4857604051638dfc202b60e01b815260040160405180910390fd5b613b8260017f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df5706900611ccf565b613bac827fb9119c9d507ab94e0f4429b4c7bbf0463ef7a3523c74e225b6641cfb04e67a00611ccf565b611586817f93de9a8576a62ce59fcb637d8053d0e5fadcf7d26694489a7981d83007528a00611ccf565b6040516001600160a01b0384811660248301528381166044830152606482018390526129449186918216906323b872dd90608401612b81565b6001600160a01b038216613c385760405163ec442f0560e01b81525f600482015260240161107a565b6115865f8383613a21565b5f8060205f8451602086015f885af180613c62576040513d5f823e3d81fd5b50505f513d91508115613c79578060011415613c86565b6001600160a01b0384163b155b1561294457604051635274afe760e01b81526001600160a01b038516600482015260240161107a565b6001600160a01b0381165f90815260208190526040812054610bb5905f6128a0565b6001600160a01b038216613cfa57604051634b637e8f60e11b81525f600482015260240161107a565b611586825f83613a21565b634e487b715f52806020526024601cfd5b6001600160a01b0381165f90815260208190526040812054610bb5565b6060825167ffffffffffffffff811115613d4f57613d4f613fc4565b604051908082528060200260200182016040528015613d9357816020015b604080518082019091525f8082526020820152815260200190600190039081613d6d5790505b5090505f5b8351811015613de957613dc4848281518110613db657613db6614406565b6020026020010151846133dc565b828281518110613dd657613dd6614406565b6020908102919091010152600101613d98565b5092915050565b5f805f5b8451811015613f4757848181518110613e0f57613e0f614406565b6020026020010151602001515f0315613f3f57856001600160a01b031663ba860033868381518110613e4357613e43614406565b602002602001015160200151878481518110613e6157613e61614406565b60200260200101515f01516040518363ffffffff1660e01b8152600401613e9b9291909182526001600160a01b0316602082015260400190565b602060405180830381865afa925050508015613ed4575060408051601f3d908101601f19168201909252613ed1918101906144b2565b60015b613f31573d808015613f01576040519150601f19603f3d011682016040523d82523d5f602084013e613f06565b606091505b508415613f27578060405162461bcd60e51b815260040161107a919061425d565b5f93505050613f4d565b613f3b818461442e565b9250505b600101613df4565b50600191505b935093915050565b5f6002826003811115613f6a57613f6a6146f3565b613f74919061474c565b60ff166001149050919050565b5080545f8255600202905f5260205f2090810190611b1791905b80821115613fc0575f81556001810180546001600160a01b0319169055600201613f9b565b5090565b634e487b7160e01b5f52604160045260245ffd5b6040516060810167ffffffffffffffff81118282101715613ffb57613ffb613fc4565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561402a5761402a613fc4565b604052919050565b6001600160a01b0381168114611b17575f80fd5b5f601f83601f840112614057575f80fd5b8235602067ffffffffffffffff8083111561407457614074613fc4565b8260051b614083838201614001565b938452868101830193838101908986111561409c575f80fd5b84890192505b85831015614174578235848111156140b8575f80fd5b89016060601f19828d0381018213156140cf575f80fd5b6140d7613fd8565b888401356140e481614032565b81526040848101358a830152928401359288841115614101575f80fd5b83850194508e603f860112614114575f80fd5b8985013593508884111561412a5761412a613fc4565b6141398a848e87011601614001565b92508383528e8185870101111561414e575f80fd5b838186018b8501375f9383018a01939093529182015283525091840191908401906140a2565b9998505050505050505050565b5f805f60408486031215614193575f80fd5b833567ffffffffffffffff808211156141aa575f80fd5b818601915086601f8301126141bd575f80fd5b8135818111156141cb575f80fd5b8760208260061b85010111156141df575f80fd5b6020928301955093509085013590808211156141f9575f80fd5b5061420686828701614046565b9150509250925092565b5f5b8381101561422a578181015183820152602001614212565b50505f910152565b5f8151808452614249816020860160208601614210565b601f01601f19169290920160200192915050565b602081525f610ce16020830184614232565b5f6020828403121561427f575f80fd5b5035919050565b5f8060408385031215614297575f80fd5b82356142a281614032565b946020939093013593505050565b5f80604083850312156142c1575f80fd5b50508035926020909101359150565b5f805f606084860312156142e2575f80fd5b83356142ed81614032565b925060208401356142fd81614032565b929592945050506040919091013590565b5f6020828403121561431e575f80fd5b8135610ce181614032565b5f806040838503121561433a575f80fd5b82359150602083013561434c81614032565b809150509250929050565b5f8060408385031215614368575f80fd5b823567ffffffffffffffff81111561437e575f80fd5b61438a85828601614046565b925050602083013561434c81614032565b5f805f606084860312156143ad575f80fd5b8335925060208401356143bf81614032565b915060408401356143cf81614032565b809150509250925092565b5f80604083850312156143eb575f80fd5b82356143f681614032565b9150602083013561434c81614032565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b80820180821115610bd057610bd061441a565b80356001600160601b0381168114610bb8575f80fd5b5f60408284031215614467575f80fd5b6040516040810181811067ffffffffffffffff8211171561448a5761448a613fc4565b604052823561449881614032565b81526144a660208401614441565b60208201529392505050565b5f602082840312156144c2575f80fd5b5051919050565b600181815b8085111561450357815f19048211156144e9576144e961441a565b808516156144f657918102915b93841c93908002906144ce565b509250929050565b5f8261451957506001610bd0565b8161452557505f610bd0565b816001811461453b576002811461454557614561565b6001915050610bd0565b60ff8411156145565761455661441a565b50506001821b610bd0565b5060208310610133831016604e8410600b8410161715614584575081810a610bd0565b61458e83836144c9565b805f19048211156145a1576145a161441a565b029392505050565b5f610ce160ff84168361450b565b81810381811115610bd057610bd061441a565b60208082528181018390525f90604080840186845b878110156146255781356145f281614032565b6001600160a01b031683526001600160601b03614610838701614441565b168386015291830191908301906001016145df565b5090979650505050505050565b600181811c9082168061464657607f821691505b60208210810361466457634e487b7160e01b5f52602260045260245ffd5b50919050565b60ff8181168382160190811115610bd057610bd061441a565b6001600160a01b039390931683526020830191909152604082015260600190565b5f602082840312156146b4575f80fd5b815160ff81168114610ce1575f80fd5b5f602082840312156146d4575f80fd5b8151610ce181614032565b634e487b7160e01b5f52601260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b5f610ce1838361450b565b5f60208284031215614722575f80fd5b81518015158114610ce1575f80fd5b5f8251614742818460208701614210565b9190910192915050565b5f60ff83168061476a57634e487b7160e01b5f52601260045260245ffd5b8060ff8416069150509291505056fea2646970667358221220a406d027cfa480b4133342409f222a5fe48e87be20fbcb3a40162946d712c21264736f6c634300081800330000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000091f98acfd427401e661bb300f61480349202aaa00000000000000000000000002df68ea583b8394a8cc71eebcd4fa7c6746027d5000000000000000000000000000000000000000000000000000000000000000573426f6c64000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000573424f4c4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000005721cbbd64fc7ae3ef44a0a3f9a790a9264cf9bf0000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000009502b7c397e9aa22fe9db7ef7daf21cd2aebe56b0000000000000000000000000000000000000000000000000000000000001770000000000000000000000000d442e41019b7f5c4dd78f50dc03726c44614869500000000000000000000000000000000000000000000000000000000000003e8

Deployed Bytecode

0x608060405234801561000f575f80fd5b50600436106102e5575f3560e01c80636e553f6511610195578063b460af94116100e4578063c6e6f5921161009e578063dd62ed3e11610079578063dd62ed3e14610684578063ef8b30f7146106bc578063f2fde38b146106cf578063fbfa77cf146106e2575f80fd5b8063c6e6f5921461064b578063ce96cb771461065e578063d905777e14610671575f80fd5b8063b460af9414610601578063b50bb66914610614578063b826ee541461061c578063ba0876521461062f578063bf2428e614610642578063c63d75b6146104bd575f80fd5b80638c04166f1161014f57806395d89b411161012a57806395d89b41146105c05780639dae2078146105c8578063a9059cbb146105db578063b3d7f6b9146105ee575f80fd5b80638c04166f1461058e5780638da5cb5b1461059757806394bf804d146105ad575f80fd5b80636e553f651461052757806370a082311461053a578063715018a61461056257806377bb1eb91461056a57806382328ffc1461057d5780638456cb5914610586575f80fd5b8063293be456116102515780633f4ba83a1161020b5780634cdad506116101e65780634cdad506146104e3578063530e784f146104f65780635c975abb146105095780636817031b14610514575f80fd5b80633f4ba83a146104b5578063402d267d146104bd57806343f68a49146104d0575f80fd5b8063293be456146104015780632d7fa052146104145780632ffdaf8914610427578063313ce56714610430578063349bc2511461044a57806338d52e0f1461048f575f80fd5b80630b78f9c0116102a25780630b78f9c014610377578063160b71df1461038a57806318160ddd146103b257806323b872dd146103ba57806324a9d853146103cd5780632630c12f146103d6575f80fd5b806301e1d114146102e957806304ad8c751461030457806306fdde031461031957806307a2d13a1461032e578063095ea7b3146103415780630a28a47714610364575b5f80fd5b6102f16106f5565b6040519081526020015b60405180910390f35b610317610312366004614181565b61072f565b005b610321610af4565b6040516102fb919061425d565b6102f161033c36600461426f565b610b84565b61035461034f366004614286565b610bbd565b60405190151581526020016102fb565b6102f161037236600461426f565b610bd6565b6103176103853660046142b0565b610c06565b610392610c83565b6040805194855260208501939093529183015260608201526080016102fb565b6002546102f1565b6103546103c83660046142d0565b610cc3565b6102f160075481565b600c546103e9906001600160a01b031681565b6040516001600160a01b0390911681526020016102fb565b61031761040f36600461426f565b610ce8565b61031761042236600461426f565b610d4e565b6102f160085481565b610438610dbf565b60405160ff90911681526020016102fb565b61045d61045836600461426f565b610def565b604080516001600160a01b0394851681526001600160601b0390931660208401529216918101919091526060016102fb565b7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d6103e9565b610317610e38565b6102f16104cb36600461430e565b610e4a565b6103176104de36600461426f565b610e7a565b6102f16104f136600461426f565b610eda565b61031761050436600461430e565b610f0a565b60055460ff16610354565b61031761052236600461430e565b610f69565b6102f1610535366004614329565b61102e565b6102f161054836600461430e565b6001600160a01b03165f9081526020819052604090205490565b610317611199565b600d546103e9906001600160a01b031681565b6102f160095481565b6103176111aa565b6102f1600a5481565b60055461010090046001600160a01b03166103e9565b6102f16105bb366004614329565b6111ba565b610321611319565b6103176105d6366004614357565b611328565b6103546105e9366004614286565b61158a565b6102f16105fc36600461426f565b611597565b6102f161060f36600461439b565b6115e0565b6102f1611719565b61031761062a36600461430e565b611794565b6102f161063d36600461439b565b6118e3565b6102f1600b5481565b6102f161065936600461426f565b611a09565b6102f161066c36600461430e565b611a3a565b6102f161067f36600461430e565b611a6a565b6102f16106923660046143da565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6102f16106ca36600461426f565b611a9a565b6103176106dd36600461430e565b611add565b600e546103e9906001600160a01b031681565b5f6106fe611b1a565b1561071c57604051633ee5aeb560e01b815260040160405180910390fd5b5f610725611b3f565b5091935050505090565b610737611c4f565b61073f611c82565b600c5460068054604080516020808402820181019092528281527f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d945f946108019487946001600160a01b039093169392879084015b828210156107f7575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101610795565b5050505086611cd5565b600d54600a549192506108219184916001600160a01b0316908490612054565b5061082c60016121d0565b505f91508190505b600654811015610886576108726006828154811061085457610854614406565b5f9182526020909120600290910201546001600160a01b0316612265565b61087c908361442e565b9150600101610834565b506109216006805480602002602001604051908101604052809291908181526020015f905b8282101561090d575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b031684860152600191820154169183019190915290835290920191016108ab565b505050508461091a610dbf565b845f612351565b61092c60065f613f81565b6109868686808060200260200160405190810160405280939291908181526020015f905b8282101561097c5761096d60408302860136819003810190614457565b81526020019060010190610950565b5050505050612580565b6040516370a0823160e01b81523060048201525f906001600160a01b038516906370a0823190602401602060405180830381865afa1580156109ca573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ee91906144b2565b90505f6109f9610dbf565b610a0490600a6145a9565b905080821115610aa957610aa96006805480602002602001604051908101604052809291908181526020015f905b82821015610a94575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101610a32565b505050508284610aa491906145b7565b6127b8565b7fd8f14e27e09d4320f103ef949a7ceff43acef14cc77d7a1eae937e4fa51764008888604051610ada9291906145ca565b60405180910390a15050505050610aef612876565b505050565b606060038054610b0390614632565b80601f0160208091040260200160405190810160405280929190818152602001828054610b2f90614632565b8015610b7a5780601f10610b5157610100808354040283529160200191610b7a565b820191905f5260205f20905b815481529060010190602001808311610b5d57829003601f168201915b5050505050905090565b5f610b8d611b1a565b15610bab57604051633ee5aeb560e01b815260040160405180910390fd5b610bb5825f6128a0565b90505b919050565b5f33610bca8185856128c9565b60019150505b92915050565b5f610bdf611b1a565b15610bfd57604051633ee5aeb560e01b815260040160405180910390fd5b610bb5826128d6565b610c0e611c4f565b6101f4821180610c1e575060fa81115b15610c3c5760405163c52a9bd360e01b815260040160405180910390fd5b6007829055600881905560408051838152602081018390527f93525d3c7f4fafe56faedbca6d501a13c63f47857d8b30d8282ec2dd806259a7910160405180910390a15050565b5f805f80610c8f611b1a565b15610cad57604051633ee5aeb560e01b815260040160405180910390fd5b610cb5611b3f565b935093509350935090919293565b5f33610cd08582856128e2565b610cdb85858561294a565b60019150505b9392505050565b610cf0611c4f565b60fa811115610d125760405163c52a9bd360e01b815260040160405180910390fd5b60098190556040518181527f4c42db8a799110fdd6a26148a21a5fbe4e581c926bccfd3b2d8a7f3aed4a87c8906020015b60405180910390a150565b610d56611c4f565b801580610d6c575069d3c21bcecceda100000081115b15610d8a5760405163c52a9bd360e01b815260040160405180910390fd5b600b8190556040518181527fd56a98e00f4e2daf46c500c9c64978145275a8f428774c566de8ec9905d595f390602001610d43565b5f610dea817f000000000000000000000000000000000000000000000000000000000000001261466a565b905090565b60068181548110610dfe575f80fd5b5f918252602090912060029091020180546001909101546001600160a01b038083169350600160a01b9092046001600160601b0316911683565b610e40611c4f565b610e486129a7565b565b5f610e53611b1a565b15610e7157604051633ee5aeb560e01b815260040160405180910390fd5b610bb5826129f9565b610e82611c4f565b6101f4811115610ea55760405163c52a9bd360e01b815260040160405180910390fd5b600a8190556040518181527f655eeddda94c0a9de22c1474e6b5aa4f18d3e8048dc9eff185437c7fe3bfb50590602001610d43565b5f610ee3611b1a565b15610f0157604051633ee5aeb560e01b815260040160405180910390fd5b610bb582612a2b565b610f12611c4f565b610f1b81612a36565b600c80546001600160a01b0319166001600160a01b0383169081179091556040519081527f6536690106168bdf4ba72c128a053d817999b1db90cae23f139b293bf862cb7590602001610d43565b610f71611c4f565b610f7a81612a36565b7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d6001600160a01b0316816001600160a01b03161480610fc257506001600160a01b03811630145b15610fe05760405163e6c4247b60e01b815260040160405180910390fd5b600e80546001600160a01b0319166001600160a01b0383169081179091556040519081527fe7ae49f883c825b05681b3e00e8be6fdea9ed2a8a45e4c6ecb9390fc44cce61590602001610d43565b5f611037612a5d565b61103f611c82565b611047612a81565b5f611051836129f9565b90508084111561108357828482604051633c8097d960e11b815260040161107a93929190614683565b60405180910390fd5b5f61109085600754612a9c565b90505f6110a56110a083886145b7565b612ab7565b90506110b333868884612ac2565b81156110ef576110ef7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d600e546001600160a01b031684612b54565b6111856006805480602002602001604051908101604052809291908181526020015f905b82821015611175575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101611113565b505050508388610aa491906145b7565b92505050611191612bb3565b610bd0612876565b6111a1611c4f565b610e485f612bdd565b6111b2611c4f565b610e48612c36565b5f6111c3612a5d565b6111cb611c82565b6111d3612a81565b5f6111dd836129f9565b9050808411156112065782848260405163284ff66760e01b815260040161107a93929190614683565b5f61121085612c73565b90505f61121f82600754612c7f565b90506112363386611230848661442e565b89612ac2565b8015611272576112727f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d600e546001600160a01b031683612b54565b6113026006805480602002602001604051908101604052809291908181526020015f905b828210156112f8575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101611296565b50505050836127b8565b61130c818361442e565b9350505050611191612bb3565b606060048054610b0390614632565b611330612a5d565b611338611c82565b600c5460068054604080516020808402820181019092528281527f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d945f946113fa9487946001600160a01b039093169392879084015b828210156113f0575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161138e565b5050505087611cd5565b90505f61141f83600d5f9054906101000a90046001600160a01b031684600a54612054565b90505f8061143283600854600954612c8f565b9093509150859050821561145857600e546114589082906001600160a01b031685612b54565b811561146957611469818884612b54565b6040516370a0823160e01b81523060048201525f906001600160a01b038816906370a0823190602401602060405180830381865afa1580156114ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d191906144b2565b90505f6114dc610dbf565b6114e790600a6145a9565b905080821115611576576115766006805480602002602001604051908101604052809291908181526020015f9082821015610a94575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101610a32565b5050505050505050611586612876565b5050565b5f33610bca81858561294a565b5f6115a0611b1a565b156115be57604051633ee5aeb560e01b815260040160405180910390fd5b5f6115c883612c73565b90506115d681600754612c7f565b610ce1908261442e565b5f6115e9612a5d565b6115f1611c82565b6115f9612a81565b5f61160383612cd4565b90508085111561162c57828582604051633fa733bb60e21b815260040161107a93929190614683565b5f611636866128d6565b90506116f96006805480602002602001604051908101604052809291908181526020015f905b828210156116be575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161165c565b505050506116e97f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d90565b6116f1610dbf565b896001612351565b6117063386868985612e11565b915050611711612bb3565b610ce1612876565b5f611722611b1a565b1561174057604051633ee5aeb560e01b815260040160405180910390fd5b5f611749611b3f565b505050905061178e611759610dbf565b61176490600a6145a9565b61176f5f600a6145a9565b60025461177c919061442e565b61178784600161442e565b9190612ed1565b91505090565b61179c611c4f565b6117a581612a36565b7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d6001600160a01b0316816001600160a01b0316036117f75760405163e6c4247b60e01b815260040160405180910390fd5b5f5b600654811015611895576006818154811061181657611816614406565b5f9182526020909120600290910201546001600160a01b038381169116148061186f57506006818154811061184d5761184d614406565b5f9182526020909120600160029092020101546001600160a01b038381169116145b1561188d5760405163e6c4247b60e01b815260040160405180910390fd5b6001016117f9565b50600d80546001600160a01b0319166001600160a01b0383169081179091556040519081527e220ce35c24f3b7cebc69ac0be87aecb3dbb78afe13e2bdc053e0d588e5604690602001610d43565b5f6118ec612a5d565b6118f4611c82565b6118fc612a81565b5f61190683612f87565b90508085111561192f57828582604051632e52afbb60e21b815260040161107a93929190614683565b5f61193986612a2b565b90506119fc6006805480602002602001604051908101604052809291908181526020015f905b828210156119c1575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161195f565b505050506119ec7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d90565b6119f4610dbf565b846001612351565b611706338686848a612e11565b5f611a12611b1a565b15611a3057604051633ee5aeb560e01b815260040160405180910390fd5b610bb5825f613093565b5f611a43611b1a565b15611a6157604051633ee5aeb560e01b815260040160405180910390fd5b610bb582612cd4565b5f611a73611b1a565b15611a9157604051633ee5aeb560e01b815260040160405180910390fd5b610bb582612f87565b5f611aa3611b1a565b15611ac157604051633ee5aeb560e01b815260040160405180910390fd5b5f611ace83600754612a9c565b9050610ce16110a082856145b7565b611ae5611c4f565b6001600160a01b038116611b0e57604051631e4fbdf760e01b81525f600482015260240161107a565b611b1781612bdd565b50565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c90565b5f808080807f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d90505f611bf86006805480602002602001604051908101604052809291908181526020015f905b82821015611bee575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101611b8c565b50505050836130d2565b90505f80611c0784600161317e565b92509250505f611c1982600a546133bd565b90505f611c2b82600854600954612c8f565b505090505f8186611c3c919061442e565b9b959a5093985091965092945050505050565b6005546001600160a01b03610100909104163314610e485760405163118cdaa760e01b815233600482015260240161107a565b611c8a611b1a565b15611ca857604051633ee5aeb560e01b815260040160405180910390fd5b610e4860017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005b906133d5565b6060825182511180611ce657508151155b15611d045760405163dd44448560e01b815260040160405180910390fd5b815167ffffffffffffffff811115611d1e57611d1e613fc4565b604051908082528060200260200182016040528015611d8057816020015b611d6d60405180608001604052805f6001600160a01b031681526020015f81526020015f8152602001606081525090565b815260200190600190039081611d3c5790505b5090505f5b825181101561204b575f5b8451811015611ff457838281518110611dab57611dab614406565b60200260200101515f01516001600160a01b0316858281518110611dd157611dd1614406565b60200260200101515f01516001600160a01b031603611fec57848181518110611dfc57611dfc614406565b60209081029190910101515160405163cfddf5f560e01b81525f6004820152600160248201526001600160a01b039091169063cfddf5f5906044015f604051808303815f87803b158015611e4e575f80fd5b505af1158015611e60573d5f803e3d5ffd5b505050505f611e89868381518110611e7a57611e7a614406565b602002602001015160016133dc565b6020015190505f858481518110611ea257611ea2614406565b6020026020010151602001518210611ed757858481518110611ec657611ec6614406565b602002602001015160200151611ed9565b815b90505f611f65898b8a8781518110611ef357611ef3614406565b602002602001015160400151858e6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f3c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f6091906146a4565b6135a3565b90506040518060800160405280898681518110611f8457611f84614406565b6020026020010151604001516001600160a01b03168152602001838152602001828152602001888781518110611fbc57611fbc614406565b602002602001015160400151815250868681518110611fdd57611fdd614406565b60200260200101819052505050505b600101611d90565b505f6001600160a01b031682828151811061201157612011614406565b60200260200101515f01516001600160a01b0316036120435760405163dd44448560e01b815260040160405180910390fd5b600101611d85565b50949350505050565b5f805b835181101561204b5783818151811061207257612072614406565b6020026020010151602001515f03156121c8575f6120ad85838151811061209b5761209b614406565b602002602001015160400151856133bd565b90505f612114878785815181106120c6576120c6614406565b60200260200101515f01518a8987815181106120e4576120e4614406565b602002602001015160200151868b898151811061210357612103614406565b6020026020010151606001516136c5565b9050612120818561442e565b9350876001600160a01b031686848151811061213e5761213e614406565b60200260200101515f01516001600160a01b0316886001600160a01b03167fd6d34547c69c5ee3d2667625c188acf1006abb93e0ee7cf03925c67cf776041389878151811061218f5761218f614406565b60200260200101516020015185876040516121bd939291909283526020830191909152604082015260600190565b60405180910390a450505b600101612057565b5f80808080806122007f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d8861317e565b9250925092508261221c575f805f95509550955050505061225e565b600b5481116122355760019550909350915061225e9050565b86156122545760405163e2b3ade560e01b815260040160405180910390fd5b5f95509093509150505b9193909250565b60405163065f566d60e01b81523060048201525f90829082906001600160a01b0383169063065f566d90602401602060405180830381865afa1580156122ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122d191906144b2565b6040516376a1021360e01b81523060048201529091505f906001600160a01b038416906376a1021390602401602060405180830381865afa158015612318573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061233c91906144b2565b9050612348818361442e565b95945050505050565b5f5b85518110156124d4575f86828151811061236f5761236f614406565b60209081029190910101515160405163065f566d60e01b81523060048201529091505f906001600160a01b0383169063065f566d90602401602060405180830381865afa1580156123c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123e691906144b2565b6040516376a1021360e01b81523060048201529091505f906001600160a01b038416906376a1021390602401602060405180830381865afa15801561242d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061245191906144b2565b90508115801561245f575080155b1561246c575050506124cc565b60405163cfddf5f560e01b815260048101839052600160248201526001600160a01b0384169063cfddf5f5906044015f604051808303815f87803b1580156124b2575f80fd5b505af11580156124c4573d5f803e3d5ffd5b505050505050505b600101612353565b506040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa158015612519573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061253d91906144b2565b90505f61254a84836145b7565b90505f61255886600a6145a9565b9050808211156125765783156125765761257688610aa483856145b7565b5050505050505050565b80515f036125a157604051635dc957f360e11b815260040160405180910390fd5b5f805b8251811015612795575f8382815181106125c0576125c0614406565b60200260200101515f015190505f8483815181106125e0576125e0614406565b60200260200101516020015190506125f782612a36565b806001600160601b03165f03612620576040516319a2a9bd60e01b815260040160405180910390fd5b5f5b855181101561268e57808414158015612668575085818151811061264857612648614406565b60200260200101515f01516001600160a01b0316836001600160a01b0316145b1561268657604051630148f8ab60e31b815260040160405180910390fd5b600101612622565b5060066040518060600160405280846001600160a01b03168152602001836001600160601b03168152602001846001600160a01b03166331b8c9466040518163ffffffff1660e01b8152600401602060405180830381865afa1580156126f6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061271a91906146c4565b6001600160a01b039081169091528254600180820185555f948552602094859020845195850151958416600160a01b6001600160601b039788160217600290930201918255604090930151920180546001600160a01b031916929091169190911790556127899082168561442e565b935050506001016125a4565b50612710811461158657604051639006dd2760e01b815260040160405180910390fd5b5f5b8251811015610aef575f8382815181106127d6576127d6614406565b602002602001015190505f61280582602001516001600160601b031661271086612ed19092919063ffffffff16565b9050801561286c578151604051630aeb4b9760e41b8152600481018390525f60248201526001600160a01b039091169063aeb4b970906044015f604051808303815f87803b158015612855575f80fd5b505af1158015612867573d5f803e3d5ffd5b505050505b50506001016127ba565b610e485f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00611ccf565b5f610ce16128ad836138ce565b6128b5610dbf565b6128c090600a6145a9565b8591908561391b565b610aef838383600161395d565b5f610bb5826001613093565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198114612944578181101561293657828183604051637dc7a0d960e11b815260040161107a93929190614683565b61294484848484035f61395d565b50505050565b6001600160a01b03831661297357604051634b637e8f60e11b81525f600482015260240161107a565b6001600160a01b03821661299c5760405163ec442f0560e01b81525f600482015260240161107a565b610aef838383613a21565b6129af613b34565b6005805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b5f80612a045f6121d0565b50509050801580612a17575060055460ff165b15612a2457505f92915050565b5f19610ce1565b5f610bb5825f6128a0565b6001600160a01b038116611b175760405163e6c4247b60e01b815260040160405180910390fd5b60055460ff1615610e485760405163d93c066560e01b815260040160405180910390fd5b5f80612a8d60016121d0565b92509250506115868282613b57565b5f610ce182612aad6127108261442e565b859190600161391b565b5f610bb5825f613093565b612aee7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d853085613bd6565b612af88382613c0f565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78484604051612b46929190918252602082015260400190565b60405180910390a350505050565b6040516001600160a01b03838116602483015260448201839052610aef91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613c43565b610e485f7f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df5706900611ccf565b600580546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b612c3e612a5d565b6005805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586129dc3390565b5f610bb58260016128a0565b5f610ce18383612710600161391b565b5f808080612ca08787612710612ed1565b90505f612cb08887612710612ed1565b905080612cbd838a6145b7565b612cc791906145b7565b9891975095509350505050565b5f80612cdf5f6121d0565b50509050801580612cf2575060055460ff165b15612cff57505f92915050565b5f612d0984613caf565b90505f612dc26006805480602002602001604051908101604052809291908181526020015f905b82821015612d92575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101612d30565b50505050612dbd7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d90565b6130d2565b905080821115612e09575f612dd5610dbf565b612de090600a6145a9565b905080821015612df557505f95945050505050565b612dff81836145b7565b9695505050505050565b509392505050565b826001600160a01b0316856001600160a01b031614612e3557612e358386836128e2565b612e3f8382613cd1565b612e6a7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d8584612b54565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8585604051612ec2929190918252602082015260400190565b60405180910390a45050505050565b5f838302815f1985870982811083820303915050805f03612f0557838281612efb57612efb6146df565b0492505050610ce1565b808411612f1c57612f1c6003851502601118613d05565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f80612f925f6121d0565b50509050801580612fa5575060055460ff165b15612fb257505f92915050565b5f612fbc84613caf565b90505f6130446006805480602002602001604051908101604052809291908181526020015f9082821015612d92575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b03168486015260019182015416918301919091529083529092019101612d30565b90508082111561308a575f613057610dbf565b61306290600a6145a9565b90508082101561307757505f95945050505050565b612dff61308482846145b7565b5f613093565b61234885613d16565b5f610ce161309f610dbf565b6130aa90600a6145a9565b6128c05f8560038111156130c0576130c06146f3565b146130cb575f6138ce565b60016138ce565b5f805b8351811015613117576131038482815181106130f3576130f3614406565b60200260200101515f0151612265565b61310d908361442e565b91506001016130d5565b506040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa15801561315a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115d691906144b2565b5f80807f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df57069005c156131f7575060019150507fb9119c9d507ab94e0f4429b4c7bbf0463ef7a3523c74e225b6641cfb04e67a005c7f93de9a8576a62ce59fcb637d8053d0e5fadcf7d26694489a7981d83007528a005c6133b6565b5f6132886006805480602002602001604051908101604052809291908181526020015f905b8282101561327e575f848152602090819020604080516060810182526002860290920180546001600160a01b038082168552600160a01b9091046001600160601b0316848601526001918201541691830191909152908352909201910161321c565b505050505f613d33565b600c549091506132a2906001600160a01b03168287613df0565b909450925083156133b457600c546001600160a01b031663ba8600336132c6610dbf565b6132d190600a6145a9565b6040516001600160e01b031960e084901b16815260048101919091526001600160a01b0389166024820152604401602060405180830381865afa925050508015613338575060408051601f3d908101601f19168201909252613335918101906144b2565b60015b613399573d808015613365576040519150601f19603f3d011682016040523d82523d5f602084013e61336a565b606091505b50851561338b578060405162461bcd60e51b815260040161107a919061425d565b505f93508391506133b69050565b6133b06133a86012600a614707565b859083612ed1565b9250505b505b9250925092565b5f6133cb8383612710612ed1565b610ce190846145b7565b80825d5050565b604080518082019091525f808252602082015260408084015190516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa158015613437573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061345b91906144b2565b9050821561348d57604051806040016040528085604001516001600160a01b0316815260200182815250915050610bd0565b83516040516311faa0d560e21b81523060048201525f916001600160a01b0316906347ea835490602401602060405180830381865afa1580156134d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906134f691906144b2565b8551604051637b4c628760e01b81523060048201529192505f916001600160a01b0390911690637b4c628790602401602060405180830381865afa158015613540573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061356491906144b2565b90505f83613572838561442e565b61357c919061442e565b6040805180820182529801516001600160a01b031688526020880152509495945050505050565b60405163ba86003360e01b8152600481018390526001600160a01b0384811660248301525f91829188169063ba86003390604401602060405180830381865afa1580156135f2573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061361691906144b2565b90505f6001600160a01b03881663ba86003361363386600a6145a9565b6040516001600160e01b031960e084901b16815260048101919091526001600160a01b038a166024820152604401602060405180830381865afa15801561367c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136a091906144b2565b90506136b96136b16012600a614707565b839083612ed1565b98975050505050505050565b6040516370a0823160e01b81523060048201525f90859082906001600160a01b038316906370a0823190602401602060405180830381865afa15801561370d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061373191906144b2565b60405163095ea7b360e01b81526001600160a01b038b81166004830152602482018990529192509089169063095ea7b3906044016020604051808303815f875af1158015613781573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137a59190614712565b505f808a6001600160a01b0316866040516137c09190614731565b5f604051808303815f865af19150503d805f81146137f9576040519150601f19603f3d011682016040523d82523d5f602084013e6137fe565b606091505b50915091508161382357806040516315fcd67560e01b815260040161107a919061425d565b6040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa158015613867573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061388b91906144b2565b90505f61389885836145b7565b9050888110156138be576040516377b8dde360e01b81526004810182905260240161107a565b9c9b505050505050505050505050565b5f806138d8611b3f565b5050509050610ce16138e8610dbf565b6138f390600a6145a9565b6138fe5f600a6145a9565b60025461390b919061442e565b8561391785600161442e565b9291905b5f61394861392883613f55565b801561394357505f848061393e5761393e6146df565b868809115b151590565b613953868686612ed1565b612348919061442e565b6001600160a01b0384166139865760405163e602df0560e01b81525f600482015260240161107a565b6001600160a01b0383166139af57604051634a1406b160e11b81525f600482015260240161107a565b6001600160a01b038085165f908152600160209081526040808320938716835292905220829055801561294457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051612b4691815260200190565b6001600160a01b038316613a4b578060025f828254613a40919061442e565b90915550613aa89050565b6001600160a01b0383165f9081526020819052604090205481811015613a8a5783818360405163391434e360e21b815260040161107a93929190614683565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b038216613ac457600280548290039055613ae2565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051613b2791815260200190565b60405180910390a3505050565b60055460ff16610e4857604051638dfc202b60e01b815260040160405180910390fd5b613b8260017f7f4a0d96299dae48c93382764b8799886298548aad0eae1e31f8351df5706900611ccf565b613bac827fb9119c9d507ab94e0f4429b4c7bbf0463ef7a3523c74e225b6641cfb04e67a00611ccf565b611586817f93de9a8576a62ce59fcb637d8053d0e5fadcf7d26694489a7981d83007528a00611ccf565b6040516001600160a01b0384811660248301528381166044830152606482018390526129449186918216906323b872dd90608401612b81565b6001600160a01b038216613c385760405163ec442f0560e01b81525f600482015260240161107a565b6115865f8383613a21565b5f8060205f8451602086015f885af180613c62576040513d5f823e3d81fd5b50505f513d91508115613c79578060011415613c86565b6001600160a01b0384163b155b1561294457604051635274afe760e01b81526001600160a01b038516600482015260240161107a565b6001600160a01b0381165f90815260208190526040812054610bb5905f6128a0565b6001600160a01b038216613cfa57604051634b637e8f60e11b81525f600482015260240161107a565b611586825f83613a21565b634e487b715f52806020526024601cfd5b6001600160a01b0381165f90815260208190526040812054610bb5565b6060825167ffffffffffffffff811115613d4f57613d4f613fc4565b604051908082528060200260200182016040528015613d9357816020015b604080518082019091525f8082526020820152815260200190600190039081613d6d5790505b5090505f5b8351811015613de957613dc4848281518110613db657613db6614406565b6020026020010151846133dc565b828281518110613dd657613dd6614406565b6020908102919091010152600101613d98565b5092915050565b5f805f5b8451811015613f4757848181518110613e0f57613e0f614406565b6020026020010151602001515f0315613f3f57856001600160a01b031663ba860033868381518110613e4357613e43614406565b602002602001015160200151878481518110613e6157613e61614406565b60200260200101515f01516040518363ffffffff1660e01b8152600401613e9b9291909182526001600160a01b0316602082015260400190565b602060405180830381865afa925050508015613ed4575060408051601f3d908101601f19168201909252613ed1918101906144b2565b60015b613f31573d808015613f01576040519150601f19603f3d011682016040523d82523d5f602084013e613f06565b606091505b508415613f27578060405162461bcd60e51b815260040161107a919061425d565b5f93505050613f4d565b613f3b818461442e565b9250505b600101613df4565b50600191505b935093915050565b5f6002826003811115613f6a57613f6a6146f3565b613f74919061474c565b60ff166001149050919050565b5080545f8255600202905f5260205f2090810190611b1791905b80821115613fc0575f81556001810180546001600160a01b0319169055600201613f9b565b5090565b634e487b7160e01b5f52604160045260245ffd5b6040516060810167ffffffffffffffff81118282101715613ffb57613ffb613fc4565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561402a5761402a613fc4565b604052919050565b6001600160a01b0381168114611b17575f80fd5b5f601f83601f840112614057575f80fd5b8235602067ffffffffffffffff8083111561407457614074613fc4565b8260051b614083838201614001565b938452868101830193838101908986111561409c575f80fd5b84890192505b85831015614174578235848111156140b8575f80fd5b89016060601f19828d0381018213156140cf575f80fd5b6140d7613fd8565b888401356140e481614032565b81526040848101358a830152928401359288841115614101575f80fd5b83850194508e603f860112614114575f80fd5b8985013593508884111561412a5761412a613fc4565b6141398a848e87011601614001565b92508383528e8185870101111561414e575f80fd5b838186018b8501375f9383018a01939093529182015283525091840191908401906140a2565b9998505050505050505050565b5f805f60408486031215614193575f80fd5b833567ffffffffffffffff808211156141aa575f80fd5b818601915086601f8301126141bd575f80fd5b8135818111156141cb575f80fd5b8760208260061b85010111156141df575f80fd5b6020928301955093509085013590808211156141f9575f80fd5b5061420686828701614046565b9150509250925092565b5f5b8381101561422a578181015183820152602001614212565b50505f910152565b5f8151808452614249816020860160208601614210565b601f01601f19169290920160200192915050565b602081525f610ce16020830184614232565b5f6020828403121561427f575f80fd5b5035919050565b5f8060408385031215614297575f80fd5b82356142a281614032565b946020939093013593505050565b5f80604083850312156142c1575f80fd5b50508035926020909101359150565b5f805f606084860312156142e2575f80fd5b83356142ed81614032565b925060208401356142fd81614032565b929592945050506040919091013590565b5f6020828403121561431e575f80fd5b8135610ce181614032565b5f806040838503121561433a575f80fd5b82359150602083013561434c81614032565b809150509250929050565b5f8060408385031215614368575f80fd5b823567ffffffffffffffff81111561437e575f80fd5b61438a85828601614046565b925050602083013561434c81614032565b5f805f606084860312156143ad575f80fd5b8335925060208401356143bf81614032565b915060408401356143cf81614032565b809150509250925092565b5f80604083850312156143eb575f80fd5b82356143f681614032565b9150602083013561434c81614032565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b80820180821115610bd057610bd061441a565b80356001600160601b0381168114610bb8575f80fd5b5f60408284031215614467575f80fd5b6040516040810181811067ffffffffffffffff8211171561448a5761448a613fc4565b604052823561449881614032565b81526144a660208401614441565b60208201529392505050565b5f602082840312156144c2575f80fd5b5051919050565b600181815b8085111561450357815f19048211156144e9576144e961441a565b808516156144f657918102915b93841c93908002906144ce565b509250929050565b5f8261451957506001610bd0565b8161452557505f610bd0565b816001811461453b576002811461454557614561565b6001915050610bd0565b60ff8411156145565761455661441a565b50506001821b610bd0565b5060208310610133831016604e8410600b8410161715614584575081810a610bd0565b61458e83836144c9565b805f19048211156145a1576145a161441a565b029392505050565b5f610ce160ff84168361450b565b81810381811115610bd057610bd061441a565b60208082528181018390525f90604080840186845b878110156146255781356145f281614032565b6001600160a01b031683526001600160601b03614610838701614441565b168386015291830191908301906001016145df565b5090979650505050505050565b600181811c9082168061464657607f821691505b60208210810361466457634e487b7160e01b5f52602260045260245ffd5b50919050565b60ff8181168382160190811115610bd057610bd061441a565b6001600160a01b039390931683526020830191909152604082015260600190565b5f602082840312156146b4575f80fd5b815160ff81168114610ce1575f80fd5b5f602082840312156146d4575f80fd5b8151610ce181614032565b634e487b7160e01b5f52601260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b5f610ce1838361450b565b5f60208284031215614722575f80fd5b81518015158114610ce1575f80fd5b5f8251614742818460208701614210565b9190910192915050565b5f60ff83168061476a57634e487b7160e01b5f52601260045260245ffd5b8060ff8416069150509291505056fea2646970667358221220a406d027cfa480b4133342409f222a5fe48e87be20fbcb3a40162946d712c21264736f6c63430008180033

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

0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000091f98acfd427401e661bb300f61480349202aaa00000000000000000000000002df68ea583b8394a8cc71eebcd4fa7c6746027d5000000000000000000000000000000000000000000000000000000000000000573426f6c64000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000573424f4c4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000005721cbbd64fc7ae3ef44a0a3f9a790a9264cf9bf0000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000009502b7c397e9aa22fe9db7ef7daf21cd2aebe56b0000000000000000000000000000000000000000000000000000000000001770000000000000000000000000d442e41019b7f5c4dd78f50dc03726c44614869500000000000000000000000000000000000000000000000000000000000003e8

-----Decoded View---------------
Arg [0] : _asset (address): 0x6440f144b7e50D6a8439336510312d2F54beB01D
Arg [1] : _name (string): sBold
Arg [2] : _symbol (string): sBOLD
Arg [3] : _sps (tuple[]):
Arg [1] : addr (address): 0x5721cbbd64fc7Ae3Ef44A0A3F9a790A9264Cf9BF
Arg [2] : weight (uint96): 3000

Arg [1] : addr (address): 0x9502b7c397E9aa22FE9dB7EF7DAF21cD2AEBe56B
Arg [2] : weight (uint96): 6000

Arg [1] : addr (address): 0xd442E41019B7F5C4dD78F50dc03726C446148695
Arg [2] : weight (uint96): 1000

Arg [4] : _priceOracle (address): 0x91F98Acfd427401E661Bb300f61480349202Aaa0
Arg [5] : _vault (address): 0x2dF68EA583B8394A8Cc71EeBcd4fA7c6746027D5

-----Encoded View---------------
17 Constructor Arguments found :
Arg [0] : 0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [4] : 00000000000000000000000091f98acfd427401e661bb300f61480349202aaa0
Arg [5] : 0000000000000000000000002df68ea583b8394a8cc71eebcd4fa7c6746027d5
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [7] : 73426f6c64000000000000000000000000000000000000000000000000000000
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [9] : 73424f4c44000000000000000000000000000000000000000000000000000000
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [11] : 0000000000000000000000005721cbbd64fc7ae3ef44a0a3f9a790a9264cf9bf
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000bb8
Arg [13] : 0000000000000000000000009502b7c397e9aa22fe9db7ef7daf21cd2aebe56b
Arg [14] : 0000000000000000000000000000000000000000000000000000000000001770
Arg [15] : 000000000000000000000000d442e41019b7f5c4dd78f50dc03726c446148695
Arg [16] : 00000000000000000000000000000000000000000000000000000000000003e8


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