ETH Price: $2,918.65 (-3.64%)
Gas: 1 Gwei

Contract

0xca1F1CB5eD09C33E6D618E476AcaF1C22525D636
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
0x60a06040191809952024-02-08 4:14:35151 days ago1707365675IN
 Create: BuyUnlockedProcessor
0 ETH0.1648104733.16716134

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
BuyUnlockedProcessor

Compiler Version
v0.8.22+commit.4fc1097e

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 36 : BuyUnlockedProcessor.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import {SafeERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {OrderProcessor, ITokenLockCheck} from "./OrderProcessor.sol";

/// @notice Contract managing market purchase orders for bridged assets with direct payment
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/orders/BuyUnlockedProcessor.sol)
/// This order processor emits market orders to buy the underlying asset that are good until cancelled
/// Fees are calculated upfront and held back from the order amount
/// The payment is taken by the operator before the order is filled
/// The operator can return unused payment to the user
/// The operator cannot cancel the order until payment is returned or the order is filled
/// Implicitly assumes that asset tokens are DShare and can be minted
/// Order lifecycle (fulfillment):
///   1. User requests an order (requestOrder)
///   2. Operator takes escrowed payment (takeEscrow)
///   3. [Optional] Operator partially fills the order (fillOrder)
///   4. Operator completely fulfills the order (fillOrder)
/// Order lifecycle (cancellation):
///   1. User requests an order (requestOrder)
///   2. Operator takes escrowed payment (takeEscrow)
///   3. [Optional] Operator partially fills the order (fillOrder)
///   4. [Optional] User requests cancellation (requestCancel)
///   5. Operator returns unused payment to contract (returnEscrow)
///   6. Operator cancels the order (cancelOrder)
contract BuyUnlockedProcessor is OrderProcessor {
    using SafeERC20 for IERC20;

    /// ------------------ Types ------------------ ///

    error NotBuyOrder();
    /// @dev Escrowed payment has been taken
    error UnreturnedEscrow();

    /// @dev Emitted when `amount` of escrowed payment is taken for order
    event EscrowTaken(uint256 indexed id, address indexed requester, uint256 amount);
    /// @dev Emitted when `amount` of escrowed payment is returned for order
    event EscrowReturned(uint256 indexed id, address indexed requester, uint256 amount);

    /// ------------------ State ------------------ ///

    struct BuyUnlockedProcessorStorage {
        // Order escrow tracking
        mapping(uint256 => uint256) _getOrderEscrow;
    }

    // keccak256(abi.encode(uint256(keccak256("dinaricrypto.storage.BuyUnlockedProcessor")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant BuyUnlockedProcessorStorageLocation =
        0x9ef2e27f0661cd1c5e17cad73e47154b2655f2434621cc5680ed2d93095efa00;

    function _getBuyUnlockedProcessorStorage() private pure returns (BuyUnlockedProcessorStorage storage $) {
        assembly {
            $.slot := BuyUnlockedProcessorStorageLocation
        }
    }

    /// ------------------ Getters ------------------ ///

    /// @notice Get the amount of payment token escrowed for an order
    /// @param id order id
    function getOrderEscrow(uint256 id) external view returns (uint256) {
        BuyUnlockedProcessorStorage storage $ = _getBuyUnlockedProcessorStorage();
        return $._getOrderEscrow[id];
    }

    /// ------------------ Order Lifecycle ------------------ ///

    /// @notice Take escrowed payment for an order
    /// @param id order id
    /// @param order Order
    /// @param amount Amount of escrowed payment token to take
    /// @dev Only callable by operator
    function takeEscrow(uint256 id, Order calldata order, uint256 amount) external onlyRole(OPERATOR_ROLE) {
        // No nonsense
        if (amount == 0) revert ZeroValue();
        // Verify order data
        bytes32 orderHash = _getOrderHash(id);
        if (orderHash != hashOrderCalldata(order)) revert InvalidOrderData();
        // Can't take more than escrowed
        BuyUnlockedProcessorStorage storage $ = _getBuyUnlockedProcessorStorage();
        uint256 escrow = $._getOrderEscrow[id];
        if (amount > escrow) revert AmountTooLarge();

        // Update escrow tracking
        $._getOrderEscrow[id] = escrow - amount;
        address requester = _getRequester(id);
        _decreaseEscrowedBalanceOf(order.paymentToken, requester, amount);
        // Notify escrow taken
        emit EscrowTaken(id, requester, amount);

        // Take escrowed payment
        IERC20(order.paymentToken).safeTransfer(msg.sender, amount);
    }

    /// @notice Return unused escrowed payment for an order
    /// @param id order id
    /// @param order Order
    /// @param amount Amount of payment token to return to escrow
    /// @dev Only callable by operator
    function returnEscrow(uint256 id, Order calldata order, uint256 amount) external onlyRole(OPERATOR_ROLE) {
        // No nonsense
        if (amount == 0) revert ZeroValue();
        // Verify order data
        bytes32 orderHash = _getOrderHash(id);
        if (orderHash != hashOrderCalldata(order)) revert InvalidOrderData();
        // Can only return unused amount
        uint256 unfilledAmount = getUnfilledAmount(id);
        BuyUnlockedProcessorStorage storage $ = _getBuyUnlockedProcessorStorage();
        uint256 escrow = $._getOrderEscrow[id];
        // Unused amount = remaining order - remaining escrow
        if (escrow + amount > unfilledAmount) revert AmountTooLarge();

        // Update escrow tracking
        $._getOrderEscrow[id] = escrow + amount;
        address requester = _getRequester(id);
        _increaseEscrowedBalanceOf(order.paymentToken, requester, amount);
        // Notify escrow returned
        emit EscrowReturned(id, requester, amount);

        // Return payment to escrow
        IERC20(order.paymentToken).safeTransferFrom(msg.sender, address(this), amount);
    }

    /// @inheritdoc OrderProcessor
    function _requestOrderAccounting(uint256 id, Order calldata order) internal virtual override {
        // Only buy orders
        if (order.sell) revert NotBuyOrder();
        // Compile standard buy order
        super._requestOrderAccounting(id, order);
        // Initialize escrow tracking for order
        BuyUnlockedProcessorStorage storage $ = _getBuyUnlockedProcessorStorage();
        $._getOrderEscrow[id] = order.paymentTokenQuantity;
    }

    /// @inheritdoc OrderProcessor
    function _fillOrderAccounting(
        uint256 id,
        Order calldata order,
        OrderState memory orderState,
        uint256 unfilledAmount,
        uint256 fillAmount,
        uint256 receivedAmount
    ) internal virtual override returns (uint256 paymentEarned, uint256 feesEarned) {
        // Can't fill more than payment previously taken from escrow
        BuyUnlockedProcessorStorage storage $ = _getBuyUnlockedProcessorStorage();
        uint256 escrow = $._getOrderEscrow[id];
        if (fillAmount > unfilledAmount - escrow) revert AmountTooLarge();

        paymentEarned = 0;
        (, feesEarned) = super._fillOrderAccounting(id, order, orderState, unfilledAmount, fillAmount, receivedAmount);
    }

    /// @inheritdoc OrderProcessor
    function _cancelOrderAccounting(
        uint256 id,
        Order calldata order,
        OrderState memory orderState,
        uint256 unfilledAmount
    ) internal virtual override returns (uint256 refund) {
        // Prohibit cancel if escrowed payment has been taken and not returned or filled
        BuyUnlockedProcessorStorage storage $ = _getBuyUnlockedProcessorStorage();
        uint256 escrow = $._getOrderEscrow[id];
        if (unfilledAmount != escrow) revert UnreturnedEscrow();

        // Clear the escrow record
        delete $._getOrderEscrow[id];

        // Standard buy order accounting
        refund = super._cancelOrderAccounting(id, order, orderState, unfilledAmount);
    }
}

File 2 of 36 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

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

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

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

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

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

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

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

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

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

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

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

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

File 3 of 36 : OrderProcessor.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import {
    UUPSUpgradeable,
    Initializable
} from "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import {
    AccessControlDefaultAdminRulesUpgradeable,
    AccessControlUpgradeable,
    IAccessControl
} from "openzeppelin-contracts-upgradeable/contracts/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol";
import {MulticallUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/utils/MulticallUpgradeable.sol";
import {SafeERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {mulDiv, mulDiv18} from "prb-math/Common.sol";
import {SelfPermit} from "../common/SelfPermit.sol";
import {IOrderProcessor} from "./IOrderProcessor.sol";
import {ITransferRestrictor} from "../ITransferRestrictor.sol";
import {DShare, IDShare} from "../DShare.sol";
import {ITokenLockCheck} from "../ITokenLockCheck.sol";
import {FeeLib} from "../common/FeeLib.sol";
import {IForwarder} from "../forwarder/IForwarder.sol";

/// @notice Base contract managing orders for bridged assets
/// Orders are submitted by users, emitted by the contract, and filled by operators
/// Fees are accumulated as order is filled
/// The incoming token is escrowed until the order is filled or cancelled
/// The incoming token is refunded if the order is cancelled
/// Implicitly assumes that asset tokens are dShare and can be burned
/// Order lifecycle (fulfillment):
///   1. User requests an order (requestOrder)
///   2. [Optional] Operator partially fills the order (fillOrder)
///   3. Operator completely fulfills the order (fillOrder)
/// Order lifecycle (cancellation):
///   1. User requests an order (requestOrder)
///   2. [Optional] Operator partially fills the order (fillOrder)
///   3. [Optional] User requests cancellation (requestCancel)
///   4. Operator cancels the order (cancelOrder)
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/orders/OrderProcessor.sol)
contract OrderProcessor is
    Initializable,
    UUPSUpgradeable,
    AccessControlDefaultAdminRulesUpgradeable,
    MulticallUpgradeable,
    SelfPermit,
    IOrderProcessor
{
    using SafeERC20 for IERC20;

    /// ------------------ Types ------------------ ///

    // Order state cleared after order is fulfilled or cancelled.
    struct OrderState {
        // Hash of order data used to validate order details stored offchain
        bytes32 orderHash;
        // Flat fee at time of order request
        uint256 flatFee;
        // Percentage fee rate at time of order request
        uint24 percentageFeeRate;
        // Account that requested the order
        address requester;
        // Whether a cancellation for this order has been initiated
        bool cancellationInitiated;
        // Total amount of received token due to fills
        uint256 received;
        // Total fees paid to treasury
        uint256 feesPaid;
        // Total fees paid to claim
        uint256 splitAmountPaid;
    }

    // Order state not cleared after order is fulfilled or cancelled.
    struct OrderInfo {
        // Amount of order token remaining to be used
        uint256 unfilledAmount;
        // Status of order
        OrderStatus status;
    }

    struct FeeRates {
        uint64 perOrderFeeBuy;
        uint24 percentageFeeRateBuy;
        uint64 perOrderFeeSell;
        uint24 percentageFeeRateSell;
    }

    struct FeeRatesStorage {
        bool set;
        uint64 perOrderFeeBuy;
        uint24 percentageFeeRateBuy;
        uint64 perOrderFeeSell;
        uint24 percentageFeeRateSell;
    }

    /// @dev Zero address
    error ZeroAddress();
    /// @dev Orders are paused
    error Paused();
    /// @dev Zero value
    error ZeroValue();
    /// @dev msg.sender is not order requester
    error NotRequester();
    /// @dev Order does not exist
    error OrderNotFound();
    /// @dev Invalid order data
    error InvalidOrderData();
    /// @dev Amount too large
    error AmountTooLarge();
    /// @dev Order type mismatch
    error OrderTypeMismatch();
    error UnsupportedToken(address token);
    /// @dev blacklist address
    error Blacklist();
    /// @dev Custom error when an order cancellation has already been initiated
    error OrderCancellationInitiated();
    /// @dev Thrown when assetTokenQuantity's precision doesn't match the expected precision in orderDecimals.
    error InvalidPrecision();
    error LimitPriceNotSet();
    error OrderFillBelowLimitPrice();
    error OrderFillAboveLimitPrice();

    /// @dev Emitted when `treasury` is set
    event TreasurySet(address indexed treasury);
    /// @dev Emitted when orders are paused/unpaused
    event OrdersPaused(bool paused);
    /// @dev Emitted when token lock check contract is set
    event TokenLockCheckSet(ITokenLockCheck indexed tokenLockCheck);
    /// @dev Emitted when fees are set
    event FeesSet(address indexed account, address indexed paymentToken, FeeRates feeRates);
    /// @dev Emitted when OrderDecimal is set
    event MaxOrderDecimalsSet(address indexed assetToken, int8 decimals);

    /// ------------------ Constants ------------------ ///

    /// @notice Operator role for filling and cancelling orders
    bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
    /// @notice Asset token role for whitelisting asset tokens
    /// @dev Tokens with decimals > 18 are not supported by current implementation
    bytes32 public constant ASSETTOKEN_ROLE = keccak256("ASSETTOKEN_ROLE");
    /// @notice Forwarder role for forwarding context awareness
    bytes32 public constant FORWARDER_ROLE = keccak256("FORWARDER_ROLE");

    /// ------------------ State ------------------ ///

    struct OrderProcessorStorage {
        // Address to receive fees
        address _treasury;
        // Transfer restrictor checker
        ITokenLockCheck _tokenLockCheck;
        // Are orders paused?
        bool _ordersPaused;
        // Total number of active orders. Onchain enumeration not supported.
        uint256 _numOpenOrders;
        // Next order id
        uint256 _nextOrderId;
        // Active order state
        mapping(uint256 => OrderState) _orders;
        // Persisted order state
        mapping(uint256 => OrderInfo) _orderInfo;
        // Escrowed balance of asset token per requester
        mapping(address => mapping(address => uint256)) _escrowedBalanceOf;
        // Max order decimals for asset token, defaults to 0 decimals
        mapping(address => int8) _maxOrderDecimals;
        // Fee schedule for requester, per paymentToken
        // Uses address(0) to store default fee schedule
        mapping(address => mapping(address => FeeRatesStorage)) _accountFees;
    }

    // keccak256(abi.encode(uint256(keccak256("dinaricrypto.storage.OrderProcessor")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OrderProcessorStorageLocation =
        0x8036d9ca2814a3bcd78d3e8aba96b71e7697006bd322a98e7f5f0f41b09a8b00;

    function _getOrderProcessorStorage() private pure returns (OrderProcessorStorage storage $) {
        assembly {
            $.slot := OrderProcessorStorageLocation
        }
    }

    /// ------------------ Initialization ------------------ ///

    /// @notice Initialize contract
    /// @param _owner Owner of contract
    /// @param _treasury Address to receive fees
    /// @param _tokenLockCheck Token lock check contract
    /// @dev Treasury cannot be zero address
    function initialize(address _owner, address _treasury, ITokenLockCheck _tokenLockCheck)
        public
        virtual
        initializer
    {
        __AccessControlDefaultAdminRules_init(0, _owner);
        __Multicall_init();

        // Don't send fees to zero address
        if (_treasury == address(0)) revert ZeroAddress();

        // Initialize
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._treasury = _treasury;
        $._tokenLockCheck = _tokenLockCheck;
    }

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function _authorizeUpgrade(address) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

    /// ------------------ Getters ------------------ ///

    /// @notice Address to receive fees
    function treasury() public view returns (address) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._treasury;
    }

    /// @notice Transfer restrictor checker
    function tokenLockCheck() public view returns (ITokenLockCheck) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._tokenLockCheck;
    }

    /// @notice Are orders paused?
    function ordersPaused() public view returns (bool) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._ordersPaused;
    }

    /// @inheritdoc IOrderProcessor
    function numOpenOrders() public view override returns (uint256) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._numOpenOrders;
    }

    /// @inheritdoc IOrderProcessor
    function nextOrderId() public view override returns (uint256) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._nextOrderId;
    }

    /// @inheritdoc IOrderProcessor
    function escrowedBalanceOf(address token, address requester) public view override returns (uint256) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._escrowedBalanceOf[token][requester];
    }

    /// @inheritdoc IOrderProcessor
    function maxOrderDecimals(address token) public view override returns (int8) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._maxOrderDecimals[token];
    }

    /// @inheritdoc IOrderProcessor
    function getOrderStatus(uint256 id) external view returns (OrderStatus) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._orderInfo[id].status;
    }

    /// @inheritdoc IOrderProcessor
    function getUnfilledAmount(uint256 id) public view returns (uint256) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._orderInfo[id].unfilledAmount;
    }

    /// @inheritdoc IOrderProcessor
    function getTotalReceived(uint256 id) public view returns (uint256) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._orders[id].received;
    }

    /// @notice Has order cancellation been requested?
    /// @param id Order ID
    function cancelRequested(uint256 id) external view returns (bool) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._orders[id].cancellationInitiated;
    }

    function hasRole(bytes32 role, address account)
        public
        view
        override(AccessControlUpgradeable, IAccessControl, IOrderProcessor)
        returns (bool)
    {
        return super.hasRole(role, account);
    }

    function getAccountFees(address account, address paymentToken) external view returns (FeeRates memory) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        FeeRatesStorage memory feeRates = $._accountFees[account][paymentToken];
        // If user,paymentToken does not have a custom fee schedule, use default
        if (!feeRates.set) {
            feeRates = $._accountFees[address(0)][paymentToken];
        }
        return FeeRates({
            perOrderFeeBuy: feeRates.perOrderFeeBuy,
            percentageFeeRateBuy: feeRates.percentageFeeRateBuy,
            perOrderFeeSell: feeRates.perOrderFeeSell,
            percentageFeeRateSell: feeRates.percentageFeeRateSell
        });
    }

    /// @inheritdoc IOrderProcessor
    function getFeeRatesForOrder(address requester, bool sell, address paymentToken)
        public
        view
        returns (uint256, uint24)
    {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        FeeRatesStorage memory feeRates = $._accountFees[requester][paymentToken];
        // If user does not have a custom fee schedule, use default
        if (!feeRates.set) {
            feeRates = $._accountFees[address(0)][paymentToken];
        }
        if (sell) {
            return (FeeLib.flatFeeForOrder(paymentToken, feeRates.perOrderFeeSell), feeRates.percentageFeeRateSell);
        } else {
            return (FeeLib.flatFeeForOrder(paymentToken, feeRates.perOrderFeeBuy), feeRates.percentageFeeRateBuy);
        }
    }

    /// @inheritdoc IOrderProcessor
    function estimateTotalFeesForOrder(
        address requester,
        bool sell,
        address paymentToken,
        uint256 paymentTokenOrderValue
    ) public view returns (uint256) {
        // Get fee rates
        (uint256 flatFee, uint24 percentageFeeRate) = getFeeRatesForOrder(requester, sell, paymentToken);
        // Calculate total fees
        return FeeLib.estimateTotalFees(flatFee, percentageFeeRate, paymentTokenOrderValue);
    }

    /// ------------------ Administration ------------------ ///

    /// @dev Check if orders are paused
    modifier whenOrdersNotPaused() {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        if ($._ordersPaused) revert Paused();
        _;
    }

    /// @notice Set treasury address
    /// @param account Address to receive fees
    /// @dev Only callable by admin
    /// Treasury cannot be zero address
    function setTreasury(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
        // Don't send fees to zero address
        if (account == address(0)) revert ZeroAddress();

        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._treasury = account;
        emit TreasurySet(account);
    }

    /// @notice Pause/unpause orders
    /// @param pause Pause orders if true, unpause if false
    /// @dev Only callable by admin
    function setOrdersPaused(bool pause) external onlyRole(DEFAULT_ADMIN_ROLE) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._ordersPaused = pause;
        emit OrdersPaused(pause);
    }

    /// @notice Set token lock check contract
    /// @param _tokenLockCheck Token lock check contract
    /// @dev Only callable by admin
    function setTokenLockCheck(ITokenLockCheck _tokenLockCheck) external onlyRole(DEFAULT_ADMIN_ROLE) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._tokenLockCheck = _tokenLockCheck;
        emit TokenLockCheckSet(_tokenLockCheck);
    }

    /// @notice Set default fee rates
    /// @param paymentToken Payment token
    /// @param feeRates Fee rates
    /// @dev Only callable by admin
    function setDefaultFees(address paymentToken, FeeRates memory feeRates) external onlyRole(DEFAULT_ADMIN_ROLE) {
        _setFees(address(0), paymentToken, feeRates);
    }

    /// @notice Set unique fee rates for requester
    /// @param requester Requester address
    /// @param paymentToken Payment token
    /// @param feeRates Fee rates
    /// @dev Only callable by admin
    function setFees(address requester, address paymentToken, FeeRates memory feeRates)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        if (requester == address(0)) revert ZeroAddress();
        _setFees(requester, paymentToken, feeRates);
    }

    /// @notice Reset fee rates for requester to default
    /// @param requester Requester address
    /// @param paymentToken Payment token
    /// @dev Only callable by admin
    function resetFees(address requester, address paymentToken) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (requester == address(0)) revert ZeroAddress();

        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        delete $._accountFees[requester][paymentToken];
        FeeRatesStorage memory defaultFeeRates = $._accountFees[address(0)][paymentToken];
        emit FeesSet(
            requester,
            paymentToken,
            FeeRates({
                perOrderFeeBuy: defaultFeeRates.perOrderFeeBuy,
                percentageFeeRateBuy: defaultFeeRates.percentageFeeRateBuy,
                perOrderFeeSell: defaultFeeRates.perOrderFeeSell,
                percentageFeeRateSell: defaultFeeRates.percentageFeeRateSell
            })
        );
    }

    function _setFees(address account, address paymentToken, FeeRates memory feeRates) private {
        FeeLib.checkPercentageFeeRate(feeRates.percentageFeeRateBuy);
        FeeLib.checkPercentageFeeRate(feeRates.percentageFeeRateSell);

        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._accountFees[account][paymentToken] = FeeRatesStorage({
            set: true,
            perOrderFeeBuy: feeRates.perOrderFeeBuy,
            percentageFeeRateBuy: feeRates.percentageFeeRateBuy,
            perOrderFeeSell: feeRates.perOrderFeeSell,
            percentageFeeRateSell: feeRates.percentageFeeRateSell
        });
        emit FeesSet(account, paymentToken, feeRates);
    }

    /// @notice Set max order decimals for asset token
    /// @param token Asset token
    /// @param decimals Max order decimals
    /// @dev Only callable by admin
    function setMaxOrderDecimals(address token, int8 decimals) external onlyRole(DEFAULT_ADMIN_ROLE) {
        uint8 tokenDecimals = IERC20Metadata(token).decimals();
        if (decimals > int8(tokenDecimals)) revert InvalidPrecision();
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._maxOrderDecimals[token] = decimals;
        emit MaxOrderDecimalsSet(token, decimals);
    }

    /// ------------------ Order Lifecycle ------------------ ///

    /// @inheritdoc IOrderProcessor
    function requestOrder(Order calldata order) public whenOrdersNotPaused returns (uint256 id) {
        // cheap checks first
        if (order.recipient == address(0)) revert ZeroAddress();
        uint256 orderAmount = (order.sell) ? order.assetTokenQuantity : order.paymentTokenQuantity;
        // No zero orders
        if (orderAmount == 0) revert ZeroValue();
        if (order.splitAmount > 0 && order.splitRecipient == address(0)) revert ZeroAddress();

        OrderProcessorStorage storage $ = _getOrderProcessorStorage();

        // Precision checked for assetTokenQuantity, market buys excluded
        if (order.sell || order.orderType == OrderType.LIMIT) {
            // Check for max order decimals (assetTokenQuantity)
            uint8 assetTokenDecimals = IERC20Metadata(order.assetToken).decimals();
            uint256 assetPrecision = 10 ** uint8(int8(assetTokenDecimals) - $._maxOrderDecimals[order.assetToken]);
            if (order.assetTokenQuantity % assetPrecision != 0) revert InvalidPrecision();
        }

        // Check for whitelisted tokens
        if (!hasRole(ASSETTOKEN_ROLE, order.assetToken)) revert UnsupportedToken(order.assetToken);
        if (!$._accountFees[address(0)][order.paymentToken].set) revert UnsupportedToken(order.paymentToken);
        // Cache order id
        id = $._nextOrderId;
        // Check requester
        address requester = getRequester(id);
        if (requester == address(0)) revert ZeroAddress();
        // black list checker
        blackListCheck(order.assetToken, order.paymentToken, order.recipient, requester);

        // Update next order id
        $._nextOrderId = id + 1;

        // Check values
        _requestOrderAccounting(id, order);

        // Send order to bridge
        emit OrderRequested(id, requester, order);

        // Calculate fees
        (uint256 flatFee, uint24 percentageFeeRate) = getFeeRatesForOrder(requester, order.sell, order.paymentToken);
        // Initialize order state
        $._orders[id] = OrderState({
            orderHash: hashOrder(order),
            requester: requester,
            flatFee: flatFee,
            percentageFeeRate: percentageFeeRate,
            received: 0,
            feesPaid: 0,
            cancellationInitiated: false,
            splitAmountPaid: 0
        });
        $._orderInfo[id] = OrderInfo({unfilledAmount: orderAmount, status: OrderStatus.ACTIVE});
        $._numOpenOrders++;

        if (order.sell) {
            // update escrowed balance
            $._escrowedBalanceOf[order.assetToken][order.recipient] += order.assetTokenQuantity;

            // Transfer asset to contract
            IERC20(order.assetToken).safeTransferFrom(msg.sender, address(this), order.assetTokenQuantity);
        } else {
            uint256 totalFees = FeeLib.estimateTotalFees(flatFee, percentageFeeRate, order.paymentTokenQuantity);
            uint256 quantityIn = order.paymentTokenQuantity + totalFees;
            // update escrowed balance
            $._escrowedBalanceOf[order.paymentToken][order.recipient] += quantityIn;

            // Escrow payment for purchase
            IERC20(order.paymentToken).safeTransferFrom(msg.sender, address(this), quantityIn);
        }
    }

    function getRequester(uint256 id) internal view returns (address) {
        // Determine true requester
        if (hasRole(FORWARDER_ROLE, msg.sender)) {
            // If order was requested by a forwarder, use the forwarder's requester on file
            return IForwarder(msg.sender).orderSigner(id);
        }
        return msg.sender;
    }

    /// @notice Hash order data for validation
    function hashOrder(Order memory order) public pure returns (bytes32) {
        return keccak256(
            abi.encode(
                order.recipient,
                order.assetToken,
                order.paymentToken,
                order.sell,
                order.orderType,
                order.assetTokenQuantity,
                order.paymentTokenQuantity,
                order.price,
                order.tif,
                order.splitRecipient,
                order.splitAmount
            )
        );
    }

    /// @notice Hash order data for validation
    function hashOrderCalldata(Order calldata order) public pure returns (bytes32) {
        return keccak256(
            abi.encode(
                order.recipient,
                order.assetToken,
                order.paymentToken,
                order.sell,
                order.orderType,
                order.assetTokenQuantity,
                order.paymentTokenQuantity,
                order.price,
                order.tif,
                order.splitRecipient,
                order.splitAmount
            )
        );
    }

    /// @inheritdoc IOrderProcessor
    // slither-disable-next-line cyclomatic-complexity
    function fillOrder(uint256 id, Order calldata order, uint256 fillAmount, uint256 receivedAmount)
        external
        onlyRole(OPERATOR_ROLE)
    {
        // No nonsense
        if (fillAmount == 0) revert ZeroValue();

        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        OrderState memory orderState = $._orders[id];

        // Order must exist
        if (orderState.requester == address(0)) revert OrderNotFound();
        // Verify order data
        if (orderState.orderHash != hashOrderCalldata(order)) revert InvalidOrderData();
        // Fill cannot exceed remaining order
        OrderInfo memory orderInfo = $._orderInfo[id];
        if (fillAmount > orderInfo.unfilledAmount) revert AmountTooLarge();

        // Calculate earned fees and handle any unique checks
        (uint256 paymentEarned, uint256 feesEarned) =
            _fillOrderAccounting(id, order, orderState, orderInfo.unfilledAmount, fillAmount, receivedAmount);

        // Notify order filled
        emit OrderFill(
            id, orderState.requester, order.paymentToken, order.assetToken, fillAmount, receivedAmount, feesEarned
        );

        // Take splitAmount from amount to distribute
        uint256 splitAmountEarned = 0;
        if (order.splitAmount > 0) {
            if (orderState.splitAmountPaid < order.splitAmount) {
                uint256 amountToDistribute = order.sell ? paymentEarned : receivedAmount;
                uint256 splitAmountRemaining = order.splitAmount - orderState.splitAmountPaid;
                if (amountToDistribute > splitAmountRemaining) {
                    splitAmountEarned = splitAmountRemaining;
                } else {
                    splitAmountEarned = amountToDistribute;
                }
            }
        }

        // Update order state
        _updateOrderStateForFill(
            id,
            orderInfo.unfilledAmount,
            orderState,
            order.sell,
            order.paymentTokenQuantity,
            fillAmount,
            receivedAmount,
            feesEarned,
            splitAmountEarned
        );

        // Move tokens
        if (order.sell) {
            // update escrowed balance
            $._escrowedBalanceOf[order.assetToken][order.recipient] -= fillAmount;
            // Burn the filled quantity from the asset token
            IDShare(order.assetToken).burn(fillAmount);

            // Transfer the received amount from the filler to this contract
            IERC20(order.paymentToken).safeTransferFrom(msg.sender, address(this), receivedAmount);

            // Send split amount first
            if (splitAmountEarned > 0) {
                IERC20(order.paymentToken).safeTransfer(order.splitRecipient, splitAmountEarned);
            }

            // If there are proceeds from the order, transfer them to the recipient
            uint256 proceeds = paymentEarned - splitAmountEarned;
            if (proceeds > 0) {
                IERC20(order.paymentToken).safeTransfer(order.recipient, proceeds);
            }
        } else {
            // update escrowed balance
            $._escrowedBalanceOf[order.paymentToken][order.recipient] -= paymentEarned + feesEarned;
            // Claim payment
            IERC20(order.paymentToken).safeTransfer(msg.sender, paymentEarned);

            // Send split amount first
            if (splitAmountEarned > 0) {
                IDShare(order.assetToken).mint(order.recipient, splitAmountEarned);
            }

            // Mint asset
            uint256 proceeds = receivedAmount - splitAmountEarned;
            if (proceeds > 0) {
                IDShare(order.assetToken).mint(order.recipient, proceeds);
            }
        }

        // If there are protocol fees from the order, transfer them to the treasury
        if (feesEarned > 0) {
            IERC20(order.paymentToken).safeTransfer($._treasury, feesEarned);
        }
    }

    function _updateOrderStateForFill(
        uint256 id,
        uint256 unfilledAmount,
        OrderState memory orderState,
        bool sell,
        uint256 orderPaymentTokenQuantity,
        uint256 fillAmount,
        uint256 receivedAmount,
        uint256 feesEarned,
        uint256 splitAmountEarned
    ) private {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        uint256 newUnfilledAmount = unfilledAmount - fillAmount;
        $._orderInfo[id].unfilledAmount = newUnfilledAmount;
        // If order is completely filled then clear order state
        if (newUnfilledAmount == 0) {
            $._orderInfo[id].status = OrderStatus.FULFILLED;
            // Clear order state
            delete $._orders[id];
            $._numOpenOrders--;
            // Notify order fulfilled
            emit OrderFulfilled(id, orderState.requester);
        } else {
            // Otherwise update order state
            uint256 feesPaid = orderState.feesPaid + feesEarned;
            // Check values
            if (!sell) {
                uint256 estimatedTotalFees = FeeLib.estimateTotalFees(
                    orderState.flatFee, orderState.percentageFeeRate, orderPaymentTokenQuantity
                );
                assert(feesPaid <= estimatedTotalFees);
            }
            $._orders[id].received = orderState.received + receivedAmount;
            $._orders[id].feesPaid = feesPaid;
            if (splitAmountEarned > 0) {
                $._orders[id].splitAmountPaid = orderState.splitAmountPaid + splitAmountEarned;
            }
        }
    }

    function blackListCheck(address assetToken, address paymentToken, address recipient, address sender)
        internal
        view
    {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        ITokenLockCheck _tokenLockCheck = $._tokenLockCheck;
        if (_tokenLockCheck.isTransferLocked(assetToken, recipient)) revert Blacklist();
        if (_tokenLockCheck.isTransferLocked(assetToken, sender)) revert Blacklist();
        if (_tokenLockCheck.isTransferLocked(paymentToken, recipient)) revert Blacklist();
        if (_tokenLockCheck.isTransferLocked(paymentToken, sender)) revert Blacklist();
    }

    /// @notice Request to cancel an order
    /// @param id Order id
    /// @dev Only callable by initial order requester
    /// @dev Emits CancelRequested event to be sent to fulfillment service (operator)
    function requestCancel(uint256 id) external {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        if ($._orders[id].cancellationInitiated) revert OrderCancellationInitiated();
        // Order must exist
        address requester = $._orders[id].requester;
        if (requester == address(0)) revert OrderNotFound();
        // Get cancel requester
        address cancelRequester = getRequester(id);
        // Only requester can request cancellation
        if (requester != cancelRequester) revert NotRequester();

        $._orders[id].cancellationInitiated = true;

        // Send cancel request to bridge
        emit CancelRequested(id, requester);
    }

    /// @notice Cancel an order
    /// @param order Order to cancel
    /// @param id Order id
    /// @param reason Reason for cancellation
    /// @dev Only callable by operator
    function cancelOrder(uint256 id, Order calldata order, string calldata reason) external onlyRole(OPERATOR_ROLE) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        OrderState memory orderState = $._orders[id];
        // Order must exist
        if (orderState.requester == address(0)) revert OrderNotFound();
        // Verify order data
        if (orderState.orderHash != hashOrderCalldata(order)) revert InvalidOrderData();

        // Order is cancelled
        $._orderInfo[id].status = OrderStatus.CANCELLED;
        // Clear order state

        delete $._orders[id];
        $._numOpenOrders--;

        // Notify order cancelled
        emit OrderCancelled(id, orderState.requester, reason);

        // Calculate refund
        uint256 refund = _cancelOrderAccounting(id, order, orderState, $._orderInfo[id].unfilledAmount);

        address refundToken = (order.sell) ? order.assetToken : order.paymentToken;
        // update escrowed balance
        $._escrowedBalanceOf[refundToken][order.recipient] -= refund;

        // Return escrow
        IERC20(refundToken).safeTransfer(orderState.requester, refund);
    }

    /// ------------------ Virtuals ------------------ ///

    function _getOrderHash(uint256 id) internal view returns (bytes32) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._orders[id].orderHash;
    }

    function _getRequester(uint256 id) internal view returns (address) {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        return $._orders[id].requester;
    }

    function _increaseEscrowedBalanceOf(address token, address user, uint256 amount) internal {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._escrowedBalanceOf[token][user] += amount;
    }

    function _decreaseEscrowedBalanceOf(address token, address user, uint256 amount) internal {
        OrderProcessorStorage storage $ = _getOrderProcessorStorage();
        $._escrowedBalanceOf[token][user] -= amount;
    }

    /// @notice Perform any unique order request checks and accounting
    /// @param id Order ID
    /// @param order Order request to process
    function _requestOrderAccounting(uint256 id, Order calldata order) internal virtual {
        // Ensure that price is set for limit orders
        if (order.orderType == OrderType.LIMIT && order.price == 0) revert LimitPriceNotSet();
    }

    /// @notice Handle any unique order accounting and checks
    /// @param id Order ID
    /// @param order Order to fill
    /// @param orderState Order state
    /// @param unfilledAmount Amount of order token remaining to be used
    /// @param fillAmount Amount of order token filled
    /// @param receivedAmount Amount of received token
    /// @return paymentEarned Amount of payment token earned to be paid to operator or recipient
    /// @return feesEarned Amount of fees earned to be paid to treasury
    function _fillOrderAccounting(
        uint256 id,
        Order calldata order,
        OrderState memory orderState,
        uint256 unfilledAmount,
        uint256 fillAmount,
        uint256 receivedAmount
    ) internal virtual returns (uint256 paymentEarned, uint256 feesEarned) {
        if (order.sell) {
            // For limit sell orders, ensure that the received amount is greater or equal to limit price * fill amount, order price has ether decimals
            if (order.orderType == OrderType.LIMIT && receivedAmount < mulDiv18(fillAmount, order.price)) {
                revert OrderFillAboveLimitPrice();
            }

            // Fees - earn up to the flat fee, then earn percentage fee on the remainder
            // TODO: make sure that all fees are taken at total fill to prevent dust accumulating here
            // Determine the subtotal used to calculate the percentage fee
            uint256 subtotal = 0;
            // If the flat fee hasn't been fully covered yet, ...
            if (orderState.feesPaid < orderState.flatFee) {
                // How much of the flat fee is left to cover?
                uint256 flatFeeRemaining = orderState.flatFee - orderState.feesPaid;
                // If the amount subject to fees is greater than the remaining flat fee, ...
                if (receivedAmount > flatFeeRemaining) {
                    // Earn the remaining flat fee
                    feesEarned = flatFeeRemaining;
                    // Calculate the subtotal by subtracting the remaining flat fee from the amount subject to fees
                    subtotal = receivedAmount - flatFeeRemaining;
                } else {
                    // Otherwise, earn the amount subject to fees
                    feesEarned = receivedAmount;
                }
            } else {
                // If the flat fee has been fully covered, the subtotal is the entire fill amount
                subtotal = receivedAmount;
            }

            // Calculate the percentage fee on the subtotal
            if (subtotal > 0 && orderState.percentageFeeRate > 0) {
                feesEarned += mulDiv18(subtotal, orderState.percentageFeeRate);
            }

            paymentEarned = receivedAmount - feesEarned;
        } else {
            // For limit buy orders, ensure that the received amount is greater or equal to fill amount / limit price, order price has ether decimals
            if (order.orderType == OrderType.LIMIT && receivedAmount < mulDiv(fillAmount, 1 ether, order.price)) {
                revert OrderFillBelowLimitPrice();
            }

            paymentEarned = fillAmount;
            // Fees - earn the flat fee if first fill, then earn percentage fee on the fill
            feesEarned = 0;
            if (orderState.feesPaid == 0) {
                feesEarned = orderState.flatFee;
            }
            uint256 estimatedTotalFees =
                FeeLib.estimateTotalFees(orderState.flatFee, orderState.percentageFeeRate, order.paymentTokenQuantity);
            uint256 totalPercentageFees = estimatedTotalFees - orderState.flatFee;
            feesEarned += mulDiv(totalPercentageFees, fillAmount, order.paymentTokenQuantity);
        }
    }

    /// @notice Move tokens for order cancellation including fees and escrow
    /// @param id Order ID
    /// @param order Order to cancel
    /// @param orderState Order state
    /// @param unfilledAmount Amount of order token remaining to be used
    /// @return refund Amount of order token to refund to user
    function _cancelOrderAccounting(
        uint256 id,
        Order calldata order,
        OrderState memory orderState,
        uint256 unfilledAmount
    ) internal virtual returns (uint256 refund) {
        if (order.sell) {
            refund = unfilledAmount;
        } else {
            uint256 totalFees =
                FeeLib.estimateTotalFees(orderState.flatFee, orderState.percentageFeeRate, order.paymentTokenQuantity);
            // If no fills, then full refund
            refund = unfilledAmount + totalFees;
            if (refund < order.paymentTokenQuantity + totalFees) {
                // Refund remaining order and fees
                refund -= orderState.feesPaid;
            }
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

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

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

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

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

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

File 7 of 36 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.20;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

File 8 of 36 : AccessControlDefaultAdminRulesUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlDefaultAdminRules.sol)

pragma solidity ^0.8.20;

import {IAccessControlDefaultAdminRules} from "@openzeppelin/contracts/access/extensions/IAccessControlDefaultAdminRules.sol";
import {AccessControlUpgradeable} from "../AccessControlUpgradeable.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IERC5313} from "@openzeppelin/contracts/interfaces/IERC5313.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";

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

        uint48 _currentDelay;
        address _currentDefaultAdmin;

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

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControlDefaultAdminRules")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant AccessControlDefaultAdminRulesStorageLocation = 0xeef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698400;

    function _getAccessControlDefaultAdminRulesStorage() private pure returns (AccessControlDefaultAdminRulesStorage storage $) {
        assembly {
            $.slot := AccessControlDefaultAdminRulesStorageLocation
        }
    }

    /**
     * @dev Sets the initial values for {defaultAdminDelay} and {defaultAdmin} address.
     */
    function __AccessControlDefaultAdminRules_init(uint48 initialDelay, address initialDefaultAdmin) internal onlyInitializing {
        __AccessControlDefaultAdminRules_init_unchained(initialDelay, initialDefaultAdmin);
    }

    function __AccessControlDefaultAdminRules_init_unchained(uint48 initialDelay, address initialDefaultAdmin) internal onlyInitializing {
        AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage();
        if (initialDefaultAdmin == address(0)) {
            revert AccessControlInvalidDefaultAdmin(address(0));
        }
        $._currentDelay = initialDelay;
        _grantRole(DEFAULT_ADMIN_ROLE, initialDefaultAdmin);
    }

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

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

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

    /**
     * @dev See {AccessControl-grantRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function grantRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControl) {
        if (role == DEFAULT_ADMIN_ROLE) {
            revert AccessControlEnforcedDefaultAdminRules();
        }
        super.grantRole(role, account);
    }

    /**
     * @dev See {AccessControl-revokeRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function revokeRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControl) {
        if (role == DEFAULT_ADMIN_ROLE) {
            revert AccessControlEnforcedDefaultAdminRules();
        }
        super.revokeRole(role, account);
    }

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

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

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

    /**
     * @dev See {AccessControl-_setRoleAdmin}. Reverts for `DEFAULT_ADMIN_ROLE`.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual override {
        if (role == DEFAULT_ADMIN_ROLE) {
            revert AccessControlEnforcedDefaultAdminRules();
        }
        super._setRoleAdmin(role, adminRole);
    }

    ///
    /// AccessControlDefaultAdminRules accessors
    ///

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function defaultAdmin() public view virtual returns (address) {
        AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage();
        return $._currentDefaultAdmin;
    }

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

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

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

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

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

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

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

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

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

    /**
     * @inheritdoc IAccessControlDefaultAdminRules
     */
    function acceptDefaultAdminTransfer() public virtual {
        (address newDefaultAdmin, ) = pendingDefaultAdmin();
        if (_msgSender() != newDefaultAdmin) {
            // Enforce newDefaultAdmin explicit acceptance.
            revert AccessControlInvalidDefaultAdmin(_msgSender());
        }
        _acceptDefaultAdminTransfer();
    }

    /**
     * @dev See {acceptDefaultAdminTransfer}.
     *
     * Internal function without access restriction.
     */
    function _acceptDefaultAdminTransfer() internal virtual {
        AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage();
        (address newAdmin, uint48 schedule) = pendingDefaultAdmin();
        if (!_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
            revert AccessControlEnforcedDefaultAdminDelay(schedule);
        }
        _revokeRole(DEFAULT_ADMIN_ROLE, defaultAdmin());
        _grantRole(DEFAULT_ADMIN_ROLE, newAdmin);
        delete $._pendingDefaultAdmin;
        delete $._pendingDefaultAdminSchedule;
    }

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

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

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

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

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

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

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

    ///
    /// Private setters
    ///

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

        $._pendingDefaultAdmin = newAdmin;
        $._pendingDefaultAdminSchedule = newSchedule;

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

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

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

        $._pendingDelay = newDelay;
        $._pendingDelaySchedule = newSchedule;
    }

    ///
    /// Private helpers
    ///

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

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

File 9 of 36 : MulticallUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Multicall.sol)

pragma solidity ^0.8.20;

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Provides a function to batch together multiple calls in a single external call.
 */
abstract contract MulticallUpgradeable is Initializable {
    function __Multicall_init() internal onlyInitializing {
    }

    function __Multicall_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Receives and executes a batch of function calls on this contract.
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), data[i]);
        }
        return results;
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

File 11 of 36 : Common.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;

// Common.sol
//
// Common mathematical functions needed by both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.

/*//////////////////////////////////////////////////////////////////////////
                                CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/

/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);

/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);

/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();

/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);

/*//////////////////////////////////////////////////////////////////////////
                                    CONSTANTS
//////////////////////////////////////////////////////////////////////////*/

/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;

/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;

/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;

/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;

/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;

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

/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
    unchecked {
        // Start from 0.5 in the 192.64-bit fixed-point format.
        result = 0x800000000000000000000000000000000000000000000000;

        // The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
        //
        // 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
        // 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
        // a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
        // we know that `x & 0xFF` is also 1.
        if (x & 0xFF00000000000000 > 0) {
            if (x & 0x8000000000000000 > 0) {
                result = (result * 0x16A09E667F3BCC909) >> 64;
            }
            if (x & 0x4000000000000000 > 0) {
                result = (result * 0x1306FE0A31B7152DF) >> 64;
            }
            if (x & 0x2000000000000000 > 0) {
                result = (result * 0x1172B83C7D517ADCE) >> 64;
            }
            if (x & 0x1000000000000000 > 0) {
                result = (result * 0x10B5586CF9890F62A) >> 64;
            }
            if (x & 0x800000000000000 > 0) {
                result = (result * 0x1059B0D31585743AE) >> 64;
            }
            if (x & 0x400000000000000 > 0) {
                result = (result * 0x102C9A3E778060EE7) >> 64;
            }
            if (x & 0x200000000000000 > 0) {
                result = (result * 0x10163DA9FB33356D8) >> 64;
            }
            if (x & 0x100000000000000 > 0) {
                result = (result * 0x100B1AFA5ABCBED61) >> 64;
            }
        }

        if (x & 0xFF000000000000 > 0) {
            if (x & 0x80000000000000 > 0) {
                result = (result * 0x10058C86DA1C09EA2) >> 64;
            }
            if (x & 0x40000000000000 > 0) {
                result = (result * 0x1002C605E2E8CEC50) >> 64;
            }
            if (x & 0x20000000000000 > 0) {
                result = (result * 0x100162F3904051FA1) >> 64;
            }
            if (x & 0x10000000000000 > 0) {
                result = (result * 0x1000B175EFFDC76BA) >> 64;
            }
            if (x & 0x8000000000000 > 0) {
                result = (result * 0x100058BA01FB9F96D) >> 64;
            }
            if (x & 0x4000000000000 > 0) {
                result = (result * 0x10002C5CC37DA9492) >> 64;
            }
            if (x & 0x2000000000000 > 0) {
                result = (result * 0x1000162E525EE0547) >> 64;
            }
            if (x & 0x1000000000000 > 0) {
                result = (result * 0x10000B17255775C04) >> 64;
            }
        }

        if (x & 0xFF0000000000 > 0) {
            if (x & 0x800000000000 > 0) {
                result = (result * 0x1000058B91B5BC9AE) >> 64;
            }
            if (x & 0x400000000000 > 0) {
                result = (result * 0x100002C5C89D5EC6D) >> 64;
            }
            if (x & 0x200000000000 > 0) {
                result = (result * 0x10000162E43F4F831) >> 64;
            }
            if (x & 0x100000000000 > 0) {
                result = (result * 0x100000B1721BCFC9A) >> 64;
            }
            if (x & 0x80000000000 > 0) {
                result = (result * 0x10000058B90CF1E6E) >> 64;
            }
            if (x & 0x40000000000 > 0) {
                result = (result * 0x1000002C5C863B73F) >> 64;
            }
            if (x & 0x20000000000 > 0) {
                result = (result * 0x100000162E430E5A2) >> 64;
            }
            if (x & 0x10000000000 > 0) {
                result = (result * 0x1000000B172183551) >> 64;
            }
        }

        if (x & 0xFF00000000 > 0) {
            if (x & 0x8000000000 > 0) {
                result = (result * 0x100000058B90C0B49) >> 64;
            }
            if (x & 0x4000000000 > 0) {
                result = (result * 0x10000002C5C8601CC) >> 64;
            }
            if (x & 0x2000000000 > 0) {
                result = (result * 0x1000000162E42FFF0) >> 64;
            }
            if (x & 0x1000000000 > 0) {
                result = (result * 0x10000000B17217FBB) >> 64;
            }
            if (x & 0x800000000 > 0) {
                result = (result * 0x1000000058B90BFCE) >> 64;
            }
            if (x & 0x400000000 > 0) {
                result = (result * 0x100000002C5C85FE3) >> 64;
            }
            if (x & 0x200000000 > 0) {
                result = (result * 0x10000000162E42FF1) >> 64;
            }
            if (x & 0x100000000 > 0) {
                result = (result * 0x100000000B17217F8) >> 64;
            }
        }

        if (x & 0xFF000000 > 0) {
            if (x & 0x80000000 > 0) {
                result = (result * 0x10000000058B90BFC) >> 64;
            }
            if (x & 0x40000000 > 0) {
                result = (result * 0x1000000002C5C85FE) >> 64;
            }
            if (x & 0x20000000 > 0) {
                result = (result * 0x100000000162E42FF) >> 64;
            }
            if (x & 0x10000000 > 0) {
                result = (result * 0x1000000000B17217F) >> 64;
            }
            if (x & 0x8000000 > 0) {
                result = (result * 0x100000000058B90C0) >> 64;
            }
            if (x & 0x4000000 > 0) {
                result = (result * 0x10000000002C5C860) >> 64;
            }
            if (x & 0x2000000 > 0) {
                result = (result * 0x1000000000162E430) >> 64;
            }
            if (x & 0x1000000 > 0) {
                result = (result * 0x10000000000B17218) >> 64;
            }
        }

        if (x & 0xFF0000 > 0) {
            if (x & 0x800000 > 0) {
                result = (result * 0x1000000000058B90C) >> 64;
            }
            if (x & 0x400000 > 0) {
                result = (result * 0x100000000002C5C86) >> 64;
            }
            if (x & 0x200000 > 0) {
                result = (result * 0x10000000000162E43) >> 64;
            }
            if (x & 0x100000 > 0) {
                result = (result * 0x100000000000B1721) >> 64;
            }
            if (x & 0x80000 > 0) {
                result = (result * 0x10000000000058B91) >> 64;
            }
            if (x & 0x40000 > 0) {
                result = (result * 0x1000000000002C5C8) >> 64;
            }
            if (x & 0x20000 > 0) {
                result = (result * 0x100000000000162E4) >> 64;
            }
            if (x & 0x10000 > 0) {
                result = (result * 0x1000000000000B172) >> 64;
            }
        }

        if (x & 0xFF00 > 0) {
            if (x & 0x8000 > 0) {
                result = (result * 0x100000000000058B9) >> 64;
            }
            if (x & 0x4000 > 0) {
                result = (result * 0x10000000000002C5D) >> 64;
            }
            if (x & 0x2000 > 0) {
                result = (result * 0x1000000000000162E) >> 64;
            }
            if (x & 0x1000 > 0) {
                result = (result * 0x10000000000000B17) >> 64;
            }
            if (x & 0x800 > 0) {
                result = (result * 0x1000000000000058C) >> 64;
            }
            if (x & 0x400 > 0) {
                result = (result * 0x100000000000002C6) >> 64;
            }
            if (x & 0x200 > 0) {
                result = (result * 0x10000000000000163) >> 64;
            }
            if (x & 0x100 > 0) {
                result = (result * 0x100000000000000B1) >> 64;
            }
        }

        if (x & 0xFF > 0) {
            if (x & 0x80 > 0) {
                result = (result * 0x10000000000000059) >> 64;
            }
            if (x & 0x40 > 0) {
                result = (result * 0x1000000000000002C) >> 64;
            }
            if (x & 0x20 > 0) {
                result = (result * 0x10000000000000016) >> 64;
            }
            if (x & 0x10 > 0) {
                result = (result * 0x1000000000000000B) >> 64;
            }
            if (x & 0x8 > 0) {
                result = (result * 0x10000000000000006) >> 64;
            }
            if (x & 0x4 > 0) {
                result = (result * 0x10000000000000003) >> 64;
            }
            if (x & 0x2 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }
            if (x & 0x1 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }
        }

        // In the code snippet below, two operations are executed simultaneously:
        //
        // 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
        // accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
        // 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
        //
        // The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
        // integer part, $2^n$.
        result *= UNIT;
        result >>= (191 - (x >> 64));
    }
}

/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
///     x >>= 128;
///     result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
    // 2^128
    assembly ("memory-safe") {
        let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^64
    assembly ("memory-safe") {
        let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^32
    assembly ("memory-safe") {
        let factor := shl(5, gt(x, 0xFFFFFFFF))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^16
    assembly ("memory-safe") {
        let factor := shl(4, gt(x, 0xFFFF))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^8
    assembly ("memory-safe") {
        let factor := shl(3, gt(x, 0xFF))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^4
    assembly ("memory-safe") {
        let factor := shl(2, gt(x, 0xF))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^2
    assembly ("memory-safe") {
        let factor := shl(1, gt(x, 0x3))
        x := shr(factor, x)
        result := or(result, factor)
    }
    // 2^1
    // No need to shift x any more.
    assembly ("memory-safe") {
        let factor := gt(x, 0x1)
        result := or(result, factor)
    }
}

/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
    // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
    // use the Chinese Remainder Theorem to reconstruct the 512-bit result. The result is stored in two 256
    // variables such that product = prod1 * 2^256 + prod0.
    uint256 prod0; // Least significant 256 bits of the product
    uint256 prod1; // Most significant 256 bits of the product
    assembly ("memory-safe") {
        let mm := mulmod(x, y, not(0))
        prod0 := mul(x, y)
        prod1 := sub(sub(mm, prod0), lt(mm, prod0))
    }

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

    // Make sure the result is less than 2^256. Also prevents denominator == 0.
    if (prod1 >= denominator) {
        revert PRBMath_MulDiv_Overflow(x, y, denominator);
    }

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

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

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

    unchecked {
        // Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
        // because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
        // For more detail, see https://cs.stackexchange.com/q/138556/92363.
        uint256 lpotdod = denominator & (~denominator + 1);
        uint256 flippedLpotdod;

        assembly ("memory-safe") {
            // Factor powers of two out of denominator.
            denominator := div(denominator, lpotdod)

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

            // Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
            // `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
            // However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
            flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
        }

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

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

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

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

/// @notice Calculates x*y÷1e18 with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded toward zero.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
///     x * y = MAX\_UINT256 * UNIT \\
///     (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
    uint256 prod0;
    uint256 prod1;
    assembly ("memory-safe") {
        let mm := mulmod(x, y, not(0))
        prod0 := mul(x, y)
        prod1 := sub(sub(mm, prod0), lt(mm, prod0))
    }

    if (prod1 == 0) {
        unchecked {
            return prod0 / UNIT;
        }
    }

    if (prod1 >= UNIT) {
        revert PRBMath_MulDiv18_Overflow(x, y);
    }

    uint256 remainder;
    assembly ("memory-safe") {
        remainder := mulmod(x, y, UNIT)
        result :=
            mul(
                or(
                    div(sub(prod0, remainder), UNIT_LPOTD),
                    mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
                ),
                UNIT_INVERSE
            )
    }
}

/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
    if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
        revert PRBMath_MulDivSigned_InputTooSmall();
    }

    // Get hold of the absolute values of x, y and the denominator.
    uint256 xAbs;
    uint256 yAbs;
    uint256 dAbs;
    unchecked {
        xAbs = x < 0 ? uint256(-x) : uint256(x);
        yAbs = y < 0 ? uint256(-y) : uint256(y);
        dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
    }

    // Compute the absolute value of x*y÷denominator. The result must fit in int256.
    uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
    if (resultAbs > uint256(type(int256).max)) {
        revert PRBMath_MulDivSigned_Overflow(x, y);
    }

    // Get the signs of x, y and the denominator.
    uint256 sx;
    uint256 sy;
    uint256 sd;
    assembly ("memory-safe") {
        // "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
        sx := sgt(x, sub(0, 1))
        sy := sgt(y, sub(0, 1))
        sd := sgt(denominator, sub(0, 1))
    }

    // XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
    // If there are, the result should be negative. Otherwise, it should be positive.
    unchecked {
        result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
    }
}

/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
    if (x == 0) {
        return 0;
    }

    // For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
    //
    // We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
    //
    // $$
    // msb(x) <= x <= 2*msb(x)$
    // $$
    //
    // We write $msb(x)$ as $2^k$, and we get:
    //
    // $$
    // k = log_2(x)
    // $$
    //
    // Thus, we can write the initial inequality as:
    //
    // $$
    // 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
    // sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
    // 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
    // $$
    //
    // Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
    uint256 xAux = uint256(x);
    result = 1;
    if (xAux >= 2 ** 128) {
        xAux >>= 128;
        result <<= 64;
    }
    if (xAux >= 2 ** 64) {
        xAux >>= 64;
        result <<= 32;
    }
    if (xAux >= 2 ** 32) {
        xAux >>= 32;
        result <<= 16;
    }
    if (xAux >= 2 ** 16) {
        xAux >>= 16;
        result <<= 8;
    }
    if (xAux >= 2 ** 8) {
        xAux >>= 8;
        result <<= 4;
    }
    if (xAux >= 2 ** 4) {
        xAux >>= 4;
        result <<= 2;
    }
    if (xAux >= 2 ** 2) {
        result <<= 1;
    }

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

        // If x is not a perfect square, round the result toward zero.
        uint256 roundedResult = x / result;
        if (result >= roundedResult) {
            result = roundedResult;
        }
    }
}

File 12 of 36 : SelfPermit.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import {IERC20Permit} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol";

/// @notice Functionality to call permit on any EIP-2612-compliant token
/// @author Dinari (https://github.com/dinaricrypto/sbt-peripheral/blob/main/src/common/SelfPermit.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/v3-periphery/blob/master/contracts/base/SelfPermit.sol)
/// This function is expected to be embedded in multicalls to allow EOAs to approve a contract and call a function
/// that requires an approval in a single transaction.
abstract contract SelfPermit {
    /// @notice Permits this contract to spend a given token from `msg.sender`
    /// @dev The `spender` is always address(this).
    /// @param token The address of the token spent
    /// @param owner The address of the holder of the token
    /// @param value The amount that can be spent of token
    /// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp
    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
    function selfPermit(address token, address owner, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        public
    {
        IERC20Permit(token).permit(owner, address(this), value, deadline, v, r, s);
    }
}

File 13 of 36 : IOrderProcessor.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

/// @notice Interface for contracts processing orders for bridged assets
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/orders/IOrderProcessor.sol)
/// This interface provides a standard Order type and order lifecycle events
/// Orders are requested on-chain, processed off-chain, then fulfillment is submitted for on-chain settlement
/// Processor operators have a consistent interface for processing orders and submitting fulfillment
interface IOrderProcessor {
    /// ------------------ Types ------------------ ///

    // Market or limit order
    enum OrderType {
        MARKET,
        LIMIT
    }

    // Time in force
    enum TIF {
        // Good until end of day
        DAY,
        // Good until cancelled
        GTC,
        // Immediate or cancel
        IOC,
        // Fill or kill
        FOK
    }

    // Order status enum
    enum OrderStatus {
        // Order is active
        ACTIVE,
        // Order is completely filled
        FULFILLED,
        // Order is cancelled
        CANCELLED
    }

    // Emitted order data for off-chain order fulfillment
    struct Order {
        // Recipient of order fills
        address recipient;
        // Bridged asset token
        address assetToken;
        // Payment token
        address paymentToken;
        // Buy or sell
        bool sell;
        // Market or limit
        OrderType orderType;
        // Amount of asset token to be used for fills
        uint256 assetTokenQuantity;
        // Amount of payment token to be used for fills
        uint256 paymentTokenQuantity;
        // Price for limit orders
        uint256 price;
        // Time in force
        TIF tif;
        // Account receiving split amount
        address splitRecipient;
        // Received amount filled to secondary address first
        uint256 splitAmount;
    }

    /// @dev Fully specifies order details and order ID
    event OrderRequested(uint256 indexed id, address indexed requester, Order order);
    /// @dev Emitted for each fill
    event OrderFill(
        uint256 indexed id,
        address indexed requester,
        address paymentToken,
        address assetToken,
        uint256 fillAmount,
        uint256 receivedAmount,
        uint256 feesPaid
    );
    /// @dev Emitted when order is completely filled, terminal
    event OrderFulfilled(uint256 indexed id, address indexed requester);
    /// @dev Emitted when order cancellation is requested
    event CancelRequested(uint256 indexed id, address indexed requester);
    /// @dev Emitted when order is cancelled, terminal
    event OrderCancelled(uint256 indexed id, address indexed requester, string reason);

    /// ------------------ Getters ------------------ ///

    /// @notice Total number of open orders
    function numOpenOrders() external view returns (uint256);

    /// @notice Next order id to be used
    function nextOrderId() external view returns (uint256);

    /// @notice Status of a given order
    /// @param id Order ID
    function getOrderStatus(uint256 id) external view returns (OrderStatus);

    /// @notice Get remaining order quantity to fill
    /// @param id Order ID
    function getUnfilledAmount(uint256 id) external view returns (uint256);

    /// @notice Get total received for order
    /// @param id Order ID
    function getTotalReceived(uint256 id) external view returns (uint256);

    /// @notice This function fetches the total balance held in escrow for a given requester and token
    /// @param token The address of the token for which the escrowed balance is fetched
    /// @param requester The address of the requester for which the escrowed balance is fetched
    /// @return Returns the total amount of the specific token held in escrow for the given requester
    function escrowedBalanceOf(address token, address requester) external view returns (uint256);

    /// @notice This function retrieves the number of decimal places configured for a given token
    /// @param token The address of the token for which the number of decimal places is fetched
    /// @return Returns the number of decimal places set for the specified token
    function maxOrderDecimals(address token) external view returns (int8);

    /// @notice Get fee rates for an order
    /// @param requester Requester of order
    /// @param sell Sell order
    /// @param paymentToken Payment token for order
    /// @return flatFee Flat fee for order
    /// @return percentageFeeRate Percentage fee rate for order
    function getFeeRatesForOrder(address requester, bool sell, address paymentToken)
        external
        view
        returns (uint256, uint24);

    /// @notice Get total fees for an order
    /// @param requester Requester of order
    /// @param sell Sell order
    /// @param paymentToken Payment token for order
    /// @param paymentTokenOrderValue Order payment token quantity
    function estimateTotalFeesForOrder(
        address requester,
        bool sell,
        address paymentToken,
        uint256 paymentTokenOrderValue
    ) external view returns (uint256);

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

    function FORWARDER_ROLE() external view returns (bytes32);

    /// ------------------ Actions ------------------ ///

    /// @notice Request an order
    /// @param order Order request to submit
    /// @return id Order id
    /// @dev Emits OrderRequested event to be sent to fulfillment service (operator)
    function requestOrder(Order calldata order) external returns (uint256);

    /// @notice Fill an order
    /// @param id order id
    /// @param order Order request to fill
    /// @param fillAmount Amount of order token to fill
    /// @param receivedAmount Amount of received token
    /// @dev Only callable by operator
    function fillOrder(uint256 id, Order calldata order, uint256 fillAmount, uint256 receivedAmount) external;

    /// @notice Request to cancel an order
    /// @param id Order id
    /// @dev Only callable by initial order requester
    /// @dev Emits CancelRequested event to be sent to fulfillment service (operator)
    function requestCancel(uint256 id) external;

    /// @notice Cancel an order
    /// @param order id
    /// @param order Order request to cancel
    /// @param reason Reason for cancellation
    /// @dev Only callable by operator
    function cancelOrder(uint256 id, Order calldata order, string calldata reason) external;
}

File 14 of 36 : ITransferRestrictor.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

/// @notice Enforces transfer restrictions
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/ITransferRestrictor.sol)
interface ITransferRestrictor {
    /// @notice Checks if the transfer is allowed
    /// @param from The address of the sender
    /// @param to The address of the recipient
    function requireNotRestricted(address from, address to) external view;

    /// @notice Checks if the transfer is allowed
    /// @param account The address of the account
    function isBlacklisted(address account) external view returns (bool);
}

File 15 of 36 : DShare.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import {Initializable} from "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import {AccessControlDefaultAdminRulesUpgradeable} from
    "openzeppelin-contracts-upgradeable/contracts/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol";
import {IDShare, ITransferRestrictor} from "./IDShare.sol";
import {ERC20Rebasing} from "./ERC20Rebasing.sol";

/// @notice Core token contract for bridged assets. Rebases on stock splits.
/// ERC20 with minter, burner, and blacklist
/// Uses solady ERC20 which allows EIP-2612 domain separator with `name` changes
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/dShare.sol)
contract DShare is IDShare, Initializable, ERC20Rebasing, AccessControlDefaultAdminRulesUpgradeable {
    /// ------------------ Types ------------------ ///

    error Unauthorized();
    error ZeroValue();

    /// @dev Emitted when `name` is set
    event NameSet(string name);
    /// @dev Emitted when `symbol` is set
    event SymbolSet(string symbol);
    /// @dev Emitted when transfer restrictor contract is set
    event TransferRestrictorSet(ITransferRestrictor indexed transferRestrictor);
    /// @dev Emitted when split factor is updated
    event BalancePerShareSet(uint256 balancePerShare);

    /// ------------------ Immutables ------------------ ///

    /// @notice Role for approved minters
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    /// @notice Role for approved burners
    bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

    /// ------------------ State ------------------ ///

    struct dShareStorage {
        string _name;
        string _symbol;
        ITransferRestrictor _transferRestrictor;
        /// @dev Aggregate mult factor due to splits since deployment, ethers decimals
        uint128 _balancePerShare;
    }

    // keccak256(abi.encode(uint256(keccak256("dinaricrypto.storage.DShare")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant dShareStorageLocation = 0x7315beb2381679795e06870021c0fca5deb85616e29e098c2e7b7e488f185800;

    function _getdShareStorage() private pure returns (dShareStorage storage $) {
        assembly {
            $.slot := dShareStorageLocation
        }
    }

    /// ------------------ Initialization ------------------ ///

    function initialize(
        address owner,
        string memory _name,
        string memory _symbol,
        ITransferRestrictor _transferRestrictor
    ) public initializer {
        __AccessControlDefaultAdminRules_init_unchained(0, owner);

        dShareStorage storage $ = _getdShareStorage();
        $._name = _name;
        $._symbol = _symbol;
        $._transferRestrictor = _transferRestrictor;
        $._balancePerShare = _INITIAL_BALANCE_PER_SHARE;
    }

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    /// ------------------ Getters ------------------ ///

    /// @notice Token name
    function name() public view override returns (string memory) {
        dShareStorage storage $ = _getdShareStorage();
        return $._name;
    }

    /// @notice Token symbol
    function symbol() public view override returns (string memory) {
        dShareStorage storage $ = _getdShareStorage();
        return $._symbol;
    }

    /// @notice Contract to restrict transfers
    function transferRestrictor() public view returns (ITransferRestrictor) {
        dShareStorage storage $ = _getdShareStorage();
        return $._transferRestrictor;
    }

    function balancePerShare() public view override returns (uint128) {
        dShareStorage storage $ = _getdShareStorage();
        uint128 _balancePerShare = $._balancePerShare;
        // Override with default if not set due to upgrade
        if (_balancePerShare == 0) return _INITIAL_BALANCE_PER_SHARE;
        return _balancePerShare;
    }

    /// ------------------ Setters ------------------ ///

    /// @notice Set token name
    /// @dev Only callable by owner or deployer
    function setName(string calldata newName) external onlyRole(DEFAULT_ADMIN_ROLE) {
        dShareStorage storage $ = _getdShareStorage();
        $._name = newName;
        emit NameSet(newName);
    }

    /// @notice Set token symbol
    /// @dev Only callable by owner or deployer
    function setSymbol(string calldata newSymbol) external onlyRole(DEFAULT_ADMIN_ROLE) {
        dShareStorage storage $ = _getdShareStorage();
        $._symbol = newSymbol;
        emit SymbolSet(newSymbol);
    }

    /// @notice Update split factor
    /// @dev Relies on offchain computation of aggregate splits and reverse splits
    function setBalancePerShare(uint128 balancePerShare_) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (balancePerShare_ == 0) revert ZeroValue();

        dShareStorage storage $ = _getdShareStorage();
        $._balancePerShare = balancePerShare_;
        emit BalancePerShareSet(balancePerShare_);
    }

    /// @notice Set transfer restrictor contract
    /// @dev Only callable by owner
    function setTransferRestrictor(ITransferRestrictor newRestrictor) external onlyRole(DEFAULT_ADMIN_ROLE) {
        dShareStorage storage $ = _getdShareStorage();
        $._transferRestrictor = newRestrictor;
        emit TransferRestrictorSet(newRestrictor);
    }

    /// ------------------ Minting and Burning ------------------ ///

    /// @notice Mint tokens
    /// @param to Address to mint tokens to
    /// @param value Amount of tokens to mint
    /// @dev Only callable by approved minter
    function mint(address to, uint256 value) external onlyRole(MINTER_ROLE) {
        _mint(to, value);
    }

    /// @notice Burn tokens
    /// @param value Amount of tokens to burn
    /// @dev Only callable by approved burner
    function burn(uint256 value) external onlyRole(BURNER_ROLE) {
        _burn(msg.sender, value);
    }

    /// @notice Burn tokens from an account
    /// @param account Address to burn tokens from
    /// @param value Amount of tokens to burn
    /// @dev Only callable by approved burner
    function burnFrom(address account, uint256 value) external onlyRole(BURNER_ROLE) {
        _spendAllowance(account, msg.sender, value);
        _burn(account, value);
    }

    /// ------------------ Transfers ------------------ ///

    function _beforeTokenTransfer(address from, address to, uint256) internal view override {
        // If transferRestrictor is not set, no restrictions are applied
        dShareStorage storage $ = _getdShareStorage();
        ITransferRestrictor _transferRestrictor = $._transferRestrictor;
        if (address(_transferRestrictor) != address(0)) {
            // Check transfer restrictions
            _transferRestrictor.requireNotRestricted(from, to);
        }
    }

    /**
     * @param account The address of the account
     * @return Whether the account is blacklisted
     * @dev Returns true if the account is blacklisted , if the account is the zero address
     */
    function isBlacklisted(address account) external view returns (bool) {
        dShareStorage storage $ = _getdShareStorage();
        ITransferRestrictor _transferRestrictor = $._transferRestrictor;
        if (address(_transferRestrictor) == address(0)) return false;
        return _transferRestrictor.isBlacklisted(account);
    }
}

File 16 of 36 : ITokenLockCheck.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

interface ITokenLockCheck {
    function isTransferLocked(address token, address account) external view returns (bool);
}

File 17 of 36 : FeeLib.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import "prb-math/Common.sol" as PrbMath;
import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";

library FeeLib {
    // 1_000_000 == 100%
    uint24 private constant _ONEHUNDRED_PERCENT = 1_000_000;

    /// @dev Fee is too large
    error FeeTooLarge();
    /// @dev Decimals are too large
    error DecimalsTooLarge();

    function checkPercentageFeeRate(uint24 _percentageFeeRate) internal pure {
        if (_percentageFeeRate >= _ONEHUNDRED_PERCENT) revert FeeTooLarge();
    }

    function percentageFeeForValue(uint256 value, uint24 percentageFeeRate) internal pure returns (uint256) {
        if (percentageFeeRate >= _ONEHUNDRED_PERCENT) revert FeeTooLarge();
        return percentageFeeRate != 0 ? PrbMath.mulDiv(value, percentageFeeRate, _ONEHUNDRED_PERCENT) : 0;
    }

    function flatFeeForOrder(address token, uint64 perOrderFee) internal view returns (uint256 flatFee) {
        uint8 decimals = IERC20Metadata(token).decimals();
        if (decimals > 18) revert DecimalsTooLarge();
        flatFee = perOrderFee;
        if (flatFee != 0 && decimals < 18) {
            flatFee /= 10 ** (18 - decimals);
        }
    }

    function estimateTotalFees(uint256 flatFee, uint24 percentageFeeRate, uint256 orderValue)
        internal
        pure
        returns (uint256 totalFees)
    {
        totalFees = flatFee;
        if (percentageFeeRate != 0) {
            totalFees += PrbMath.mulDiv(orderValue, percentageFeeRate, _ONEHUNDRED_PERCENT);
        }
    }
}

File 18 of 36 : IForwarder.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import {IOrderProcessor} from "../orders/IOrderProcessor.sol";

/// @notice Contract interface for paying gas fees for users and forwarding meta transactions to OrderProcessor contracts.
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/forwarder/IForwarder.sol)
interface IForwarder {
    struct ForwardRequest {
        address user; // The address of the user initiating the meta-transaction.
        address to; // The address of the target contract (e.g., OrderProcessor)
            // to which the meta-transaction should be forwarded.
        bytes data; // Encoded function call that the user wants to execute
            // through the meta-transaction.
        uint64 deadline; // The time by which the meta-transaction must be mined.
        uint256 nonce; // A nonce to prevent replay attacks. It must be unique
            // for each meta-transaction made by the user.
        bytes signature; // ECDSA signature of the user authorizing the meta-transaction.
    }

    struct OrderForwardRequest {
        address user;
        address to;
        IOrderProcessor.Order order;
        uint256 deadline;
        uint256 nonce;
        bytes signature;
    }

    struct CancelForwardRequest {
        address user;
        address to;
        uint256 orderId;
        uint256 deadline;
        uint256 nonce;
        bytes signature;
    }

    /// @notice The fee rate in basis points (1 basis point = 0.01%) for paying gas fees in tokens.
    function feeBps() external view returns (uint16);

    /// @notice Gas cost estimate added to cover oder cancellations.
    function cancellationGasCost() external view returns (uint256);

    /// @notice The mapping of relayer addresses authorize to send meta transactions.
    function isRelayer(address relayer) external view returns (bool);

    /// @notice The mapping of order IDs to signers used for order cancellation protection.
    function orderSigner(uint256 orderId) external view returns (address);

    /// @notice EIP-712 compliant order forward request hash function.
    function orderForwardRequestHash(OrderForwardRequest calldata metaTx) external pure returns (bytes32);

    /// @notice EIP-712 compliant cancel forward request hash function.
    function cancelForwardRequestHash(CancelForwardRequest calldata metaTx) external pure returns (bytes32);

    /**
     * @notice Forwards a meta transaction to an BuyOrder contract.
     * @dev Validates the meta transaction signature, then forwards the call to the target OrderProcessor.
     * The relayer's address is used for EIP-712 compliant signature verification.
     * This function should only be called by the authorized relayer.
     * @param metaTx The meta transaction containing the user address, target contract, encoded function call data,
     * deadline, nonce, payment token oracle price, and the signature components (v, r, s).
     * @return The return data of the forwarded function call.
     */
    function forwardRequestBuyOrder(OrderForwardRequest calldata metaTx) external returns (uint256);

    /**
     * @notice Forwards a meta transaction to cancel an Order to OrderProcessor contract.
     * @dev Validates the meta transaction signature, then forwards the call to the target OrderProcessor.
     * The relayer's address is used for EIP-712 compliant signature verification.
     * This function should only be called by the authorized relayer.
     * @param metaTx The meta transaction containing the user address, target contract, encoded function call data,
     * deadline, nonce, payment token oracle price, and the signature components (v, r, s).
     */
    function forwardRequestCancel(CancelForwardRequest calldata metaTx) external;

    /**
     * @notice Forwards a meta transaction to an SellOrder contract.
     * @dev Validates the meta transaction signature, then forwards the call to the target OrderProcessor.
     * The relayer's address is used for EIP-712 compliant signature verification.
     * This function should only be called by the authorized relayer.
     * @param metaTx The meta transaction containing the user address, target contract, encoded function call data,
     * deadline, nonce, payment token oracle price, and the signature components (v, r, s).
     * @return The return data of the forwarded function call.
     */
    function forwardRequestSellOrder(OrderForwardRequest calldata metaTx) external returns (uint256);
}

File 19 of 36 : draft-IERC1822.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 20 of 36 : ERC1967Utils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 */
library ERC1967Utils {
    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

File 21 of 36 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

    /**
     * @dev Emitted when a {defaultAdmin} transfer is started, setting `newAdmin` as the next
     * address to become the {defaultAdmin} by calling {acceptDefaultAdminTransfer} only after `acceptSchedule`
     * passes.
     */
    event DefaultAdminTransferScheduled(address indexed newAdmin, uint48 acceptSchedule);

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

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

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

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

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

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

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

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

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

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

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

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

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

File 23 of 36 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

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

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;


    /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
    struct AccessControlStorage {
        mapping(bytes32 role => RoleData) _roles;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;

    function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
        assembly {
            $.slot := AccessControlStorageLocation
        }
    }

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    function __AccessControl_init() internal onlyInitializing {
    }

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

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

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

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

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

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

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

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

        _revokeRole(role, callerConfirmation);
    }

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

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (!hasRole(role, account)) {
            $._roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

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

File 24 of 36 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

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

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

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

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

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

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

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

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

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

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

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

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

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

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

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

File 28 of 36 : IDShare.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

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

/// @notice Core token contract interface for bridged assets.
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/IDShare.sol)
/// Minter, burner, and blacklist
interface IDShare {
    /// @notice Contract to restrict transfers
    function transferRestrictor() external view returns (ITransferRestrictor);

    /// @notice Mint tokens
    /// @param to Address to mint tokens to
    /// @param value Amount of tokens to mint
    /// @dev Only callable by approved minter and deployer
    /// @dev Not callable after split
    function mint(address to, uint256 value) external;

    /// @notice Burn tokens
    /// @param value Amount of tokens to burn
    /// @dev Only callable by approved burner
    /// @dev Deployer can always burn after split
    function burn(uint256 value) external;

    /**
     * @param account The address of the account
     * @return Whether the account is blacklisted
     * @dev Returns true if the account is blacklisted , if the account is the zero address
     */
    function isBlacklisted(address account) external view returns (bool);
}

File 29 of 36 : ERC20Rebasing.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import {ERC20} from "solady/src/tokens/ERC20.sol";
import {mulDiv, mulDiv18} from "prb-math/Common.sol";
import {NumberUtils} from "./common/NumberUtils.sol";

/// @notice Rebasing ERC20 token as an in-place upgrade to solady erc20
/// @author Dinari (https://github.com/dinaricrypto/sbt-contracts/blob/main/src/dShare.sol)
abstract contract ERC20Rebasing is ERC20 {
    uint256 private constant _TRANSFER_EVENT_SIGNATURE =
        0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;

    uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c;
    uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2;

    uint128 internal constant _INITIAL_BALANCE_PER_SHARE = 1 ether;

    /**
     * @dev Returns the number of tokens an internal share amount represents.
     * This amount is assumed to have 18 decimals and is divided by 10 **18 when applied.
     */
    function balancePerShare() public view virtual returns (uint128);

    function sharesToBalance(uint256 shares) public view returns (uint256) {
        return mulDiv18(shares, balancePerShare()); // floor
    }

    function balanceToShares(uint256 balance) public view returns (uint256) {
        return mulDiv(balance, _INITIAL_BALANCE_PER_SHARE, balancePerShare()); // floor
    }

    /// ------------------ ERC20 ------------------

    function totalSupply() public view virtual override returns (uint256) {
        return sharesToBalance(super.totalSupply());
    }

    function maxSupply() public view virtual returns (uint256) {
        uint128 balancePerShare_ = balancePerShare();
        if (balancePerShare_ < _INITIAL_BALANCE_PER_SHARE) {
            return mulDiv18(type(uint256).max, balancePerShare_);
        } else if (balancePerShare_ > _INITIAL_BALANCE_PER_SHARE) {
            return mulDiv(type(uint256).max, _INITIAL_BALANCE_PER_SHARE, balancePerShare_);
        }
        return type(uint256).max;
    }

    function balanceOf(address account) public view virtual override returns (uint256) {
        return sharesToBalance(super.balanceOf(account));
    }

    function sharesOf(address account) public view virtual returns (uint256) {
        return super.balanceOf(account);
    }

    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        _transfer(msg.sender, to, amount);
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
        _spendAllowance(from, msg.sender, amount);
        _transfer(from, to, amount);
        return true;
    }

    // Convert to shares
    function _transfer(address from, address to, uint256 amount) internal virtual override {
        _beforeTokenTransfer(from, to, amount);
        uint256 shares = balanceToShares(amount);
        /// @solidity memory-safe-assembly
        assembly {
            let from_ := shl(96, from)
            // Compute the balance slot and load its value.
            mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
            let fromBalanceSlot := keccak256(0x0c, 0x20)
            let fromBalance := sload(fromBalanceSlot)
            // Revert if insufficient balance.
            if gt(shares, fromBalance) {
                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
                revert(0x1c, 0x04)
            }
            // Subtract and store the updated balance.
            sstore(fromBalanceSlot, sub(fromBalance, shares))
            // Compute the balance slot of `to`.
            mstore(0x00, to)
            let toBalanceSlot := keccak256(0x0c, 0x20)
            // Add and store the updated balance of `to`.
            // Will not overflow because the sum of all user balances
            // cannot exceed the maximum uint256 value.
            sstore(toBalanceSlot, add(sload(toBalanceSlot), shares))
            // Emit the {Transfer} event.
            mstore(0x20, amount)
            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
        }
        _afterTokenTransfer(from, to, amount);
    }

    // Convert to shares
    function _mint(address to, uint256 amount) internal virtual override {
        _beforeTokenTransfer(address(0), to, amount);
        uint256 totalSharesBefore = super.totalSupply();
        uint256 totalSupplyBefore = sharesToBalance(totalSharesBefore);
        uint256 totalSupplyAfter = 0;
        unchecked {
            totalSupplyAfter = totalSupplyBefore + amount;
            if (totalSupplyAfter < totalSupplyBefore) revert TotalSupplyOverflow();
        }
        if (NumberUtils.mulDivCheckOverflow(totalSupplyAfter, _INITIAL_BALANCE_PER_SHARE, balancePerShare())) {
            revert TotalSupplyOverflow();
        }
        uint256 shares = balanceToShares(amount);
        uint256 totalSharesAfter = 0;
        unchecked {
            totalSharesAfter = totalSharesBefore + shares;
        }
        /// @solidity memory-safe-assembly
        assembly {
            // Store the updated total supply.
            sstore(_TOTAL_SUPPLY_SLOT, totalSharesAfter)
            // Compute the balance slot and load its value.
            mstore(0x0c, _BALANCE_SLOT_SEED)
            mstore(0x00, to)
            let toBalanceSlot := keccak256(0x0c, 0x20)
            // Add and store the updated balance.
            sstore(toBalanceSlot, add(sload(toBalanceSlot), shares))
            // Emit the {Transfer} event.
            mstore(0x20, amount)
            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c)))
        }
        _afterTokenTransfer(address(0), to, amount);
    }

    // Convert to shares
    function _burn(address from, uint256 amount) internal virtual override {
        _beforeTokenTransfer(from, address(0), amount);
        uint256 shares = balanceToShares(amount);
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the balance slot and load its value.
            mstore(0x0c, _BALANCE_SLOT_SEED)
            mstore(0x00, from)
            let fromBalanceSlot := keccak256(0x0c, 0x20)
            let fromBalance := sload(fromBalanceSlot)
            // Revert if insufficient balance.
            if gt(shares, fromBalance) {
                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
                revert(0x1c, 0x04)
            }
            // Subtract and store the updated balance.
            sstore(fromBalanceSlot, sub(fromBalance, shares))
            // Subtract and store the updated total supply.
            sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), shares))
            // Emit the {Transfer} event.
            mstore(0x00, amount)
            log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0)
        }
        _afterTokenTransfer(from, address(0), amount);
    }
}

File 30 of 36 : IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

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

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 32 of 36 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

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

pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165Upgradeable is Initializable, IERC165 {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 34 of 36 : ERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Simple ERC20 + EIP-2612 implementation.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol)
///
/// @dev Note:
/// - The ERC20 standard allows minting and transferring to and from the zero address,
///   minting and transferring zero tokens, as well as self-approvals.
///   For performance, this implementation WILL NOT revert for such actions.
///   Please add any checks with overrides if desired.
/// - The `permit` function uses the ecrecover precompile (0x1).
///
/// If you are overriding:
/// - NEVER violate the ERC20 invariant:
///   the total sum of all balances must be equal to `totalSupply()`.
/// - Check that the overridden function is actually used in the function you want to
///   change the behavior of. Much of the code has been manually inlined for performance.
abstract contract ERC20 {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The total supply has overflowed.
    error TotalSupplyOverflow();

    /// @dev The allowance has overflowed.
    error AllowanceOverflow();

    /// @dev The allowance has underflowed.
    error AllowanceUnderflow();

    /// @dev Insufficient balance.
    error InsufficientBalance();

    /// @dev Insufficient allowance.
    error InsufficientAllowance();

    /// @dev The permit is invalid.
    error InvalidPermit();

    /// @dev The permit has expired.
    error PermitExpired();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Emitted when `amount` tokens is transferred from `from` to `to`.
    event Transfer(address indexed from, address indexed to, uint256 amount);

    /// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`.
    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`.
    uint256 private constant _TRANSFER_EVENT_SIGNATURE =
        0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;

    /// @dev `keccak256(bytes("Approval(address,address,uint256)"))`.
    uint256 private constant _APPROVAL_EVENT_SIGNATURE =
        0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The storage slot for the total supply.
    uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c;

    /// @dev The balance slot of `owner` is given by:
    /// ```
    ///     mstore(0x0c, _BALANCE_SLOT_SEED)
    ///     mstore(0x00, owner)
    ///     let balanceSlot := keccak256(0x0c, 0x20)
    /// ```
    uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2;

    /// @dev The allowance slot of (`owner`, `spender`) is given by:
    /// ```
    ///     mstore(0x20, spender)
    ///     mstore(0x0c, _ALLOWANCE_SLOT_SEED)
    ///     mstore(0x00, owner)
    ///     let allowanceSlot := keccak256(0x0c, 0x34)
    /// ```
    uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20;

    /// @dev The nonce slot of `owner` is given by:
    /// ```
    ///     mstore(0x0c, _NONCES_SLOT_SEED)
    ///     mstore(0x00, owner)
    ///     let nonceSlot := keccak256(0x0c, 0x20)
    /// ```
    uint256 private constant _NONCES_SLOT_SEED = 0x38377508;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`.
    uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901;

    /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
    bytes32 private constant _DOMAIN_TYPEHASH =
        0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;

    /// @dev `keccak256("1")`.
    bytes32 private constant _VERSION_HASH =
        0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6;

    /// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`.
    bytes32 private constant _PERMIT_TYPEHASH =
        0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       ERC20 METADATA                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the name of the token.
    function name() public view virtual returns (string memory);

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

    /// @dev Returns the decimals places of the token.
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           ERC20                            */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the amount of tokens in existence.
    function totalSupply() public view virtual returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := sload(_TOTAL_SUPPLY_SLOT)
        }
    }

    /// @dev Returns the amount of tokens owned by `owner`.
    function balanceOf(address owner) public view virtual returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x0c, _BALANCE_SLOT_SEED)
            mstore(0x00, owner)
            result := sload(keccak256(0x0c, 0x20))
        }
    }

    /// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`.
    function allowance(address owner, address spender)
        public
        view
        virtual
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x20, spender)
            mstore(0x0c, _ALLOWANCE_SLOT_SEED)
            mstore(0x00, owner)
            result := sload(keccak256(0x0c, 0x34))
        }
    }

    /// @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
    ///
    /// Emits a {Approval} event.
    function approve(address spender, uint256 amount) public virtual returns (bool) {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the allowance slot and store the amount.
            mstore(0x20, spender)
            mstore(0x0c, _ALLOWANCE_SLOT_SEED)
            mstore(0x00, caller())
            sstore(keccak256(0x0c, 0x34), amount)
            // Emit the {Approval} event.
            mstore(0x00, amount)
            log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c)))
        }
        return true;
    }

    /// @dev Transfer `amount` tokens from the caller to `to`.
    ///
    /// Requirements:
    /// - `from` must at least have `amount`.
    ///
    /// Emits a {Transfer} event.
    function transfer(address to, uint256 amount) public virtual returns (bool) {
        _beforeTokenTransfer(msg.sender, to, amount);
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the balance slot and load its value.
            mstore(0x0c, _BALANCE_SLOT_SEED)
            mstore(0x00, caller())
            let fromBalanceSlot := keccak256(0x0c, 0x20)
            let fromBalance := sload(fromBalanceSlot)
            // Revert if insufficient balance.
            if gt(amount, fromBalance) {
                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
                revert(0x1c, 0x04)
            }
            // Subtract and store the updated balance.
            sstore(fromBalanceSlot, sub(fromBalance, amount))
            // Compute the balance slot of `to`.
            mstore(0x00, to)
            let toBalanceSlot := keccak256(0x0c, 0x20)
            // Add and store the updated balance of `to`.
            // Will not overflow because the sum of all user balances
            // cannot exceed the maximum uint256 value.
            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
            // Emit the {Transfer} event.
            mstore(0x20, amount)
            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c)))
        }
        _afterTokenTransfer(msg.sender, to, amount);
        return true;
    }

    /// @dev Transfers `amount` tokens from `from` to `to`.
    ///
    /// Note: Does not update the allowance if it is the maximum uint256 value.
    ///
    /// Requirements:
    /// - `from` must at least have `amount`.
    /// - The caller must have at least `amount` of allowance to transfer the tokens of `from`.
    ///
    /// Emits a {Transfer} event.
    function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
        _beforeTokenTransfer(from, to, amount);
        /// @solidity memory-safe-assembly
        assembly {
            let from_ := shl(96, from)
            // Compute the allowance slot and load its value.
            mstore(0x20, caller())
            mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED))
            let allowanceSlot := keccak256(0x0c, 0x34)
            let allowance_ := sload(allowanceSlot)
            // If the allowance is not the maximum uint256 value.
            if add(allowance_, 1) {
                // Revert if the amount to be transferred exceeds the allowance.
                if gt(amount, allowance_) {
                    mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
                    revert(0x1c, 0x04)
                }
                // Subtract and store the updated allowance.
                sstore(allowanceSlot, sub(allowance_, amount))
            }
            // Compute the balance slot and load its value.
            mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
            let fromBalanceSlot := keccak256(0x0c, 0x20)
            let fromBalance := sload(fromBalanceSlot)
            // Revert if insufficient balance.
            if gt(amount, fromBalance) {
                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
                revert(0x1c, 0x04)
            }
            // Subtract and store the updated balance.
            sstore(fromBalanceSlot, sub(fromBalance, amount))
            // Compute the balance slot of `to`.
            mstore(0x00, to)
            let toBalanceSlot := keccak256(0x0c, 0x20)
            // Add and store the updated balance of `to`.
            // Will not overflow because the sum of all user balances
            // cannot exceed the maximum uint256 value.
            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
            // Emit the {Transfer} event.
            mstore(0x20, amount)
            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
        }
        _afterTokenTransfer(from, to, amount);
        return true;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          EIP-2612                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev For more performance, override to return the constant value
    /// of `keccak256(bytes(name()))` if `name()` will never change.
    function _constantNameHash() internal view virtual returns (bytes32 result) {}

    /// @dev Returns the current nonce for `owner`.
    /// This value is used to compute the signature for EIP-2612 permit.
    function nonces(address owner) public view virtual returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the nonce slot and load its value.
            mstore(0x0c, _NONCES_SLOT_SEED)
            mstore(0x00, owner)
            result := sload(keccak256(0x0c, 0x20))
        }
    }

    /// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`,
    /// authorized by a signed approval by `owner`.
    ///
    /// Emits a {Approval} event.
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        bytes32 nameHash = _constantNameHash();
        //  We simply calculate it on-the-fly to allow for cases where the `name` may change.
        if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
        /// @solidity memory-safe-assembly
        assembly {
            // Revert if the block timestamp is greater than `deadline`.
            if gt(timestamp(), deadline) {
                mstore(0x00, 0x1a15a3cc) // `PermitExpired()`.
                revert(0x1c, 0x04)
            }
            let m := mload(0x40) // Grab the free memory pointer.
            // Clean the upper 96 bits.
            owner := shr(96, shl(96, owner))
            spender := shr(96, shl(96, spender))
            // Compute the nonce slot and load its value.
            mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX)
            mstore(0x00, owner)
            let nonceSlot := keccak256(0x0c, 0x20)
            let nonceValue := sload(nonceSlot)
            // Prepare the domain separator.
            mstore(m, _DOMAIN_TYPEHASH)
            mstore(add(m, 0x20), nameHash)
            mstore(add(m, 0x40), _VERSION_HASH)
            mstore(add(m, 0x60), chainid())
            mstore(add(m, 0x80), address())
            mstore(0x2e, keccak256(m, 0xa0))
            // Prepare the struct hash.
            mstore(m, _PERMIT_TYPEHASH)
            mstore(add(m, 0x20), owner)
            mstore(add(m, 0x40), spender)
            mstore(add(m, 0x60), value)
            mstore(add(m, 0x80), nonceValue)
            mstore(add(m, 0xa0), deadline)
            mstore(0x4e, keccak256(m, 0xc0))
            // Prepare the ecrecover calldata.
            mstore(0x00, keccak256(0x2c, 0x42))
            mstore(0x20, and(0xff, v))
            mstore(0x40, r)
            mstore(0x60, s)
            let t := staticcall(gas(), 1, 0, 0x80, 0x20, 0x20)
            // If the ecrecover fails, the returndatasize will be 0x00,
            // `owner` will be checked if it equals the hash at 0x00,
            // which evaluates to false (i.e. 0), and we will revert.
            // If the ecrecover succeeds, the returndatasize will be 0x20,
            // `owner` will be compared against the returned address at 0x20.
            if iszero(eq(mload(returndatasize()), owner)) {
                mstore(0x00, 0xddafbaef) // `InvalidPermit()`.
                revert(0x1c, 0x04)
            }
            // Increment and store the updated nonce.
            sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds.
            // Compute the allowance slot and store the value.
            // The `owner` is already at slot 0x20.
            mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender))
            sstore(keccak256(0x2c, 0x34), value)
            // Emit the {Approval} event.
            log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender)
            mstore(0x40, m) // Restore the free memory pointer.
            mstore(0x60, 0) // Restore the zero pointer.
        }
    }

    /// @dev Returns the EIP-712 domain separator for the EIP-2612 permit.
    function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) {
        bytes32 nameHash = _constantNameHash();
        //  We simply calculate it on-the-fly to allow for cases where the `name` may change.
        if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Grab the free memory pointer.
            mstore(m, _DOMAIN_TYPEHASH)
            mstore(add(m, 0x20), nameHash)
            mstore(add(m, 0x40), _VERSION_HASH)
            mstore(add(m, 0x60), chainid())
            mstore(add(m, 0x80), address())
            result := keccak256(m, 0xa0)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  INTERNAL MINT FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Mints `amount` tokens to `to`, increasing the total supply.
    ///
    /// Emits a {Transfer} event.
    function _mint(address to, uint256 amount) internal virtual {
        _beforeTokenTransfer(address(0), to, amount);
        /// @solidity memory-safe-assembly
        assembly {
            let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT)
            let totalSupplyAfter := add(totalSupplyBefore, amount)
            // Revert if the total supply overflows.
            if lt(totalSupplyAfter, totalSupplyBefore) {
                mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`.
                revert(0x1c, 0x04)
            }
            // Store the updated total supply.
            sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter)
            // Compute the balance slot and load its value.
            mstore(0x0c, _BALANCE_SLOT_SEED)
            mstore(0x00, to)
            let toBalanceSlot := keccak256(0x0c, 0x20)
            // Add and store the updated balance.
            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
            // Emit the {Transfer} event.
            mstore(0x20, amount)
            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c)))
        }
        _afterTokenTransfer(address(0), to, amount);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  INTERNAL BURN FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Burns `amount` tokens from `from`, reducing the total supply.
    ///
    /// Emits a {Transfer} event.
    function _burn(address from, uint256 amount) internal virtual {
        _beforeTokenTransfer(from, address(0), amount);
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the balance slot and load its value.
            mstore(0x0c, _BALANCE_SLOT_SEED)
            mstore(0x00, from)
            let fromBalanceSlot := keccak256(0x0c, 0x20)
            let fromBalance := sload(fromBalanceSlot)
            // Revert if insufficient balance.
            if gt(amount, fromBalance) {
                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
                revert(0x1c, 0x04)
            }
            // Subtract and store the updated balance.
            sstore(fromBalanceSlot, sub(fromBalance, amount))
            // Subtract and store the updated total supply.
            sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount))
            // Emit the {Transfer} event.
            mstore(0x00, amount)
            log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0)
        }
        _afterTokenTransfer(from, address(0), amount);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                INTERNAL TRANSFER FUNCTIONS                 */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Moves `amount` of tokens from `from` to `to`.
    function _transfer(address from, address to, uint256 amount) internal virtual {
        _beforeTokenTransfer(from, to, amount);
        /// @solidity memory-safe-assembly
        assembly {
            let from_ := shl(96, from)
            // Compute the balance slot and load its value.
            mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
            let fromBalanceSlot := keccak256(0x0c, 0x20)
            let fromBalance := sload(fromBalanceSlot)
            // Revert if insufficient balance.
            if gt(amount, fromBalance) {
                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
                revert(0x1c, 0x04)
            }
            // Subtract and store the updated balance.
            sstore(fromBalanceSlot, sub(fromBalance, amount))
            // Compute the balance slot of `to`.
            mstore(0x00, to)
            let toBalanceSlot := keccak256(0x0c, 0x20)
            // Add and store the updated balance of `to`.
            // Will not overflow because the sum of all user balances
            // cannot exceed the maximum uint256 value.
            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
            // Emit the {Transfer} event.
            mstore(0x20, amount)
            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
        }
        _afterTokenTransfer(from, to, amount);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                INTERNAL ALLOWANCE FUNCTIONS                */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Updates the allowance of `owner` for `spender` based on spent `amount`.
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the allowance slot and load its value.
            mstore(0x20, spender)
            mstore(0x0c, _ALLOWANCE_SLOT_SEED)
            mstore(0x00, owner)
            let allowanceSlot := keccak256(0x0c, 0x34)
            let allowance_ := sload(allowanceSlot)
            // If the allowance is not the maximum uint256 value.
            if add(allowance_, 1) {
                // Revert if the amount to be transferred exceeds the allowance.
                if gt(amount, allowance_) {
                    mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
                    revert(0x1c, 0x04)
                }
                // Subtract and store the updated allowance.
                sstore(allowanceSlot, sub(allowance_, amount))
            }
        }
    }

    /// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`.
    ///
    /// Emits a {Approval} event.
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            let owner_ := shl(96, owner)
            // Compute the allowance slot and store the amount.
            mstore(0x20, spender)
            mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED))
            sstore(keccak256(0x0c, 0x34), amount)
            // Emit the {Approval} event.
            mstore(0x00, amount)
            log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c)))
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     HOOKS TO OVERRIDE                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Hook that is called before any transfer of tokens.
    /// This includes minting and burning.
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /// @dev Hook that is called after any transfer of tokens.
    /// This includes minting and burning.
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}

File 35 of 36 : NumberUtils.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.22;

library NumberUtils {
    function addCheckOverflow(uint256 a, uint256 b) internal pure returns (bool) {
        uint256 c = 0;
        unchecked {
            c = a + b;
        }
        return c < a || c < b;
    }

    function mulCheckOverflow(uint256 a, uint256 b) internal pure returns (bool) {
        if (a == 0 || b == 0) {
            return false;
        }
        uint256 c;
        unchecked {
            c = a * b;
        }
        return c / a != b;
    }

    function mulDivCheckOverflow(uint256 a, uint256 b, uint256 denominator) internal pure returns (bool) {
        // Taken from prb - math
        uint256 prod0; // Least significant 256 bits of the product
        uint256 prod1; // Most significant 256 bits of the product
        assembly ("memory-safe") {
            let mm := mulmod(a, b, not(0))
            prod0 := mul(a, b)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }
        return prod1 >= denominator;
    }
}

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

pragma solidity ^0.8.20;

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

Settings
{
  "remappings": [
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@prb/test/=lib/prb-math/lib/prb-test/src/",
    "chainlink/=lib/chainlink/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "prb-math/=lib/prb-math/src/",
    "prb-test/=lib/prb-math/lib/prb-test/src/",
    "solady/=lib/solady/",
    "solidity-code-metrics/=node_modules/solidity-code-metrics/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"uint48","name":"schedule","type":"uint48"}],"name":"AccessControlEnforcedDefaultAdminDelay","type":"error"},{"inputs":[],"name":"AccessControlEnforcedDefaultAdminRules","type":"error"},{"inputs":[{"internalType":"address","name":"defaultAdmin","type":"address"}],"name":"AccessControlInvalidDefaultAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"AmountTooLarge","type":"error"},{"inputs":[],"name":"Blacklist","type":"error"},{"inputs":[],"name":"DecimalsTooLarge","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"FeeTooLarge","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidOrderData","type":"error"},{"inputs":[],"name":"InvalidPrecision","type":"error"},{"inputs":[],"name":"LimitPriceNotSet","type":"error"},{"inputs":[],"name":"NotBuyOrder","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"NotRequester","type":"error"},{"inputs":[],"name":"OrderCancellationInitiated","type":"error"},{"inputs":[],"name":"OrderFillAboveLimitPrice","type":"error"},{"inputs":[],"name":"OrderFillBelowLimitPrice","type":"error"},{"inputs":[],"name":"OrderNotFound","type":"error"},{"inputs":[],"name":"OrderTypeMismatch","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"PRBMath_MulDiv18_Overflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"PRBMath_MulDiv_Overflow","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"UnreturnedEscrow","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"UnsupportedToken","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"}],"name":"CancelRequested","type":"event"},{"anonymous":false,"inputs":[],"name":"DefaultAdminDelayChangeCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"newDelay","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"effectSchedule","type":"uint48"}],"name":"DefaultAdminDelayChangeScheduled","type":"event"},{"anonymous":false,"inputs":[],"name":"DefaultAdminTransferCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"},{"indexed":false,"internalType":"uint48","name":"acceptSchedule","type":"uint48"}],"name":"DefaultAdminTransferScheduled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EscrowReturned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EscrowTaken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"paymentToken","type":"address"},{"components":[{"internalType":"uint64","name":"perOrderFeeBuy","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateBuy","type":"uint24"},{"internalType":"uint64","name":"perOrderFeeSell","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateSell","type":"uint24"}],"indexed":false,"internalType":"struct OrderProcessor.FeeRates","name":"feeRates","type":"tuple"}],"name":"FeesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"assetToken","type":"address"},{"indexed":false,"internalType":"int8","name":"decimals","type":"int8"}],"name":"MaxOrderDecimalsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"OrderCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"},{"indexed":false,"internalType":"address","name":"paymentToken","type":"address"},{"indexed":false,"internalType":"address","name":"assetToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"fillAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receivedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesPaid","type":"uint256"}],"name":"OrderFill","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"}],"name":"OrderFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"requester","type":"address"},{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"indexed":false,"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"}],"name":"OrderRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"paused","type":"bool"}],"name":"OrdersPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract ITokenLockCheck","name":"tokenLockCheck","type":"address"}],"name":"TokenLockCheckSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"treasury","type":"address"}],"name":"TreasurySet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"ASSETTOKEN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FORWARDER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"beginDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"},{"internalType":"string","name":"reason","type":"string"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"cancelRequested","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"}],"name":"changeDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelay","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelayIncreaseWait","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"requester","type":"address"}],"name":"escrowedBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"uint256","name":"paymentTokenOrderValue","type":"uint256"}],"name":"estimateTotalFeesForOrder","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"},{"internalType":"uint256","name":"fillAmount","type":"uint256"},{"internalType":"uint256","name":"receivedAmount","type":"uint256"}],"name":"fillOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"}],"name":"getAccountFees","outputs":[{"components":[{"internalType":"uint64","name":"perOrderFeeBuy","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateBuy","type":"uint24"},{"internalType":"uint64","name":"perOrderFeeSell","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateSell","type":"uint24"}],"internalType":"struct OrderProcessor.FeeRates","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"address","name":"paymentToken","type":"address"}],"name":"getFeeRatesForOrder","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getOrderEscrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getOrderStatus","outputs":[{"internalType":"enum IOrderProcessor.OrderStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getTotalReceived","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getUnfilledAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"}],"name":"hashOrder","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"}],"name":"hashOrderCalldata","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"contract ITokenLockCheck","name":"_tokenLockCheck","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"maxOrderDecimals","outputs":[{"internalType":"int8","name":"","type":"int8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextOrderId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numOpenOrders","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ordersPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdmin","outputs":[{"internalType":"address","name":"newAdmin","type":"address"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdminDelay","outputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"requestCancel","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"}],"name":"requestOrder","outputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"}],"name":"resetFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"returnEscrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rollbackDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"paymentToken","type":"address"},{"components":[{"internalType":"uint64","name":"perOrderFeeBuy","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateBuy","type":"uint24"},{"internalType":"uint64","name":"perOrderFeeSell","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateSell","type":"uint24"}],"internalType":"struct OrderProcessor.FeeRates","name":"feeRates","type":"tuple"}],"name":"setDefaultFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"components":[{"internalType":"uint64","name":"perOrderFeeBuy","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateBuy","type":"uint24"},{"internalType":"uint64","name":"perOrderFeeSell","type":"uint64"},{"internalType":"uint24","name":"percentageFeeRateSell","type":"uint24"}],"internalType":"struct OrderProcessor.FeeRates","name":"feeRates","type":"tuple"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"int8","name":"decimals","type":"int8"}],"name":"setMaxOrderDecimals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"pause","type":"bool"}],"name":"setOrdersPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ITokenLockCheck","name":"_tokenLockCheck","type":"address"}],"name":"setTokenLockCheck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"sell","type":"bool"},{"internalType":"enum IOrderProcessor.OrderType","name":"orderType","type":"uint8"},{"internalType":"uint256","name":"assetTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"paymentTokenQuantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"enum IOrderProcessor.TIF","name":"tif","type":"uint8"},{"internalType":"address","name":"splitRecipient","type":"address"},{"internalType":"uint256","name":"splitAmount","type":"uint256"}],"internalType":"struct IOrderProcessor.Order","name":"order","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"takeEscrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tokenLockCheck","outputs":[{"internalType":"contract ITokenLockCheck","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"}]

60a0604052306080523480156200001557600080fd5b506200002062000026565b620000da565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff1615620000775760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b0390811614620000d75780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b60805161587062000104600039600081816132220152818161324b015261338f01526158706000f3fe6080604052600436106103765760003560e01c8063853d23f4116101d1578063cefc142911610102578063e75a895a116100a0578063f64f67de1161006f578063f64f67de14610a8f578063f8cf1ada14610aaf578063feb5015314610acf578063fefa9ba914610aef57600080fd5b8063e75a895a14610a0d578063f0aac58714610a2d578063f0f4426014610a4d578063f5b541a614610a6d57600080fd5b8063d602b9fd116100dc578063d602b9fd146109a3578063d87f8ee1146109b8578063da0bef0d146109cd578063e683a2d4146109ed57600080fd5b8063cefc142914610933578063cf6eefb714610948578063d547741f1461098357600080fd5b8063ac9650d81161016f578063bb3a558911610149578063bb3a5589146108be578063c0c53b8b146108de578063c50dee0c146108fe578063cc8463c81461091e57600080fd5b8063ac9650d814610826578063ad3cb1cc14610853578063ba2332931461089157600080fd5b806391d14854116101ab57806391d148541461079d578063a1eda53c146107bd578063a217fddf146107f1578063a8e4192e1461080657600080fd5b8063853d23f414610748578063879344a1146107685780638da5cb5b1461078857600080fd5b80634b5e6890116102ab578063634e93da116102495780636d96132c116102235780636d96132c146106c05780636e49f903146106e057806381fed7081461071357806384ef8ffc1461073357600080fd5b8063634e93da1461064c578063649a5ec71461066c578063681f70f71461068c57600080fd5b80635ba437d2116102855780635ba437d2146105c95780635f09d933146105e957806361d027b31461062257806362c39a851461063757600080fd5b80634b5e6890146105815780634f1ef286146105a157806352d1902d146105b457600080fd5b80632a8c7bfa1161031857806334305065116102f257806334305065146104d357806335f6fb871461050057806336568abe1461053457806345fa8aae1461055457600080fd5b80632a8c7bfa146104735780632f2ff15d1461049357806332808b03146104b357600080fd5b80630c84003b116103545780630c84003b146103f057806319aafbaf14610410578063248a9ca31461043e5780632a58b3301461045e57600080fd5b806301ffc9a71461037b578063022d63fb146103b05780630aa6220b146103d9575b600080fd5b34801561038757600080fd5b5061039b6103963660046149d6565b610b29565b60405190151581526020015b60405180910390f35b3480156103bc57600080fd5b50620697805b60405165ffffffffffff90911681526020016103a7565b3480156103e557600080fd5b506103ee610b54565b005b3480156103fc57600080fd5b506103ee61040b366004614b3d565b610b6a565b34801561041c57600080fd5b5061043061042b366004614b85565b610bad565b6040519081526020016103a7565b34801561044a57600080fd5b50610430610459366004614bbe565b610be9565b34801561046a57600080fd5b50610430610c0b565b34801561047f57600080fd5b5061043061048e366004614c0e565b610c20565b34801561049f57600080fd5b506103ee6104ae366004614cce565b610c89565b3480156104bf57600080fd5b5061039b6104ce366004614bbe565b610cb5565b3480156104df57600080fd5b506104e8610ce2565b6040516001600160a01b0390911681526020016103a7565b34801561050c57600080fd5b506104307f3fb90a982568460bdf5505b984928e3c942db3525e60c25e39051cacec08b60f81565b34801561054057600080fd5b506103ee61054f366004614cce565b610d00565b34801561056057600080fd5b5061057461056f366004614bbe565b610dc9565b6040516103a79190614d09565b34801561058d57600080fd5b506103ee61059c366004614d23565b610def565b6103ee6105af366004614d40565b610e63565b3480156105c057600080fd5b50610430610e7e565b3480156105d557600080fd5b506103ee6105e4366004614e00565b610e9b565b3480156105f557600080fd5b50610609610604366004614e38565b610ffd565b6040805192835262ffffff9091166020830152016103a7565b34801561062e57600080fd5b506104e861115f565b34801561064357600080fd5b5061043061117a565b34801561065857600080fd5b506103ee610667366004614e83565b61118f565b34801561067857600080fd5b506103ee610687366004614ea0565b6111a3565b34801561069857600080fd5b506104307f22e9f4899cbd840357e113d5e255eb05266351f80fe8568f6c736829f9886f5a81565b3480156106cc57600080fd5b506104306106db366004614ec8565b6111b7565b3480156106ec57600080fd5b506107006106fb366004614e83565b6118d1565b60405160009190910b81526020016103a7565b34801561071f57600080fd5b5061043061072e366004614bbe565b611900565b34801561073f57600080fd5b506104e8611920565b34801561075457600080fd5b50610430610763366004614bbe565b611937565b34801561077457600080fd5b506103ee610783366004614ee5565b61195a565b34801561079457600080fd5b506104e8611971565b3480156107a957600080fd5b5061039b6107b8366004614cce565b611980565b3480156107c957600080fd5b506107d26119bb565b6040805165ffffffffffff9384168152929091166020830152016103a7565b3480156107fd57600080fd5b50610430600081565b34801561081257600080fd5b506103ee610821366004614b85565b611a40565b34801561083257600080fd5b50610846610841366004614f1b565b611b8b565b6040516103a79190614fdf565b34801561085f57600080fd5b50610884604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516103a79190615043565b34801561089d57600080fd5b506108b16108ac366004614b85565b611c74565b6040516103a79190615056565b3480156108ca57600080fd5b506103ee6108d9366004614e00565b611e06565b3480156108ea57600080fd5b506103ee6108f936600461509e565b611f72565b34801561090a57600080fd5b506104306109193660046150ce565b6120ed565b34801561092a57600080fd5b506103c2612119565b34801561093f57600080fd5b506103ee6121a9565b34801561095457600080fd5b5061095d6121e9565b604080516001600160a01b03909316835265ffffffffffff9091166020830152016103a7565b34801561098f57600080fd5b506103ee61099e366004614cce565b612217565b3480156109af57600080fd5b506103ee61223f565b3480156109c457600080fd5b5061039b612252565b3480156109d957600080fd5b506103ee6109e8366004614e83565b612271565b3480156109f957600080fd5b506103ee610a08366004614bbe565b6122d8565b348015610a1957600080fd5b506103ee610a2836600461511f565b6123ff565b348015610a3957600080fd5b50610430610a48366004614ec8565b612a3e565b348015610a5957600080fd5b506103ee610a68366004614e83565b612ae0565b348015610a7957600080fd5b506104306000805160206157fb83398151915281565b348015610a9b57600080fd5b506103ee610aaa36600461516d565b612b69565b348015610abb57600080fd5b506103ee610aca3660046151de565b612beb565b348015610adb57600080fd5b506103ee610aea366004615267565b612e70565b348015610afb57600080fd5b50610430610b0a366004614bbe565b600090815260008051602061579b833981519152602052604090205490565b60006001600160e01b031982166318a4c3c360e11b1480610b4e5750610b4e82612f7a565b92915050565b6000610b5f81612faf565b610b67612fb9565b50565b6000610b7581612faf565b6001600160a01b038416610b9c5760405163d92e233d60e01b815260040160405180910390fd5b610ba7848484612fc6565b50505050565b600080610bb86131a4565b6001600160a01b03948516600090815260069190910160209081526040808320959096168252939093525050205490565b600090815260008051602061581b833981519152602052604090206001015490565b600080610c166131a4565b6003015492915050565b80516020808301516040808501516060860151608087015160a088015160c089015160e08a01516101008b01516101208c01516101408d0151985160009c610c6c9c909b9a91016152c0565b604051602081830303815290604052805190602001209050919050565b81610ca757604051631fe1e13d60e11b815260040160405180910390fd5b610cb182826131c8565b5050565b600080610cc06131a4565b600093845260040160205250506040902060020154600160b81b900460ff1690565b600080610ced6131a4565b600101546001600160a01b031692915050565b6000805160206157db83398151915282158015610d355750610d20611920565b6001600160a01b0316826001600160a01b0316145b15610dba57600080610d456121e9565b90925090506001600160a01b038216151580610d67575065ffffffffffff8116155b80610d7a57504265ffffffffffff821610155b15610da7576040516319ca5ebb60e01b815265ffffffffffff821660048201526024015b60405180910390fd5b5050805465ffffffffffff60a01b191681555b610dc483836131e4565b505050565b600080610dd46131a4565b60009384526005016020525050604090206001015460ff1690565b6000610dfa81612faf565b6000610e046131a4565b600181018054851515600160a01b0260ff60a01b199091161790556040519091507feded67f5310120daa4cd7610cb05cee3ce8d5e6237b28455089b814371ef4c3c90610e5690851515815260200190565b60405180910390a1505050565b610e6b613217565b610e74826132bc565b610cb182826132c7565b6000610e88613384565b506000805160206157bb83398151915290565b6000805160206157fb833981519152610eb381612faf565b81600003610ed457604051637c946ed760e01b815260040160405180910390fd5b6000610edf856133cd565b9050610eea84612a3e565b8114610f095760405163a342e7d960e01b815260040160405180910390fd5b600085815260008051602061579b833981519152602081905260409091205480851115610f4957604051630625040160e01b815260040160405180910390fd5b610f53858261534a565b600088815260208490526040812091909155610f6e886133ed565b9050610f8a610f836060890160408a01614e83565b8288613420565b806001600160a01b0316887fb013294d91b96864e668e4bd96e04df167560e353af4268f952b16be9d40a78088604051610fc691815260200190565b60405180910390a3610ff33387610fe360608b0160408c01614e83565b6001600160a01b03169190613473565b5050505050505050565b600080600061100a6131a4565b6001600160a01b0380881660009081526008830160209081526040808320938916835292815290829020825160a081018452905460ff811615158083526001600160401b03610100830481169484019490945262ffffff600160481b8304811695840195909552600160601b82049093166060830152600160a01b90049092166080830152919250906111195750600080805260088201602090815260408083206001600160a01b0388168452825291829020825160a081018452905460ff8116151582526001600160401b03610100820481169383019390935262ffffff600160481b8204811694830194909452600160601b81049092166060820152600160a01b90910490911660808201525b851561113d5761112d8582606001516134d2565b8160800151935093505050611157565b61114b8582602001516134d2565b81604001519350935050505b935093915050565b60008061116a6131a4565b546001600160a01b031692915050565b6000806111856131a4565b6002015492915050565b600061119a81612faf565b610cb1826135a1565b60006111ae81612faf565b610cb182613614565b6000806111c26131a4565b6001810154909150600160a01b900460ff16156111f2576040516313d0ff5960e31b815260040160405180910390fd5b60006112016020850185614e83565b6001600160a01b0316036112285760405163d92e233d60e01b815260040160405180910390fd5b600061123a6080850160608601614d23565b611248578360c0013561124e565b8360a001355b90508060000361127157604051637c946ed760e01b815260040160405180910390fd5b60008461014001351180156112a05750600061129561014086016101208701614e83565b6001600160a01b0316145b156112be5760405163d92e233d60e01b815260040160405180910390fd5b60006112c86131a4565b90506112da6080860160608701614d23565b80611305575060016112f260a087016080880161535d565b600181111561130357611303614cf3565b145b156113f957600061131c6040870160208801614e83565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611359573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137d9190615378565b90506000600783018161139660408a0160208b01614e83565b6001600160a01b0316815260208101919091526040016000908120546113bd910b83615395565b6113c890600a61549a565b90506113d88160a08901356154bf565b156113f65760405163aa8828e760e01b815260040160405180910390fd5b50505b61142d7f22e9f4899cbd840357e113d5e255eb05266351f80fe8568f6c736829f9886f5a6107b86040880160208901614e83565b611466576114416040860160208701614e83565b604051635f8b555b60e11b81526001600160a01b039091166004820152602401610d9e565b600080805260088201602052604080822091906114899060608901908901614e83565b6001600160a01b0316815260208101919091526040016000205460ff166114ba576114416060860160408701614e83565b8060030154935060006114cc85613684565b90506001600160a01b0381166114f55760405163d92e233d60e01b815260040160405180910390fd5b61152b6115086040880160208901614e83565b6115186060890160408a01614e83565b61152560208a018a614e83565b8461371c565b6115368560016154d3565b60038301556115458587613978565b806001600160a01b0316857f0e8491ac313aa920e94e4571be1156423036e7e83268fbf0397fd05d88a466398860405161157f91906154e6565b60405180910390a36000806115ae8361159e60808b0160608c01614d23565b61060460608c0160408d01614e83565b915091506040518061010001604052806115d28a80360381019061048e9190614c0e565b81526020018381526020018262ffffff168152602001846001600160a01b0316815260200160001515815260200160008152602001600081526020016000815250846004016000898152602001908152602001600020600082015181600001556020820151816001015560408201518160020160006101000a81548162ffffff021916908362ffffff16021790555060608201518160020160036101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160020160176101000a81548160ff02191690831515021790555060a0820151816003015560c0820151816004015560e082015181600501559050506040518060400160405280868152602001600060028111156116f3576116f3614cf3565b905260008881526005860160209081526040909120825181559082015160018083018054909160ff199091169083600281111561173257611732614cf3565b0217905550505060028401805490600061174b836155cd565b9091555061176190506080890160608a01614d23565b1561180f5760a088013560068501600061178160408c0160208d01614e83565b6001600160a01b031681526020808201929092526040016000908120916117aa908c018c614e83565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546117d991906154d3565b9091555061180a9050333060a08b01356117f960408d0160208e01614e83565b6001600160a01b03169291906139d6565b6118c6565b600061182083838b60c00135613a0f565b905060006118328260c08c01356154d3565b90508060068701600061184b60608e0160408f01614e83565b6001600160a01b03168152602080820192909252604001600090812091611874908e018e614e83565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546118a391906154d3565b925050819055506118c33330838d60400160208101906117f99190614e83565b50505b505050505050919050565b6000806118dc6131a4565b6001600160a01b039093166000908152600790930160205250506040812054900b90565b60008061190b6131a4565b60009384526005016020525050604090205490565b6000806000805160206157db833981519152610ced565b6000806119426131a4565b60009384526004016020525050604090206003015490565b600061196581612faf565b610dc460008484612fc6565b600061197b611920565b905090565b600082815260008051602061581b833981519152602090815260408083206001600160a01b038516845290915281205460ff165b9392505050565b7feef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d869840154600090600160d01b900465ffffffffffff166000805160206157db8339815191528115801590611a1557504265ffffffffffff831610155b611a2157600080611a37565b6001810154600160a01b900465ffffffffffff16825b92509250509091565b6000611a4b81612faf565b6001600160a01b038316611a725760405163d92e233d60e01b815260040160405180910390fd5b6000611a7c6131a4565b6001600160a01b0385811660008181526008840160208181526040808420958a1680855295825280842080546001600160b81b0319169055838052918152818320858452815291819020815160a081018352905460ff8116151582526001600160401b036101008204811683860190815262ffffff600160481b84048116858701908152600160601b850484166060808801918252600160a01b9096048316608080890191825289519081018a529451861685529151831698840198909852965190921681860152945116908401529051949550937fd4b23f319fe513df34cddf75df188ebfb16db475655c7828421dc90c5c53244c91611b7c91615056565b60405180910390a35050505050565b6060816001600160401b03811115611ba557611ba5614a25565b604051908082528060200260200182016040528015611bd857816020015b6060815260200190600190039081611bc35790505b50905060005b82811015611c6d57611c4830858584818110611bfc57611bfc6155e6565b9050602002810190611c0e91906155fc565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613a3892505050565b828281518110611c5a57611c5a6155e6565b6020908102919091010152600101611bde565b5092915050565b604080516080810182526000808252602082018190529181018290526060810182905290611ca06131a4565b6001600160a01b0380861660009081526008830160209081526040808320938816835292815290829020825160a081018452905460ff811615158083526001600160401b03610100830481169484019490945262ffffff600160481b8304811695840195909552600160601b82049093166060830152600160a01b9004909216608083015291925090611daf5750600080805260088201602090815260408083206001600160a01b0387168452825291829020825160a081018452905460ff8116151582526001600160401b03610100820481169383019390935262ffffff600160481b8204811694830194909452600160601b81049092166060820152600160a01b90910490911660808201525b604051806080016040528082602001516001600160401b03168152602001826040015162ffffff16815260200182606001516001600160401b03168152602001826080015162ffffff168152509250505092915050565b6000805160206157fb833981519152611e1e81612faf565b81600003611e3f57604051637c946ed760e01b815260040160405180910390fd5b6000611e4a856133cd565b9050611e5584612a3e565b8114611e745760405163a342e7d960e01b815260040160405180910390fd5b6000611e7f86611900565b600087815260008051602061579b83398151915260208190526040909120549192509082611ead87836154d3565b1115611ecc57604051630625040160e01b815260040160405180910390fd5b611ed686826154d3565b600089815260208490526040812091909155611ef1896133ed565b9050611f0d611f0660608a0160408b01614e83565b8289613aae565b806001600160a01b0316897ff58c78c7658c89a31db2cce8dd547cbf5015572035f58f9aca5dc5a3568f3a2689604051611f4991815260200190565b60405180910390a3611f673330896117f960608d0160408e01614e83565b505050505050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b0316600081158015611fb75750825b90506000826001600160401b03166001148015611fd35750303b155b905081158015611fe1575080155b15611fff5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561202957845460ff60401b1916600160401b1785555b612034600089613af6565b61203c613b08565b6001600160a01b0387166120635760405163d92e233d60e01b815260040160405180910390fd5b600061206d6131a4565b80546001600160a01b03808b166001600160a01b031992831617835560019092018054928a1692909116919091179055508315610ff357845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15050505050505050565b60008060006120fd878787610ffd565b9150915061210c828286613a0f565b925050505b949350505050565b7feef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698401546000906000805160206157db83398151915290600160d01b900465ffffffffffff16801580159061217357504265ffffffffffff8216105b61218d578154600160d01b900465ffffffffffff166121a2565b6001820154600160a01b900465ffffffffffff165b9250505090565b60006121b36121e9565b509050336001600160a01b038216146121e157604051636116401160e11b8152336004820152602401610d9e565b610b67613b10565b6000805160206157db833981519152546001600160a01b03811691600160a01b90910465ffffffffffff1690565b8161223557604051631fe1e13d60e11b815260040160405180910390fd5b610cb18282613bad565b600061224a81612faf565b610b67613bc9565b60008061225d6131a4565b60010154600160a01b900460ff1692915050565b600061227c81612faf565b60006122866131a4565b6001810180546001600160a01b0319166001600160a01b038616908117909155604051919250907f10806d5d70e6f30969b0108ce176b903fca9b758b7341d271f69963323da313c90600090a2505050565b60006122e26131a4565b6000838152600482016020526040902060020154909150600160b81b900460ff16156123215760405163a9d0268d60e01b815260040160405180910390fd5b6000828152600482016020526040902060020154630100000090046001600160a01b0316806123635760405163d36d896560e01b815260040160405180910390fd5b600061236e84613684565b9050806001600160a01b0316826001600160a01b0316146123a2576040516371ced2cf60e11b815260040160405180910390fd5b6000848152600484016020526040808220600201805460ff60b81b1916600160b81b179055516001600160a01b0384169186917f4f45a3bbce2de4ee8d69d6bf7dd2455dc927f1d1a50725b7292e0bf5aa06d8ab9190a350505050565b6000805160206157fb83398151915261241781612faf565b8260000361243857604051637c946ed760e01b815260040160405180910390fd5b60006124426131a4565b60008781526004828101602090815260409283902083516101008101855281548152600182015492810192909252600281015462ffffff811694830194909452630100000084046001600160a01b031660608301819052600160b81b90940460ff1615156080830152600381015460a08301529182015460c082015260059091015460e08201529192506124e95760405163d36d896560e01b815260040160405180910390fd5b6124f286612a3e565b8151146125125760405163a342e7d960e01b815260040160405180910390fd5b600087815260058301602090815260408083208151808301909252805482526001810154919290919083019060ff16600281111561255257612552614cf3565b600281111561256357612563614cf3565b905250805190915086111561258b57604051630625040160e01b815260040160405180910390fd5b6000806125a08a8a8686600001518c8c613bd4565b9150915083606001516001600160a01b03168a7fbd6e615cc8b2df8e15d6dfae6fdaafad4fe24965addd99b870dda4aab1cf39328b60400160208101906125e79190614e83565b6125f760408e0160208f01614e83565b604080516001600160a01b03938416815292909116602083015281018c9052606081018b90526080810185905260a00160405180910390a360006101408a01351561269d578961014001358560e00151101561269d57600061265f60808c0160608d01614d23565b612669578861266b565b835b905060008660e001518c6101400135612684919061534a565b9050808211156126965780925061269a565b8192505b50505b6126c88b8560000151878d60600160208101906126ba9190614d23565b8e60c001358e8e8989613c43565b6126d860808b0160608c01614d23565b1561284457886006870160006126f460408e0160208f01614e83565b6001600160a01b0316815260208082019290925260400160009081209161271d908e018e614e83565b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461274c919061534a565b90915550612762905060408b0160208c01614e83565b6001600160a01b03166342966c688a6040518263ffffffff1660e01b815260040161278f91815260200190565b600060405180830381600087803b1580156127a957600080fd5b505af11580156127bd573d6000803e3d6000fd5b505050506127da33308a8d60400160208101906117f99190614e83565b8015612806576128066127f56101408c016101208d01614e83565b82610fe360608e0160408f01614e83565b6000612812828561534a565b9050801561283e5761283e61282a60208d018d614e83565b828d6040016020810190610fe39190614e83565b50612a0b565b61284e82846154d3565b60068701600061286460608e0160408f01614e83565b6001600160a01b0316815260208082019290925260400160009081209161288d908e018e614e83565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546128bc919061534a565b909155506128d790503384610fe360608e0160408f01614e83565b8015612969576128ed60408b0160208c01614e83565b6001600160a01b03166340c10f1961290860208d018d614e83565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b15801561295057600080fd5b505af1158015612964573d6000803e3d6000fd5b505050505b6000612975828a61534a565b90508015612a095761298d60408c0160208d01614e83565b6001600160a01b03166340c10f196129a860208e018e614e83565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b1580156129f057600080fd5b505af1158015612a04573d6000803e3d6000fd5b505050505b505b8115612a31578554612a31906001600160a01b031683610fe360608e0160408f01614e83565b5050505050505050505050565b6000612a4d6020830183614e83565b612a5d6040840160208501614e83565b612a6d6060850160408601614e83565b612a7d6080860160608701614d23565b612a8d60a087016080880161535d565b60a087013560c088013560e0890135612aae6101208b016101008c01615649565b612ac06101408c016101208d01614e83565b8b6101400135604051602001610c6c9b9a999897969594939291906152c0565b6000612aeb81612faf565b6001600160a01b038216612b125760405163d92e233d60e01b815260040160405180910390fd5b6000612b1c6131a4565b80546001600160a01b0319166001600160a01b0385169081178255604051919250907f3c864541ef71378c6229510ed90f376565ee42d9c5e0904a984a9e863e6db44f90600090a2505050565b60405163d505accf60e01b81526001600160a01b038781166004830152306024830152604482018790526064820186905260ff8516608483015260a4820184905260c4820183905288169063d505accf9060e401600060405180830381600087803b158015612bd757600080fd5b505af1158015612a31573d6000803e3d6000fd5b6000805160206157fb833981519152612c0381612faf565b6000612c0d6131a4565b60008781526004828101602090815260409283902083516101008101855281548152600182015492810192909252600281015462ffffff811694830194909452630100000084046001600160a01b031660608301819052600160b81b90940460ff1615156080830152600381015460a08301529182015460c082015260059091015460e0820152919250612cb45760405163d36d896560e01b815260040160405180910390fd5b612cbd86612a3e565b815114612cdd5760405163a342e7d960e01b815260040160405180910390fd5b60008781526005838101602090815260408084206001908101805460ff19166002908117909155600480890190945291852085815590810185905580820180546001600160c01b03191690556003810185905591820184905591018290558301805491612d4983615664565b919050555080606001516001600160a01b0316877ff2820c9274d611a15d979823ac23bb965c1972a808eebd952297d9bd3a60f4b88787604051612d8e92919061567b565b60405180910390a36000878152600583016020526040812054612db690899089908590613dd1565b90506000612dca6080890160608a01614d23565b612de357612dde6060890160408a01614e83565b612df3565b612df36040890160208a01614e83565b6001600160a01b03811660009081526006860160209081526040822092935084929190612e22908c018c614e83565b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254612e51919061534a565b90915550506060830151611f67906001600160a01b0383169084613473565b6000612e7b81612faf565b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ebb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612edf9190615378565b90508060000b8360000b1315612f085760405163aa8828e760e01b815260040160405180910390fd5b6000612f126131a4565b6001600160a01b03861660008181526007830160209081526040808320805460ff191660ff8b16179055519188900b825292935090917fe7239279c8eed71aa3c3725e6858242c0238bb4198777634effdf39c4fd2c89f910160405180910390a25050505050565b60006001600160e01b03198216637965db0b60e01b1480610b4e57506301ffc9a760e01b6001600160e01b0319831614610b4e565b610b678133613e2a565b612fc4600080613e63565b565b612fd38160200151613f50565b612fe08160600151613f50565b6000612fea6131a4565b90506040518060a0016040528060011515815260200183600001516001600160401b03168152602001836020015162ffffff16815260200183604001516001600160401b03168152602001836060015162ffffff16815250816008016000866001600160a01b03166001600160a01b031681526020019081526020016000206000856001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548160ff02191690831515021790555060208201518160000160016101000a8154816001600160401b0302191690836001600160401b0316021790555060408201518160000160096101000a81548162ffffff021916908362ffffff160217905550606082015181600001600c6101000a8154816001600160401b0302191690836001600160401b0316021790555060808201518160000160146101000a81548162ffffff021916908362ffffff160217905550905050826001600160a01b0316846001600160a01b03167fd4b23f319fe513df34cddf75df188ebfb16db475655c7828421dc90c5c53244c846040516131969190615056565b60405180910390a350505050565b7f8036d9ca2814a3bcd78d3e8aba96b71e7697006bd322a98e7f5f0f41b09a8b0090565b6131d182610be9565b6131da81612faf565b610ba78383613f78565b6001600160a01b038116331461320d5760405163334bd91960e11b815260040160405180910390fd5b610dc48282613fe7565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061329e57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166132926000805160206157bb833981519152546001600160a01b031690565b6001600160a01b031614155b15612fc45760405163703e46dd60e11b815260040160405180910390fd5b6000610cb181612faf565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015613321575060408051601f3d908101601f1916820190925261331e918101906156aa565b60015b61334957604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610d9e565b6000805160206157bb833981519152811461337a57604051632a87526960e21b815260048101829052602401610d9e565b610dc48383614040565b306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614612fc45760405163703e46dd60e11b815260040160405180910390fd5b6000806133d86131a4565b60009384526004016020525050604090205490565b6000806133f86131a4565b600093845260040160205250506040902060020154630100000090046001600160a01b031690565b600061342a6131a4565b6001600160a01b038086166000908152600683016020908152604080832093881683529290529081208054929350849290919061346890849061534a565b909155505050505050565b6040516001600160a01b03838116602483015260448201839052610dc491859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050614096565b600080836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613513573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135379190615378565b905060128160ff16111561355e57604051633c9c1e2d60e01b815260040160405180910390fd5b6001600160401b0383169150811580159061357c575060128160ff16105b15611c6d5761358c8160126156c3565b61359790600a61549a565b61211190836156dc565b60006135ab612119565b6135b4426140f9565b6135be91906156f0565b90506135ca8282614130565b60405165ffffffffffff821681526001600160a01b038316907f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed69060200160405180910390a25050565b600061361f826141bd565b613628426140f9565b61363291906156f0565b905061363e8282613e63565b6040805165ffffffffffff8085168252831660208201527ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b910160405180910390a15050565b60006136b07f3fb90a982568460bdf5505b984928e3c942db3525e60c25e39051cacec08b60f33611980565b156137155760405163133f730360e21b8152600481018390523390634cfdcc0c90602401602060405180830381865afa1580156136f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4e919061570f565b5033919050565b60006137266131a4565b600181015460405163010270a960e71b81526001600160a01b03888116600483015286811660248301529293509116908190638138548090604401602060405180830381865afa15801561377e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137a2919061572c565b156137c05760405163c95b482560e01b815260040160405180910390fd5b60405163010270a960e71b81526001600160a01b0387811660048301528481166024830152821690638138548090604401602060405180830381865afa15801561380e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613832919061572c565b156138505760405163c95b482560e01b815260040160405180910390fd5b60405163010270a960e71b81526001600160a01b0386811660048301528581166024830152821690638138548090604401602060405180830381865afa15801561389e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138c2919061572c565b156138e05760405163c95b482560e01b815260040160405180910390fd5b60405163010270a960e71b81526001600160a01b0386811660048301528481166024830152821690638138548090604401602060405180830381865afa15801561392e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613952919061572c565b156139705760405163c95b482560e01b815260040160405180910390fd5b505050505050565b6139886080820160608301614d23565b156139a657604051630c8a506160e21b815260040160405180910390fd5b6139b08282614205565b600091825260008051602061579b833981519152602052604090912060c0909101359055565b6040516001600160a01b038481166024830152838116604483015260648201839052610ba79186918216906323b872dd906084016134a0565b8262ffffff8316156119b457613a2e8262ffffff8516620f4240614255565b61211190826154d3565b6060600080846001600160a01b031684604051613a559190615749565b600060405180830381855af49150503d8060008114613a90576040519150601f19603f3d011682016040523d82523d6000602084013e613a95565b606091505b5091509150613aa5858383614329565b95945050505050565b6000613ab86131a4565b6001600160a01b03808616600090815260068301602090815260408083209388168352929052908120805492935084929091906134689084906154d3565b613afe614380565b610cb182826143c9565b612fc4614380565b6000805160206157db833981519152600080613b2a6121e9565b91509150613b3f8165ffffffffffff16151590565b1580613b5357504265ffffffffffff821610155b15613b7b576040516319ca5ebb60e01b815265ffffffffffff82166004820152602401610d9e565b613b8d6000613b88611920565b613fe7565b50613b99600083613f78565b505081546001600160d01b03191690915550565b613bb682610be9565b613bbf81612faf565b610ba78383613fe7565b612fc4600080614130565b600086815260008051602061579b83398151915260208190526040822054829190613bff818861534a565b861115613c1f57604051630625040160e01b815260040160405180910390fd5b60009350613c318a8a8a8a8a8a614432565b949b949a509398505050505050505050565b6000613c4d6131a4565b90506000613c5b868b61534a565b60008c81526005840160205260408120829055909150819003613d285760008b81526005838101602090815260408084206001908101805460ff1916821790556004808801909352908420848155908101849055600280820180546001600160c01b0319169055600382018590559181018490559091018290558301805491613ce383615664565b919050555088606001516001600160a01b03168b7fe5f48e2a4a303d196ad814389aa54cf34e7b1e404e740599d005907a2ca0cd6c60405160405180910390a3612a31565b6000848a60c00151613d3a91906154d3565b905088613d6a576000613d568b602001518c604001518b613a0f565b905080821115613d6857613d68615765565b505b858a60a00151613d7a91906154d3565b60008d8152600480860160205260409091206003810192909255018190558315613dc357838a60e00151613dae91906154d3565b60008d81526004850160205260409020600501555b505050505050505050505050565b600084815260008051602061579b83398151915260208190526040822054838114613e0f5760405163191e664760e11b815260040160405180910390fd5b60008781526020839052604081205561210c8787878761461c565b613e348282611980565b610cb15760405163e2517d3f60e01b81526001600160a01b038216600482015260248101839052604401610d9e565b7feef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698401546000805160206157db83398151915290600160d01b900465ffffffffffff168015613f12574265ffffffffffff82161015613ee857600182015482546001600160d01b0316600160a01b90910465ffffffffffff16600160d01b02178255613f12565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec590600090a15b5060010180546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b620f424062ffffff821610610b6757604051637e2df70960e11b815260040160405180910390fd5b60006000805160206157db83398151915283613fdd576000613f98611920565b6001600160a01b031614613fbf57604051631fe1e13d60e11b815260040160405180910390fd5b6001810180546001600160a01b0319166001600160a01b0385161790555b6121118484614691565b60006000805160206157db8339815191528315801561401e5750614009611920565b6001600160a01b0316836001600160a01b0316145b15614036576001810180546001600160a01b03191690555b6121118484614736565b614049826147b2565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a280511561408e57610dc48282613a38565b610cb1614817565b60006140ab6001600160a01b03841683614836565b905080516000141580156140d05750808060200190518101906140ce919061572c565b155b15610dc457604051635274afe760e01b81526001600160a01b0384166004820152602401610d9e565b600065ffffffffffff82111561412c576040516306dfcc6560e41b81526030600482015260248101839052604401610d9e565b5090565b6000805160206157db83398151915260006141496121e9565b835465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b03881617178455915061418990508165ffffffffffff16151590565b15610ba7576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510990600090a150505050565b6000806141c8612119565b90508065ffffffffffff168365ffffffffffff16116141f0576141eb838261577b565b6119b4565b6119b465ffffffffffff841662069780614844565b600161421760a083016080840161535d565b600181111561422857614228614cf3565b148015614237575060e0810135155b15610cb157604051630d7eec7360e21b815260040160405180910390fd5b600080806000198587098587029250828110838203039150508060000361428f57838281614285576142856154a9565b04925050506119b4565b8381106142c057604051630c740aef60e31b8152600481018790526024810186905260448101859052606401610d9e565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b606082614339576141eb8261485a565b815115801561435057506001600160a01b0384163b155b1561437957604051639996b31560e01b81526001600160a01b0385166004820152602401610d9e565b50806119b4565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16612fc457604051631afcd79f60e31b815260040160405180910390fd5b6143d1614380565b6000805160206157db8339815191526001600160a01b03821661440a57604051636116401160e11b815260006004820152602401610d9e565b80546001600160d01b0316600160d01b65ffffffffffff851602178155610ba7600083613f78565b6000806144456080880160608901614d23565b1561454757600161445c60a0890160808a0161535d565b600181111561446d5761446d614cf3565b1480156144865750614483848860e00135614883565b83105b156144a457604051637d18445b60e01b815260040160405180910390fd5b600086602001518760c0015110156144f45760008760c0015188602001516144cc919061534a565b9050808511156144ea579150816144e3818661534a565b91506144ee565b8492505b506144f7565b50825b60008111801561451057506000876040015162ffffff16115b156145355761452881886040015162ffffff16614883565b61453290836154d3565b91505b61453f828561534a565b925050614611565b600161455960a0890160808a0161535d565b600181111561456a5761456a614cf3565b14801561458c575061458984670de0b6b3a76400008960e00135614255565b83105b156145aa57604051630650e54560e41b815260040160405180910390fd5b839150600090508560c001516000036145c4575060208501515b60006145dd876020015188604001518a60c00135613a0f565b905060008760200151826145f1919061534a565b905061460281878b60c00135614255565b61460c90846154d3565b925050505b965096945050505050565b600061462e6080850160608601614d23565b1561463a575080612111565b6000614653846020015185604001518760c00135613a0f565b905061465f81846154d3565b915061466f8160c08701356154d3565b8210156146885760c0840151614685908361534a565b91505b50949350505050565b600060008051602061581b8339815191526146ac8484611980565b61472c576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556146e23390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a46001915050610b4e565b6000915050610b4e565b600060008051602061581b8339815191526147518484611980565b1561472c576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a46001915050610b4e565b806001600160a01b03163b6000036147e857604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610d9e565b6000805160206157bb83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b3415612fc45760405163b398979f60e01b815260040160405180910390fd5b60606119b483836000614939565b600081831061485357816119b4565b5090919050565b80511561486a5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60008080600019848609848602925082811083820303915050806000036148b75750670de0b6b3a764000090049050610b4e565b670de0b6b3a764000081106148e957604051635173648d60e01b81526004810186905260248101859052604401610d9e565b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60608147101561495e5760405163cd78605960e01b8152306004820152602401610d9e565b600080856001600160a01b0316848660405161497a9190615749565b60006040518083038185875af1925050503d80600081146149b7576040519150601f19603f3d011682016040523d82523d6000602084013e6149bc565b606091505b50915091506149cc868383614329565b9695505050505050565b6000602082840312156149e857600080fd5b81356001600160e01b0319811681146119b457600080fd5b6001600160a01b0381168114610b6757600080fd5b8035614a2081614a00565b919050565b634e487b7160e01b600052604160045260246000fd5b60405161016081016001600160401b0381118282101715614a5e57614a5e614a25565b60405290565b604051601f8201601f191681016001600160401b0381118282101715614a8c57614a8c614a25565b604052919050565b80356001600160401b0381168114614a2057600080fd5b803562ffffff81168114614a2057600080fd5b600060808284031215614ad057600080fd5b604051608081018181106001600160401b0382111715614af257614af2614a25565b604052905080614b0183614a94565b8152614b0f60208401614aab565b6020820152614b2060408401614a94565b6040820152614b3160608401614aab565b60608201525092915050565b600080600060c08486031215614b5257600080fd5b8335614b5d81614a00565b92506020840135614b6d81614a00565b9150614b7c8560408601614abe565b90509250925092565b60008060408385031215614b9857600080fd5b8235614ba381614a00565b91506020830135614bb381614a00565b809150509250929050565b600060208284031215614bd057600080fd5b5035919050565b8015158114610b6757600080fd5b8035614a2081614bd7565b803560028110614a2057600080fd5b803560048110614a2057600080fd5b60006101608284031215614c2157600080fd5b614c29614a3b565b614c3283614a15565b8152614c4060208401614a15565b6020820152614c5160408401614a15565b6040820152614c6260608401614be5565b6060820152614c7360808401614bf0565b608082015260a083013560a082015260c083013560c082015260e083013560e0820152610100614ca4818501614bff565b90820152610120614cb6848201614a15565b90820152610140928301359281019290925250919050565b60008060408385031215614ce157600080fd5b823591506020830135614bb381614a00565b634e487b7160e01b600052602160045260246000fd5b6020810160038310614d1d57614d1d614cf3565b91905290565b600060208284031215614d3557600080fd5b81356119b481614bd7565b60008060408385031215614d5357600080fd5b8235614d5e81614a00565b91506020838101356001600160401b0380821115614d7b57600080fd5b818601915086601f830112614d8f57600080fd5b813581811115614da157614da1614a25565b614db3601f8201601f19168501614a64565b91508082528784828501011115614dc957600080fd5b80848401858401376000848284010152508093505050509250929050565b60006101608284031215614dfa57600080fd5b50919050565b60008060006101a08486031215614e1657600080fd5b83359250614e278560208601614de7565b915061018084013590509250925092565b600080600060608486031215614e4d57600080fd5b8335614e5881614a00565b92506020840135614e6881614bd7565b91506040840135614e7881614a00565b809150509250925092565b600060208284031215614e9557600080fd5b81356119b481614a00565b600060208284031215614eb257600080fd5b813565ffffffffffff811681146119b457600080fd5b60006101608284031215614edb57600080fd5b6119b48383614de7565b60008060a08385031215614ef857600080fd5b8235614f0381614a00565b9150614f128460208501614abe565b90509250929050565b60008060208385031215614f2e57600080fd5b82356001600160401b0380821115614f4557600080fd5b818501915085601f830112614f5957600080fd5b813581811115614f6857600080fd5b8660208260051b8501011115614f7d57600080fd5b60209290920196919550909350505050565b60005b83811015614faa578181015183820152602001614f92565b50506000910152565b60008151808452614fcb816020860160208601614f8f565b601f01601f19169290920160200192915050565b600060208083016020845280855180835260408601915060408160051b87010192506020870160005b8281101561503657603f19888603018452615024858351614fb3565b94509285019290850190600101615008565b5092979650505050505050565b6020815260006119b46020830184614fb3565b60006080820190506001600160401b03808451168352602084015162ffffff808216602086015282604087015116604086015280606087015116606086015250505092915050565b6000806000606084860312156150b357600080fd5b83356150be81614a00565b92506020840135614e6881614a00565b600080600080608085870312156150e457600080fd5b84356150ef81614a00565b935060208501356150ff81614bd7565b9250604085013561510f81614a00565b9396929550929360600135925050565b6000806000806101c0858703121561513657600080fd5b843593506151478660208701614de7565b9396939550505050610180820135916101a0013590565b60ff81168114610b6757600080fd5b600080600080600080600060e0888a03121561518857600080fd5b873561519381614a00565b965060208801356151a381614a00565b9550604088013594506060880135935060808801356151c18161515e565b9699959850939692959460a0840135945060c09093013592915050565b6000806000806101a085870312156151f557600080fd5b843593506152068660208701614de7565b92506101808501356001600160401b038082111561522357600080fd5b818701915087601f83011261523757600080fd5b81358181111561524657600080fd5b88602082850101111561525857600080fd5b95989497505060200194505050565b6000806040838503121561527a57600080fd5b823561528581614a00565b91506020830135600081900b8114614bb357600080fd5b600281106152ac576152ac614cf3565b9052565b600481106152ac576152ac614cf3565b6001600160a01b038c811682528b811660208301528a8116604083015289151560608301526101608201906152f8608084018b61529c565b8860a08401528760c08401528660e08401526153186101008401876152b0565b9390931661012082015261014001529998505050505050505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610b4e57610b4e615334565b60006020828403121561536f57600080fd5b6119b482614bf0565b60006020828403121561538a57600080fd5b81516119b48161515e565b600082810b9082900b03607f198112607f82131715610b4e57610b4e615334565b600181815b808511156153f15781600019048211156153d7576153d7615334565b808516156153e457918102915b93841c93908002906153bb565b509250929050565b60008261540857506001610b4e565b8161541557506000610b4e565b816001811461542b576002811461543557615451565b6001915050610b4e565b60ff84111561544657615446615334565b50506001821b610b4e565b5060208310610133831016604e8410600b8410161715615474575081810a610b4e565b61547e83836153b6565b806000190482111561549257615492615334565b029392505050565b60006119b460ff8416836153f9565b634e487b7160e01b600052601260045260246000fd5b6000826154ce576154ce6154a9565b500690565b80820180821115610b4e57610b4e615334565b6101608101615505826154f885614a15565b6001600160a01b03169052565b61551160208401614a15565b6001600160a01b0316602083015261552b60408401614a15565b6001600160a01b0316604083015261554560608401614be5565b1515606083015261555860808401614bf0565b615565608084018261529c565b5060a083013560a083015260c083013560c083015260e083013560e0830152610100615592818501614bff565b61559e828501826152b0565b50506101206155ae818501614a15565b6001600160a01b03811684830152505061014092830135919092015290565b6000600182016155df576155df615334565b5060010190565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261561357600080fd5b8301803591506001600160401b0382111561562d57600080fd5b60200191503681900382131561564257600080fd5b9250929050565b60006020828403121561565b57600080fd5b6119b482614bff565b60008161567357615673615334565b506000190190565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b6000602082840312156156bc57600080fd5b5051919050565b60ff8281168282160390811115610b4e57610b4e615334565b6000826156eb576156eb6154a9565b500490565b65ffffffffffff818116838216019080821115611c6d57611c6d615334565b60006020828403121561572157600080fd5b81516119b481614a00565b60006020828403121561573e57600080fd5b81516119b481614bd7565b6000825161575b818460208701614f8f565b9190910192915050565b634e487b7160e01b600052600160045260246000fd5b65ffffffffffff828116828216039080821115611c6d57611c6d61533456fe9ef2e27f0661cd1c5e17cad73e47154b2655f2434621cc5680ed2d93095efa00360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbceef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d869840097667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b92902dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800a2646970667358221220dd9e6caa8e0b6e61eee1a9608842e59f9d074f42ac02fcec37946ae7d45dbfb364736f6c63430008160033

Deployed Bytecode

0x6080604052600436106103765760003560e01c8063853d23f4116101d1578063cefc142911610102578063e75a895a116100a0578063f64f67de1161006f578063f64f67de14610a8f578063f8cf1ada14610aaf578063feb5015314610acf578063fefa9ba914610aef57600080fd5b8063e75a895a14610a0d578063f0aac58714610a2d578063f0f4426014610a4d578063f5b541a614610a6d57600080fd5b8063d602b9fd116100dc578063d602b9fd146109a3578063d87f8ee1146109b8578063da0bef0d146109cd578063e683a2d4146109ed57600080fd5b8063cefc142914610933578063cf6eefb714610948578063d547741f1461098357600080fd5b8063ac9650d81161016f578063bb3a558911610149578063bb3a5589146108be578063c0c53b8b146108de578063c50dee0c146108fe578063cc8463c81461091e57600080fd5b8063ac9650d814610826578063ad3cb1cc14610853578063ba2332931461089157600080fd5b806391d14854116101ab57806391d148541461079d578063a1eda53c146107bd578063a217fddf146107f1578063a8e4192e1461080657600080fd5b8063853d23f414610748578063879344a1146107685780638da5cb5b1461078857600080fd5b80634b5e6890116102ab578063634e93da116102495780636d96132c116102235780636d96132c146106c05780636e49f903146106e057806381fed7081461071357806384ef8ffc1461073357600080fd5b8063634e93da1461064c578063649a5ec71461066c578063681f70f71461068c57600080fd5b80635ba437d2116102855780635ba437d2146105c95780635f09d933146105e957806361d027b31461062257806362c39a851461063757600080fd5b80634b5e6890146105815780634f1ef286146105a157806352d1902d146105b457600080fd5b80632a8c7bfa1161031857806334305065116102f257806334305065146104d357806335f6fb871461050057806336568abe1461053457806345fa8aae1461055457600080fd5b80632a8c7bfa146104735780632f2ff15d1461049357806332808b03146104b357600080fd5b80630c84003b116103545780630c84003b146103f057806319aafbaf14610410578063248a9ca31461043e5780632a58b3301461045e57600080fd5b806301ffc9a71461037b578063022d63fb146103b05780630aa6220b146103d9575b600080fd5b34801561038757600080fd5b5061039b6103963660046149d6565b610b29565b60405190151581526020015b60405180910390f35b3480156103bc57600080fd5b50620697805b60405165ffffffffffff90911681526020016103a7565b3480156103e557600080fd5b506103ee610b54565b005b3480156103fc57600080fd5b506103ee61040b366004614b3d565b610b6a565b34801561041c57600080fd5b5061043061042b366004614b85565b610bad565b6040519081526020016103a7565b34801561044a57600080fd5b50610430610459366004614bbe565b610be9565b34801561046a57600080fd5b50610430610c0b565b34801561047f57600080fd5b5061043061048e366004614c0e565b610c20565b34801561049f57600080fd5b506103ee6104ae366004614cce565b610c89565b3480156104bf57600080fd5b5061039b6104ce366004614bbe565b610cb5565b3480156104df57600080fd5b506104e8610ce2565b6040516001600160a01b0390911681526020016103a7565b34801561050c57600080fd5b506104307f3fb90a982568460bdf5505b984928e3c942db3525e60c25e39051cacec08b60f81565b34801561054057600080fd5b506103ee61054f366004614cce565b610d00565b34801561056057600080fd5b5061057461056f366004614bbe565b610dc9565b6040516103a79190614d09565b34801561058d57600080fd5b506103ee61059c366004614d23565b610def565b6103ee6105af366004614d40565b610e63565b3480156105c057600080fd5b50610430610e7e565b3480156105d557600080fd5b506103ee6105e4366004614e00565b610e9b565b3480156105f557600080fd5b50610609610604366004614e38565b610ffd565b6040805192835262ffffff9091166020830152016103a7565b34801561062e57600080fd5b506104e861115f565b34801561064357600080fd5b5061043061117a565b34801561065857600080fd5b506103ee610667366004614e83565b61118f565b34801561067857600080fd5b506103ee610687366004614ea0565b6111a3565b34801561069857600080fd5b506104307f22e9f4899cbd840357e113d5e255eb05266351f80fe8568f6c736829f9886f5a81565b3480156106cc57600080fd5b506104306106db366004614ec8565b6111b7565b3480156106ec57600080fd5b506107006106fb366004614e83565b6118d1565b60405160009190910b81526020016103a7565b34801561071f57600080fd5b5061043061072e366004614bbe565b611900565b34801561073f57600080fd5b506104e8611920565b34801561075457600080fd5b50610430610763366004614bbe565b611937565b34801561077457600080fd5b506103ee610783366004614ee5565b61195a565b34801561079457600080fd5b506104e8611971565b3480156107a957600080fd5b5061039b6107b8366004614cce565b611980565b3480156107c957600080fd5b506107d26119bb565b6040805165ffffffffffff9384168152929091166020830152016103a7565b3480156107fd57600080fd5b50610430600081565b34801561081257600080fd5b506103ee610821366004614b85565b611a40565b34801561083257600080fd5b50610846610841366004614f1b565b611b8b565b6040516103a79190614fdf565b34801561085f57600080fd5b50610884604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516103a79190615043565b34801561089d57600080fd5b506108b16108ac366004614b85565b611c74565b6040516103a79190615056565b3480156108ca57600080fd5b506103ee6108d9366004614e00565b611e06565b3480156108ea57600080fd5b506103ee6108f936600461509e565b611f72565b34801561090a57600080fd5b506104306109193660046150ce565b6120ed565b34801561092a57600080fd5b506103c2612119565b34801561093f57600080fd5b506103ee6121a9565b34801561095457600080fd5b5061095d6121e9565b604080516001600160a01b03909316835265ffffffffffff9091166020830152016103a7565b34801561098f57600080fd5b506103ee61099e366004614cce565b612217565b3480156109af57600080fd5b506103ee61223f565b3480156109c457600080fd5b5061039b612252565b3480156109d957600080fd5b506103ee6109e8366004614e83565b612271565b3480156109f957600080fd5b506103ee610a08366004614bbe565b6122d8565b348015610a1957600080fd5b506103ee610a2836600461511f565b6123ff565b348015610a3957600080fd5b50610430610a48366004614ec8565b612a3e565b348015610a5957600080fd5b506103ee610a68366004614e83565b612ae0565b348015610a7957600080fd5b506104306000805160206157fb83398151915281565b348015610a9b57600080fd5b506103ee610aaa36600461516d565b612b69565b348015610abb57600080fd5b506103ee610aca3660046151de565b612beb565b348015610adb57600080fd5b506103ee610aea366004615267565b612e70565b348015610afb57600080fd5b50610430610b0a366004614bbe565b600090815260008051602061579b833981519152602052604090205490565b60006001600160e01b031982166318a4c3c360e11b1480610b4e5750610b4e82612f7a565b92915050565b6000610b5f81612faf565b610b67612fb9565b50565b6000610b7581612faf565b6001600160a01b038416610b9c5760405163d92e233d60e01b815260040160405180910390fd5b610ba7848484612fc6565b50505050565b600080610bb86131a4565b6001600160a01b03948516600090815260069190910160209081526040808320959096168252939093525050205490565b600090815260008051602061581b833981519152602052604090206001015490565b600080610c166131a4565b6003015492915050565b80516020808301516040808501516060860151608087015160a088015160c089015160e08a01516101008b01516101208c01516101408d0151985160009c610c6c9c909b9a91016152c0565b604051602081830303815290604052805190602001209050919050565b81610ca757604051631fe1e13d60e11b815260040160405180910390fd5b610cb182826131c8565b5050565b600080610cc06131a4565b600093845260040160205250506040902060020154600160b81b900460ff1690565b600080610ced6131a4565b600101546001600160a01b031692915050565b6000805160206157db83398151915282158015610d355750610d20611920565b6001600160a01b0316826001600160a01b0316145b15610dba57600080610d456121e9565b90925090506001600160a01b038216151580610d67575065ffffffffffff8116155b80610d7a57504265ffffffffffff821610155b15610da7576040516319ca5ebb60e01b815265ffffffffffff821660048201526024015b60405180910390fd5b5050805465ffffffffffff60a01b191681555b610dc483836131e4565b505050565b600080610dd46131a4565b60009384526005016020525050604090206001015460ff1690565b6000610dfa81612faf565b6000610e046131a4565b600181018054851515600160a01b0260ff60a01b199091161790556040519091507feded67f5310120daa4cd7610cb05cee3ce8d5e6237b28455089b814371ef4c3c90610e5690851515815260200190565b60405180910390a1505050565b610e6b613217565b610e74826132bc565b610cb182826132c7565b6000610e88613384565b506000805160206157bb83398151915290565b6000805160206157fb833981519152610eb381612faf565b81600003610ed457604051637c946ed760e01b815260040160405180910390fd5b6000610edf856133cd565b9050610eea84612a3e565b8114610f095760405163a342e7d960e01b815260040160405180910390fd5b600085815260008051602061579b833981519152602081905260409091205480851115610f4957604051630625040160e01b815260040160405180910390fd5b610f53858261534a565b600088815260208490526040812091909155610f6e886133ed565b9050610f8a610f836060890160408a01614e83565b8288613420565b806001600160a01b0316887fb013294d91b96864e668e4bd96e04df167560e353af4268f952b16be9d40a78088604051610fc691815260200190565b60405180910390a3610ff33387610fe360608b0160408c01614e83565b6001600160a01b03169190613473565b5050505050505050565b600080600061100a6131a4565b6001600160a01b0380881660009081526008830160209081526040808320938916835292815290829020825160a081018452905460ff811615158083526001600160401b03610100830481169484019490945262ffffff600160481b8304811695840195909552600160601b82049093166060830152600160a01b90049092166080830152919250906111195750600080805260088201602090815260408083206001600160a01b0388168452825291829020825160a081018452905460ff8116151582526001600160401b03610100820481169383019390935262ffffff600160481b8204811694830194909452600160601b81049092166060820152600160a01b90910490911660808201525b851561113d5761112d8582606001516134d2565b8160800151935093505050611157565b61114b8582602001516134d2565b81604001519350935050505b935093915050565b60008061116a6131a4565b546001600160a01b031692915050565b6000806111856131a4565b6002015492915050565b600061119a81612faf565b610cb1826135a1565b60006111ae81612faf565b610cb182613614565b6000806111c26131a4565b6001810154909150600160a01b900460ff16156111f2576040516313d0ff5960e31b815260040160405180910390fd5b60006112016020850185614e83565b6001600160a01b0316036112285760405163d92e233d60e01b815260040160405180910390fd5b600061123a6080850160608601614d23565b611248578360c0013561124e565b8360a001355b90508060000361127157604051637c946ed760e01b815260040160405180910390fd5b60008461014001351180156112a05750600061129561014086016101208701614e83565b6001600160a01b0316145b156112be5760405163d92e233d60e01b815260040160405180910390fd5b60006112c86131a4565b90506112da6080860160608701614d23565b80611305575060016112f260a087016080880161535d565b600181111561130357611303614cf3565b145b156113f957600061131c6040870160208801614e83565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611359573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137d9190615378565b90506000600783018161139660408a0160208b01614e83565b6001600160a01b0316815260208101919091526040016000908120546113bd910b83615395565b6113c890600a61549a565b90506113d88160a08901356154bf565b156113f65760405163aa8828e760e01b815260040160405180910390fd5b50505b61142d7f22e9f4899cbd840357e113d5e255eb05266351f80fe8568f6c736829f9886f5a6107b86040880160208901614e83565b611466576114416040860160208701614e83565b604051635f8b555b60e11b81526001600160a01b039091166004820152602401610d9e565b600080805260088201602052604080822091906114899060608901908901614e83565b6001600160a01b0316815260208101919091526040016000205460ff166114ba576114416060860160408701614e83565b8060030154935060006114cc85613684565b90506001600160a01b0381166114f55760405163d92e233d60e01b815260040160405180910390fd5b61152b6115086040880160208901614e83565b6115186060890160408a01614e83565b61152560208a018a614e83565b8461371c565b6115368560016154d3565b60038301556115458587613978565b806001600160a01b0316857f0e8491ac313aa920e94e4571be1156423036e7e83268fbf0397fd05d88a466398860405161157f91906154e6565b60405180910390a36000806115ae8361159e60808b0160608c01614d23565b61060460608c0160408d01614e83565b915091506040518061010001604052806115d28a80360381019061048e9190614c0e565b81526020018381526020018262ffffff168152602001846001600160a01b0316815260200160001515815260200160008152602001600081526020016000815250846004016000898152602001908152602001600020600082015181600001556020820151816001015560408201518160020160006101000a81548162ffffff021916908362ffffff16021790555060608201518160020160036101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160020160176101000a81548160ff02191690831515021790555060a0820151816003015560c0820151816004015560e082015181600501559050506040518060400160405280868152602001600060028111156116f3576116f3614cf3565b905260008881526005860160209081526040909120825181559082015160018083018054909160ff199091169083600281111561173257611732614cf3565b0217905550505060028401805490600061174b836155cd565b9091555061176190506080890160608a01614d23565b1561180f5760a088013560068501600061178160408c0160208d01614e83565b6001600160a01b031681526020808201929092526040016000908120916117aa908c018c614e83565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546117d991906154d3565b9091555061180a9050333060a08b01356117f960408d0160208e01614e83565b6001600160a01b03169291906139d6565b6118c6565b600061182083838b60c00135613a0f565b905060006118328260c08c01356154d3565b90508060068701600061184b60608e0160408f01614e83565b6001600160a01b03168152602080820192909252604001600090812091611874908e018e614e83565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546118a391906154d3565b925050819055506118c33330838d60400160208101906117f99190614e83565b50505b505050505050919050565b6000806118dc6131a4565b6001600160a01b039093166000908152600790930160205250506040812054900b90565b60008061190b6131a4565b60009384526005016020525050604090205490565b6000806000805160206157db833981519152610ced565b6000806119426131a4565b60009384526004016020525050604090206003015490565b600061196581612faf565b610dc460008484612fc6565b600061197b611920565b905090565b600082815260008051602061581b833981519152602090815260408083206001600160a01b038516845290915281205460ff165b9392505050565b7feef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d869840154600090600160d01b900465ffffffffffff166000805160206157db8339815191528115801590611a1557504265ffffffffffff831610155b611a2157600080611a37565b6001810154600160a01b900465ffffffffffff16825b92509250509091565b6000611a4b81612faf565b6001600160a01b038316611a725760405163d92e233d60e01b815260040160405180910390fd5b6000611a7c6131a4565b6001600160a01b0385811660008181526008840160208181526040808420958a1680855295825280842080546001600160b81b0319169055838052918152818320858452815291819020815160a081018352905460ff8116151582526001600160401b036101008204811683860190815262ffffff600160481b84048116858701908152600160601b850484166060808801918252600160a01b9096048316608080890191825289519081018a529451861685529151831698840198909852965190921681860152945116908401529051949550937fd4b23f319fe513df34cddf75df188ebfb16db475655c7828421dc90c5c53244c91611b7c91615056565b60405180910390a35050505050565b6060816001600160401b03811115611ba557611ba5614a25565b604051908082528060200260200182016040528015611bd857816020015b6060815260200190600190039081611bc35790505b50905060005b82811015611c6d57611c4830858584818110611bfc57611bfc6155e6565b9050602002810190611c0e91906155fc565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613a3892505050565b828281518110611c5a57611c5a6155e6565b6020908102919091010152600101611bde565b5092915050565b604080516080810182526000808252602082018190529181018290526060810182905290611ca06131a4565b6001600160a01b0380861660009081526008830160209081526040808320938816835292815290829020825160a081018452905460ff811615158083526001600160401b03610100830481169484019490945262ffffff600160481b8304811695840195909552600160601b82049093166060830152600160a01b9004909216608083015291925090611daf5750600080805260088201602090815260408083206001600160a01b0387168452825291829020825160a081018452905460ff8116151582526001600160401b03610100820481169383019390935262ffffff600160481b8204811694830194909452600160601b81049092166060820152600160a01b90910490911660808201525b604051806080016040528082602001516001600160401b03168152602001826040015162ffffff16815260200182606001516001600160401b03168152602001826080015162ffffff168152509250505092915050565b6000805160206157fb833981519152611e1e81612faf565b81600003611e3f57604051637c946ed760e01b815260040160405180910390fd5b6000611e4a856133cd565b9050611e5584612a3e565b8114611e745760405163a342e7d960e01b815260040160405180910390fd5b6000611e7f86611900565b600087815260008051602061579b83398151915260208190526040909120549192509082611ead87836154d3565b1115611ecc57604051630625040160e01b815260040160405180910390fd5b611ed686826154d3565b600089815260208490526040812091909155611ef1896133ed565b9050611f0d611f0660608a0160408b01614e83565b8289613aae565b806001600160a01b0316897ff58c78c7658c89a31db2cce8dd547cbf5015572035f58f9aca5dc5a3568f3a2689604051611f4991815260200190565b60405180910390a3611f673330896117f960608d0160408e01614e83565b505050505050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b0316600081158015611fb75750825b90506000826001600160401b03166001148015611fd35750303b155b905081158015611fe1575080155b15611fff5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561202957845460ff60401b1916600160401b1785555b612034600089613af6565b61203c613b08565b6001600160a01b0387166120635760405163d92e233d60e01b815260040160405180910390fd5b600061206d6131a4565b80546001600160a01b03808b166001600160a01b031992831617835560019092018054928a1692909116919091179055508315610ff357845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15050505050505050565b60008060006120fd878787610ffd565b9150915061210c828286613a0f565b925050505b949350505050565b7feef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698401546000906000805160206157db83398151915290600160d01b900465ffffffffffff16801580159061217357504265ffffffffffff8216105b61218d578154600160d01b900465ffffffffffff166121a2565b6001820154600160a01b900465ffffffffffff165b9250505090565b60006121b36121e9565b509050336001600160a01b038216146121e157604051636116401160e11b8152336004820152602401610d9e565b610b67613b10565b6000805160206157db833981519152546001600160a01b03811691600160a01b90910465ffffffffffff1690565b8161223557604051631fe1e13d60e11b815260040160405180910390fd5b610cb18282613bad565b600061224a81612faf565b610b67613bc9565b60008061225d6131a4565b60010154600160a01b900460ff1692915050565b600061227c81612faf565b60006122866131a4565b6001810180546001600160a01b0319166001600160a01b038616908117909155604051919250907f10806d5d70e6f30969b0108ce176b903fca9b758b7341d271f69963323da313c90600090a2505050565b60006122e26131a4565b6000838152600482016020526040902060020154909150600160b81b900460ff16156123215760405163a9d0268d60e01b815260040160405180910390fd5b6000828152600482016020526040902060020154630100000090046001600160a01b0316806123635760405163d36d896560e01b815260040160405180910390fd5b600061236e84613684565b9050806001600160a01b0316826001600160a01b0316146123a2576040516371ced2cf60e11b815260040160405180910390fd5b6000848152600484016020526040808220600201805460ff60b81b1916600160b81b179055516001600160a01b0384169186917f4f45a3bbce2de4ee8d69d6bf7dd2455dc927f1d1a50725b7292e0bf5aa06d8ab9190a350505050565b6000805160206157fb83398151915261241781612faf565b8260000361243857604051637c946ed760e01b815260040160405180910390fd5b60006124426131a4565b60008781526004828101602090815260409283902083516101008101855281548152600182015492810192909252600281015462ffffff811694830194909452630100000084046001600160a01b031660608301819052600160b81b90940460ff1615156080830152600381015460a08301529182015460c082015260059091015460e08201529192506124e95760405163d36d896560e01b815260040160405180910390fd5b6124f286612a3e565b8151146125125760405163a342e7d960e01b815260040160405180910390fd5b600087815260058301602090815260408083208151808301909252805482526001810154919290919083019060ff16600281111561255257612552614cf3565b600281111561256357612563614cf3565b905250805190915086111561258b57604051630625040160e01b815260040160405180910390fd5b6000806125a08a8a8686600001518c8c613bd4565b9150915083606001516001600160a01b03168a7fbd6e615cc8b2df8e15d6dfae6fdaafad4fe24965addd99b870dda4aab1cf39328b60400160208101906125e79190614e83565b6125f760408e0160208f01614e83565b604080516001600160a01b03938416815292909116602083015281018c9052606081018b90526080810185905260a00160405180910390a360006101408a01351561269d578961014001358560e00151101561269d57600061265f60808c0160608d01614d23565b612669578861266b565b835b905060008660e001518c6101400135612684919061534a565b9050808211156126965780925061269a565b8192505b50505b6126c88b8560000151878d60600160208101906126ba9190614d23565b8e60c001358e8e8989613c43565b6126d860808b0160608c01614d23565b1561284457886006870160006126f460408e0160208f01614e83565b6001600160a01b0316815260208082019290925260400160009081209161271d908e018e614e83565b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461274c919061534a565b90915550612762905060408b0160208c01614e83565b6001600160a01b03166342966c688a6040518263ffffffff1660e01b815260040161278f91815260200190565b600060405180830381600087803b1580156127a957600080fd5b505af11580156127bd573d6000803e3d6000fd5b505050506127da33308a8d60400160208101906117f99190614e83565b8015612806576128066127f56101408c016101208d01614e83565b82610fe360608e0160408f01614e83565b6000612812828561534a565b9050801561283e5761283e61282a60208d018d614e83565b828d6040016020810190610fe39190614e83565b50612a0b565b61284e82846154d3565b60068701600061286460608e0160408f01614e83565b6001600160a01b0316815260208082019290925260400160009081209161288d908e018e614e83565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546128bc919061534a565b909155506128d790503384610fe360608e0160408f01614e83565b8015612969576128ed60408b0160208c01614e83565b6001600160a01b03166340c10f1961290860208d018d614e83565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b15801561295057600080fd5b505af1158015612964573d6000803e3d6000fd5b505050505b6000612975828a61534a565b90508015612a095761298d60408c0160208d01614e83565b6001600160a01b03166340c10f196129a860208e018e614e83565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b1580156129f057600080fd5b505af1158015612a04573d6000803e3d6000fd5b505050505b505b8115612a31578554612a31906001600160a01b031683610fe360608e0160408f01614e83565b5050505050505050505050565b6000612a4d6020830183614e83565b612a5d6040840160208501614e83565b612a6d6060850160408601614e83565b612a7d6080860160608701614d23565b612a8d60a087016080880161535d565b60a087013560c088013560e0890135612aae6101208b016101008c01615649565b612ac06101408c016101208d01614e83565b8b6101400135604051602001610c6c9b9a999897969594939291906152c0565b6000612aeb81612faf565b6001600160a01b038216612b125760405163d92e233d60e01b815260040160405180910390fd5b6000612b1c6131a4565b80546001600160a01b0319166001600160a01b0385169081178255604051919250907f3c864541ef71378c6229510ed90f376565ee42d9c5e0904a984a9e863e6db44f90600090a2505050565b60405163d505accf60e01b81526001600160a01b038781166004830152306024830152604482018790526064820186905260ff8516608483015260a4820184905260c4820183905288169063d505accf9060e401600060405180830381600087803b158015612bd757600080fd5b505af1158015612a31573d6000803e3d6000fd5b6000805160206157fb833981519152612c0381612faf565b6000612c0d6131a4565b60008781526004828101602090815260409283902083516101008101855281548152600182015492810192909252600281015462ffffff811694830194909452630100000084046001600160a01b031660608301819052600160b81b90940460ff1615156080830152600381015460a08301529182015460c082015260059091015460e0820152919250612cb45760405163d36d896560e01b815260040160405180910390fd5b612cbd86612a3e565b815114612cdd5760405163a342e7d960e01b815260040160405180910390fd5b60008781526005838101602090815260408084206001908101805460ff19166002908117909155600480890190945291852085815590810185905580820180546001600160c01b03191690556003810185905591820184905591018290558301805491612d4983615664565b919050555080606001516001600160a01b0316877ff2820c9274d611a15d979823ac23bb965c1972a808eebd952297d9bd3a60f4b88787604051612d8e92919061567b565b60405180910390a36000878152600583016020526040812054612db690899089908590613dd1565b90506000612dca6080890160608a01614d23565b612de357612dde6060890160408a01614e83565b612df3565b612df36040890160208a01614e83565b6001600160a01b03811660009081526006860160209081526040822092935084929190612e22908c018c614e83565b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254612e51919061534a565b90915550506060830151611f67906001600160a01b0383169084613473565b6000612e7b81612faf565b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ebb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612edf9190615378565b90508060000b8360000b1315612f085760405163aa8828e760e01b815260040160405180910390fd5b6000612f126131a4565b6001600160a01b03861660008181526007830160209081526040808320805460ff191660ff8b16179055519188900b825292935090917fe7239279c8eed71aa3c3725e6858242c0238bb4198777634effdf39c4fd2c89f910160405180910390a25050505050565b60006001600160e01b03198216637965db0b60e01b1480610b4e57506301ffc9a760e01b6001600160e01b0319831614610b4e565b610b678133613e2a565b612fc4600080613e63565b565b612fd38160200151613f50565b612fe08160600151613f50565b6000612fea6131a4565b90506040518060a0016040528060011515815260200183600001516001600160401b03168152602001836020015162ffffff16815260200183604001516001600160401b03168152602001836060015162ffffff16815250816008016000866001600160a01b03166001600160a01b031681526020019081526020016000206000856001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548160ff02191690831515021790555060208201518160000160016101000a8154816001600160401b0302191690836001600160401b0316021790555060408201518160000160096101000a81548162ffffff021916908362ffffff160217905550606082015181600001600c6101000a8154816001600160401b0302191690836001600160401b0316021790555060808201518160000160146101000a81548162ffffff021916908362ffffff160217905550905050826001600160a01b0316846001600160a01b03167fd4b23f319fe513df34cddf75df188ebfb16db475655c7828421dc90c5c53244c846040516131969190615056565b60405180910390a350505050565b7f8036d9ca2814a3bcd78d3e8aba96b71e7697006bd322a98e7f5f0f41b09a8b0090565b6131d182610be9565b6131da81612faf565b610ba78383613f78565b6001600160a01b038116331461320d5760405163334bd91960e11b815260040160405180910390fd5b610dc48282613fe7565b306001600160a01b037f000000000000000000000000ca1f1cb5ed09c33e6d618e476acaf1c22525d63616148061329e57507f000000000000000000000000ca1f1cb5ed09c33e6d618e476acaf1c22525d6366001600160a01b03166132926000805160206157bb833981519152546001600160a01b031690565b6001600160a01b031614155b15612fc45760405163703e46dd60e11b815260040160405180910390fd5b6000610cb181612faf565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015613321575060408051601f3d908101601f1916820190925261331e918101906156aa565b60015b61334957604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610d9e565b6000805160206157bb833981519152811461337a57604051632a87526960e21b815260048101829052602401610d9e565b610dc48383614040565b306001600160a01b037f000000000000000000000000ca1f1cb5ed09c33e6d618e476acaf1c22525d6361614612fc45760405163703e46dd60e11b815260040160405180910390fd5b6000806133d86131a4565b60009384526004016020525050604090205490565b6000806133f86131a4565b600093845260040160205250506040902060020154630100000090046001600160a01b031690565b600061342a6131a4565b6001600160a01b038086166000908152600683016020908152604080832093881683529290529081208054929350849290919061346890849061534a565b909155505050505050565b6040516001600160a01b03838116602483015260448201839052610dc491859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050614096565b600080836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613513573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135379190615378565b905060128160ff16111561355e57604051633c9c1e2d60e01b815260040160405180910390fd5b6001600160401b0383169150811580159061357c575060128160ff16105b15611c6d5761358c8160126156c3565b61359790600a61549a565b61211190836156dc565b60006135ab612119565b6135b4426140f9565b6135be91906156f0565b90506135ca8282614130565b60405165ffffffffffff821681526001600160a01b038316907f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed69060200160405180910390a25050565b600061361f826141bd565b613628426140f9565b61363291906156f0565b905061363e8282613e63565b6040805165ffffffffffff8085168252831660208201527ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b910160405180910390a15050565b60006136b07f3fb90a982568460bdf5505b984928e3c942db3525e60c25e39051cacec08b60f33611980565b156137155760405163133f730360e21b8152600481018390523390634cfdcc0c90602401602060405180830381865afa1580156136f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4e919061570f565b5033919050565b60006137266131a4565b600181015460405163010270a960e71b81526001600160a01b03888116600483015286811660248301529293509116908190638138548090604401602060405180830381865afa15801561377e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137a2919061572c565b156137c05760405163c95b482560e01b815260040160405180910390fd5b60405163010270a960e71b81526001600160a01b0387811660048301528481166024830152821690638138548090604401602060405180830381865afa15801561380e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613832919061572c565b156138505760405163c95b482560e01b815260040160405180910390fd5b60405163010270a960e71b81526001600160a01b0386811660048301528581166024830152821690638138548090604401602060405180830381865afa15801561389e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138c2919061572c565b156138e05760405163c95b482560e01b815260040160405180910390fd5b60405163010270a960e71b81526001600160a01b0386811660048301528481166024830152821690638138548090604401602060405180830381865afa15801561392e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613952919061572c565b156139705760405163c95b482560e01b815260040160405180910390fd5b505050505050565b6139886080820160608301614d23565b156139a657604051630c8a506160e21b815260040160405180910390fd5b6139b08282614205565b600091825260008051602061579b833981519152602052604090912060c0909101359055565b6040516001600160a01b038481166024830152838116604483015260648201839052610ba79186918216906323b872dd906084016134a0565b8262ffffff8316156119b457613a2e8262ffffff8516620f4240614255565b61211190826154d3565b6060600080846001600160a01b031684604051613a559190615749565b600060405180830381855af49150503d8060008114613a90576040519150601f19603f3d011682016040523d82523d6000602084013e613a95565b606091505b5091509150613aa5858383614329565b95945050505050565b6000613ab86131a4565b6001600160a01b03808616600090815260068301602090815260408083209388168352929052908120805492935084929091906134689084906154d3565b613afe614380565b610cb182826143c9565b612fc4614380565b6000805160206157db833981519152600080613b2a6121e9565b91509150613b3f8165ffffffffffff16151590565b1580613b5357504265ffffffffffff821610155b15613b7b576040516319ca5ebb60e01b815265ffffffffffff82166004820152602401610d9e565b613b8d6000613b88611920565b613fe7565b50613b99600083613f78565b505081546001600160d01b03191690915550565b613bb682610be9565b613bbf81612faf565b610ba78383613fe7565b612fc4600080614130565b600086815260008051602061579b83398151915260208190526040822054829190613bff818861534a565b861115613c1f57604051630625040160e01b815260040160405180910390fd5b60009350613c318a8a8a8a8a8a614432565b949b949a509398505050505050505050565b6000613c4d6131a4565b90506000613c5b868b61534a565b60008c81526005840160205260408120829055909150819003613d285760008b81526005838101602090815260408084206001908101805460ff1916821790556004808801909352908420848155908101849055600280820180546001600160c01b0319169055600382018590559181018490559091018290558301805491613ce383615664565b919050555088606001516001600160a01b03168b7fe5f48e2a4a303d196ad814389aa54cf34e7b1e404e740599d005907a2ca0cd6c60405160405180910390a3612a31565b6000848a60c00151613d3a91906154d3565b905088613d6a576000613d568b602001518c604001518b613a0f565b905080821115613d6857613d68615765565b505b858a60a00151613d7a91906154d3565b60008d8152600480860160205260409091206003810192909255018190558315613dc357838a60e00151613dae91906154d3565b60008d81526004850160205260409020600501555b505050505050505050505050565b600084815260008051602061579b83398151915260208190526040822054838114613e0f5760405163191e664760e11b815260040160405180910390fd5b60008781526020839052604081205561210c8787878761461c565b613e348282611980565b610cb15760405163e2517d3f60e01b81526001600160a01b038216600482015260248101839052604401610d9e565b7feef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698401546000805160206157db83398151915290600160d01b900465ffffffffffff168015613f12574265ffffffffffff82161015613ee857600182015482546001600160d01b0316600160a01b90910465ffffffffffff16600160d01b02178255613f12565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec590600090a15b5060010180546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b620f424062ffffff821610610b6757604051637e2df70960e11b815260040160405180910390fd5b60006000805160206157db83398151915283613fdd576000613f98611920565b6001600160a01b031614613fbf57604051631fe1e13d60e11b815260040160405180910390fd5b6001810180546001600160a01b0319166001600160a01b0385161790555b6121118484614691565b60006000805160206157db8339815191528315801561401e5750614009611920565b6001600160a01b0316836001600160a01b0316145b15614036576001810180546001600160a01b03191690555b6121118484614736565b614049826147b2565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a280511561408e57610dc48282613a38565b610cb1614817565b60006140ab6001600160a01b03841683614836565b905080516000141580156140d05750808060200190518101906140ce919061572c565b155b15610dc457604051635274afe760e01b81526001600160a01b0384166004820152602401610d9e565b600065ffffffffffff82111561412c576040516306dfcc6560e41b81526030600482015260248101839052604401610d9e565b5090565b6000805160206157db83398151915260006141496121e9565b835465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b03881617178455915061418990508165ffffffffffff16151590565b15610ba7576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510990600090a150505050565b6000806141c8612119565b90508065ffffffffffff168365ffffffffffff16116141f0576141eb838261577b565b6119b4565b6119b465ffffffffffff841662069780614844565b600161421760a083016080840161535d565b600181111561422857614228614cf3565b148015614237575060e0810135155b15610cb157604051630d7eec7360e21b815260040160405180910390fd5b600080806000198587098587029250828110838203039150508060000361428f57838281614285576142856154a9565b04925050506119b4565b8381106142c057604051630c740aef60e31b8152600481018790526024810186905260448101859052606401610d9e565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b606082614339576141eb8261485a565b815115801561435057506001600160a01b0384163b155b1561437957604051639996b31560e01b81526001600160a01b0385166004820152602401610d9e565b50806119b4565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16612fc457604051631afcd79f60e31b815260040160405180910390fd5b6143d1614380565b6000805160206157db8339815191526001600160a01b03821661440a57604051636116401160e11b815260006004820152602401610d9e565b80546001600160d01b0316600160d01b65ffffffffffff851602178155610ba7600083613f78565b6000806144456080880160608901614d23565b1561454757600161445c60a0890160808a0161535d565b600181111561446d5761446d614cf3565b1480156144865750614483848860e00135614883565b83105b156144a457604051637d18445b60e01b815260040160405180910390fd5b600086602001518760c0015110156144f45760008760c0015188602001516144cc919061534a565b9050808511156144ea579150816144e3818661534a565b91506144ee565b8492505b506144f7565b50825b60008111801561451057506000876040015162ffffff16115b156145355761452881886040015162ffffff16614883565b61453290836154d3565b91505b61453f828561534a565b925050614611565b600161455960a0890160808a0161535d565b600181111561456a5761456a614cf3565b14801561458c575061458984670de0b6b3a76400008960e00135614255565b83105b156145aa57604051630650e54560e41b815260040160405180910390fd5b839150600090508560c001516000036145c4575060208501515b60006145dd876020015188604001518a60c00135613a0f565b905060008760200151826145f1919061534a565b905061460281878b60c00135614255565b61460c90846154d3565b925050505b965096945050505050565b600061462e6080850160608601614d23565b1561463a575080612111565b6000614653846020015185604001518760c00135613a0f565b905061465f81846154d3565b915061466f8160c08701356154d3565b8210156146885760c0840151614685908361534a565b91505b50949350505050565b600060008051602061581b8339815191526146ac8484611980565b61472c576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556146e23390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a46001915050610b4e565b6000915050610b4e565b600060008051602061581b8339815191526147518484611980565b1561472c576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a46001915050610b4e565b806001600160a01b03163b6000036147e857604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610d9e565b6000805160206157bb83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b3415612fc45760405163b398979f60e01b815260040160405180910390fd5b60606119b483836000614939565b600081831061485357816119b4565b5090919050565b80511561486a5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60008080600019848609848602925082811083820303915050806000036148b75750670de0b6b3a764000090049050610b4e565b670de0b6b3a764000081106148e957604051635173648d60e01b81526004810186905260248101859052604401610d9e565b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60608147101561495e5760405163cd78605960e01b8152306004820152602401610d9e565b600080856001600160a01b0316848660405161497a9190615749565b60006040518083038185875af1925050503d80600081146149b7576040519150601f19603f3d011682016040523d82523d6000602084013e6149bc565b606091505b50915091506149cc868383614329565b9695505050505050565b6000602082840312156149e857600080fd5b81356001600160e01b0319811681146119b457600080fd5b6001600160a01b0381168114610b6757600080fd5b8035614a2081614a00565b919050565b634e487b7160e01b600052604160045260246000fd5b60405161016081016001600160401b0381118282101715614a5e57614a5e614a25565b60405290565b604051601f8201601f191681016001600160401b0381118282101715614a8c57614a8c614a25565b604052919050565b80356001600160401b0381168114614a2057600080fd5b803562ffffff81168114614a2057600080fd5b600060808284031215614ad057600080fd5b604051608081018181106001600160401b0382111715614af257614af2614a25565b604052905080614b0183614a94565b8152614b0f60208401614aab565b6020820152614b2060408401614a94565b6040820152614b3160608401614aab565b60608201525092915050565b600080600060c08486031215614b5257600080fd5b8335614b5d81614a00565b92506020840135614b6d81614a00565b9150614b7c8560408601614abe565b90509250925092565b60008060408385031215614b9857600080fd5b8235614ba381614a00565b91506020830135614bb381614a00565b809150509250929050565b600060208284031215614bd057600080fd5b5035919050565b8015158114610b6757600080fd5b8035614a2081614bd7565b803560028110614a2057600080fd5b803560048110614a2057600080fd5b60006101608284031215614c2157600080fd5b614c29614a3b565b614c3283614a15565b8152614c4060208401614a15565b6020820152614c5160408401614a15565b6040820152614c6260608401614be5565b6060820152614c7360808401614bf0565b608082015260a083013560a082015260c083013560c082015260e083013560e0820152610100614ca4818501614bff565b90820152610120614cb6848201614a15565b90820152610140928301359281019290925250919050565b60008060408385031215614ce157600080fd5b823591506020830135614bb381614a00565b634e487b7160e01b600052602160045260246000fd5b6020810160038310614d1d57614d1d614cf3565b91905290565b600060208284031215614d3557600080fd5b81356119b481614bd7565b60008060408385031215614d5357600080fd5b8235614d5e81614a00565b91506020838101356001600160401b0380821115614d7b57600080fd5b818601915086601f830112614d8f57600080fd5b813581811115614da157614da1614a25565b614db3601f8201601f19168501614a64565b91508082528784828501011115614dc957600080fd5b80848401858401376000848284010152508093505050509250929050565b60006101608284031215614dfa57600080fd5b50919050565b60008060006101a08486031215614e1657600080fd5b83359250614e278560208601614de7565b915061018084013590509250925092565b600080600060608486031215614e4d57600080fd5b8335614e5881614a00565b92506020840135614e6881614bd7565b91506040840135614e7881614a00565b809150509250925092565b600060208284031215614e9557600080fd5b81356119b481614a00565b600060208284031215614eb257600080fd5b813565ffffffffffff811681146119b457600080fd5b60006101608284031215614edb57600080fd5b6119b48383614de7565b60008060a08385031215614ef857600080fd5b8235614f0381614a00565b9150614f128460208501614abe565b90509250929050565b60008060208385031215614f2e57600080fd5b82356001600160401b0380821115614f4557600080fd5b818501915085601f830112614f5957600080fd5b813581811115614f6857600080fd5b8660208260051b8501011115614f7d57600080fd5b60209290920196919550909350505050565b60005b83811015614faa578181015183820152602001614f92565b50506000910152565b60008151808452614fcb816020860160208601614f8f565b601f01601f19169290920160200192915050565b600060208083016020845280855180835260408601915060408160051b87010192506020870160005b8281101561503657603f19888603018452615024858351614fb3565b94509285019290850190600101615008565b5092979650505050505050565b6020815260006119b46020830184614fb3565b60006080820190506001600160401b03808451168352602084015162ffffff808216602086015282604087015116604086015280606087015116606086015250505092915050565b6000806000606084860312156150b357600080fd5b83356150be81614a00565b92506020840135614e6881614a00565b600080600080608085870312156150e457600080fd5b84356150ef81614a00565b935060208501356150ff81614bd7565b9250604085013561510f81614a00565b9396929550929360600135925050565b6000806000806101c0858703121561513657600080fd5b843593506151478660208701614de7565b9396939550505050610180820135916101a0013590565b60ff81168114610b6757600080fd5b600080600080600080600060e0888a03121561518857600080fd5b873561519381614a00565b965060208801356151a381614a00565b9550604088013594506060880135935060808801356151c18161515e565b9699959850939692959460a0840135945060c09093013592915050565b6000806000806101a085870312156151f557600080fd5b843593506152068660208701614de7565b92506101808501356001600160401b038082111561522357600080fd5b818701915087601f83011261523757600080fd5b81358181111561524657600080fd5b88602082850101111561525857600080fd5b95989497505060200194505050565b6000806040838503121561527a57600080fd5b823561528581614a00565b91506020830135600081900b8114614bb357600080fd5b600281106152ac576152ac614cf3565b9052565b600481106152ac576152ac614cf3565b6001600160a01b038c811682528b811660208301528a8116604083015289151560608301526101608201906152f8608084018b61529c565b8860a08401528760c08401528660e08401526153186101008401876152b0565b9390931661012082015261014001529998505050505050505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610b4e57610b4e615334565b60006020828403121561536f57600080fd5b6119b482614bf0565b60006020828403121561538a57600080fd5b81516119b48161515e565b600082810b9082900b03607f198112607f82131715610b4e57610b4e615334565b600181815b808511156153f15781600019048211156153d7576153d7615334565b808516156153e457918102915b93841c93908002906153bb565b509250929050565b60008261540857506001610b4e565b8161541557506000610b4e565b816001811461542b576002811461543557615451565b6001915050610b4e565b60ff84111561544657615446615334565b50506001821b610b4e565b5060208310610133831016604e8410600b8410161715615474575081810a610b4e565b61547e83836153b6565b806000190482111561549257615492615334565b029392505050565b60006119b460ff8416836153f9565b634e487b7160e01b600052601260045260246000fd5b6000826154ce576154ce6154a9565b500690565b80820180821115610b4e57610b4e615334565b6101608101615505826154f885614a15565b6001600160a01b03169052565b61551160208401614a15565b6001600160a01b0316602083015261552b60408401614a15565b6001600160a01b0316604083015261554560608401614be5565b1515606083015261555860808401614bf0565b615565608084018261529c565b5060a083013560a083015260c083013560c083015260e083013560e0830152610100615592818501614bff565b61559e828501826152b0565b50506101206155ae818501614a15565b6001600160a01b03811684830152505061014092830135919092015290565b6000600182016155df576155df615334565b5060010190565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261561357600080fd5b8301803591506001600160401b0382111561562d57600080fd5b60200191503681900382131561564257600080fd5b9250929050565b60006020828403121561565b57600080fd5b6119b482614bff565b60008161567357615673615334565b506000190190565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b6000602082840312156156bc57600080fd5b5051919050565b60ff8281168282160390811115610b4e57610b4e615334565b6000826156eb576156eb6154a9565b500490565b65ffffffffffff818116838216019080821115611c6d57611c6d615334565b60006020828403121561572157600080fd5b81516119b481614a00565b60006020828403121561573e57600080fd5b81516119b481614bd7565b6000825161575b818460208701614f8f565b9190910192915050565b634e487b7160e01b600052600160045260246000fd5b65ffffffffffff828116828216039080821115611c6d57611c6d61533456fe9ef2e27f0661cd1c5e17cad73e47154b2655f2434621cc5680ed2d93095efa00360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbceef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d869840097667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b92902dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800a2646970667358221220dd9e6caa8e0b6e61eee1a9608842e59f9d074f42ac02fcec37946ae7d45dbfb364736f6c63430008160033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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