HYPE Price: $25.10 (+13.37%)
 

Overview

HYPE Balance

HyperEVM LogoHyperEVM LogoHyperEVM Logo0 HYPE

HYPE Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
DiamondInitializer

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 1000 runs

Other Settings:
cancun EvmVersion
File 1 of 31 : DiamondInitializer.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import "./DiamondInitializerTypes.sol";

/// @dev This contract is used only once to initialize the diamond proxy.
contract DiamondInitializer {
  function initialize(
    IAccessManager _accessManager,
    address _tokenP,
    CollateralSetup[] memory _collaterals,
    RedemptionSetup memory _redemptionSetup
  )
    external
  {
    LibSetters.setAccessManager(_accessManager);

    ParallelizerStorage storage ts = s.transmuterStorage();
    ts.statusReentrant = NOT_ENTERED;
    ts.normalizer = uint128(BASE_27);
    ts.tokenP = ITokenP(_tokenP);

    // Setup each collateral
    uint256 collateralsLength = _collaterals.length;
    for (uint256 i; i < collateralsLength; i++) {
      CollateralSetup memory collateral = _collaterals[i];
      LibSetters.addCollateral(collateral.token);
      LibSetters.setOracle(collateral.token, collateral.oracleConfig);
      // Mint fees
      LibSetters.setFees(collateral.token, collateral.xMintFee, collateral.yMintFee, true);
      // Burn fees
      LibSetters.setFees(collateral.token, collateral.xBurnFee, collateral.yBurnFee, false);
      LibSetters.togglePause(collateral.token, ActionType.Mint);
      LibSetters.togglePause(collateral.token, ActionType.Burn);
      LibSetters.setStablecoinCap(collateral.token, 100_000_000 ether);
      if (collateral.targetMax) LibOracle.updateOracle(collateral.token);
    }

    // setRedemptionCurveParams
    if (_redemptionSetup.xRedeemFee.length > 0) {
      LibSetters.togglePause(address(0), ActionType.Redeem);
      LibSetters.setRedemptionCurveParams(_redemptionSetup.xRedeemFee, _redemptionSetup.yRedeemFee);
    }
  }
}

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IStETH
/// @notice Interface for the `StETH` contract
interface IStETH {
  function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);

  function submit(address) external payable returns (uint256);

  function getSharesByPooledEth(uint256 _ethAmount) external view returns (uint256);
}

File 3 of 31 : IMorphoOracle.sol
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IMorphoOracle
/// @notice Interface for the oracle contracts used within Morpho
interface IMorphoOracle {
  function price() external view returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IRETH
/// @notice Interface for the `rETH` contract
interface IRETH {
  function getExchangeRate() external view returns (uint256);
}

File 5 of 31 : Storage.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import { ITokenP } from "contracts/interfaces/ITokenP.sol";

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                        ENUMS                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

enum FacetCutAction {
  Add,
  Replace,
  Remove
}

enum ManagerType {
  EXTERNAL
}

enum ActionType {
  Mint,
  Burn,
  Redeem
}

enum TrustedType {
  Updater,
  Seller
}

enum QuoteType {
  MintExactInput,
  MintExactOutput,
  BurnExactInput,
  BurnExactOutput
}

enum OracleReadType {
  CHAINLINK_FEEDS,
  EXTERNAL,
  NO_ORACLE,
  STABLE,
  WSTETH,
  CBETH,
  RETH,
  SFRXETH,
  MAX,
  MORPHO_ORACLE
}

enum OracleQuoteType {
  UNIT,
  TARGET
}

enum WhitelistType {
  BACKED
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                    STRUCTS                                                     
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

struct Permit2Details {
  address to; // Address that will receive the funds
  uint256 nonce; // Nonce of the transaction
  bytes signature; // Permit signature of the user
}

struct FacetCut {
  address facetAddress; // Facet contract address
  FacetCutAction action; // Can be add, remove or replace
  bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}

struct Facet {
  address facetAddress; // Facet contract address
  bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}

struct FacetInfo {
  address facetAddress; // Facet contract address
  uint16 selectorPosition; // Position in the list of all selectors
}

struct DiamondStorage {
  bytes4[] selectors; // List of all available selectors
  mapping(bytes4 => FacetInfo) selectorInfo; // Selector to (address, position in list)
  IAccessManager accessManager; // Contract handling access management
}

struct ImplementationStorage {
  address implementation; // Dummy implementation address for Etherscan usability
}

struct ManagerStorage {
  IERC20[] subCollaterals; // Subtokens handled by the manager or strategies
  bytes config; // Additional configuration data
}

struct Collateral {
  uint8 isManaged; // If the collateral is managed through external strategies
  uint8 isMintLive; // If minting from this asset is unpaused
  uint8 isBurnLive; // If burning to this asset is unpaused
  uint8 decimals; // IERC20Metadata(collateral).decimals()
  uint8 onlyWhitelisted; // If only whitelisted addresses can burn or redeem for this token
  uint216 normalizedStables; // Normalized amount of stablecoins issued from this collateral
  uint64[] xFeeMint; // Increasing exposures in [0,BASE_9[
  int64[] yFeeMint; // Mint fees at the exposures specified in `xFeeMint`
  uint64[] xFeeBurn; // Decreasing exposures in ]0,BASE_9]
  int64[] yFeeBurn; // Burn fees at the exposures specified in `xFeeBurn`
  bytes oracleConfig; // Data about the oracle used for the collateral
  bytes whitelistData; // For whitelisted collateral, data used to verify whitelists
  ManagerStorage managerData; // For managed collateral, data used to handle the strategies
  uint256 stablecoinCap; // Cap on the amount of stablecoins that can be issued from this collateral
}

struct ParallelizerStorage {
  ITokenP tokenP; // tokenP handled by the system
  uint8 isRedemptionLive; // If redemption is unpaused
  uint8 statusReentrant; // If call is reentrant or not
  bool consumingSchedule; // If the contract is consuming a scheduled operation
  uint128 normalizedStables; // Normalized amount of stablecoins issued by the system
  uint128 normalizer; // To reconcile `normalizedStables` values with the actual amount
  address[] collateralList; // List of collateral assets supported by the system
  uint64[] xRedemptionCurve; // Increasing collateral ratios > 0
  int64[] yRedemptionCurve; // Value of the redemption fees at `xRedemptionCurve`
  mapping(address => Collateral) collaterals; // Maps a collateral asset to its parameters
  mapping(address => uint256) isTrusted; // If an address is trusted to update the normalizer value
  mapping(address => uint256) isSellerTrusted; // If an address is trusted to sell accruing reward tokens or to run
    // keeper jobs on oracles
  mapping(WhitelistType => mapping(address => uint256)) isWhitelistedForType;
}
// Whether an address is whitelisted for a specific whitelist type

File 6 of 31 : DiamondInitializerTypes.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

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

import { LibDiamondEtherscan } from "../libraries/LibDiamondEtherscan.sol";
import { LibOracle } from "../libraries/LibOracle.sol";
import { LibSetters } from "../libraries/LibSetters.sol";
import { LibStorage as s } from "../libraries/LibStorage.sol";

import "../../utils/Constants.sol";
import "../Storage.sol";

struct CollateralSetup {
  address token;
  bool targetMax;
  bytes oracleConfig;
  uint64[] xMintFee;
  int64[] yMintFee;
  uint64[] xBurnFee;
  int64[] yBurnFee;
}

struct RedemptionSetup {
  uint64[] xRedeemFee;
  int64[] yRedeemFee;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { LibStorage as s } from "./LibStorage.sol";
import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import { AuthorityUtils } from "@openzeppelin/contracts/access/manager/AuthorityUtils.sol";

import "../../utils/Errors.sol";
import "../../utils/Constants.sol";
import "../Storage.sol";

/// @title LibDiamond
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @notice Helper library to deal with diamond proxies.
/// @dev Reference: EIP-2535 Diamonds
/// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/libraries/LibDiamond.sol by mudgen
library LibDiamond {
  event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    INTERNAL FUNCTIONS                                                
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  function isGovernor(address caller) internal view returns (bool) {
    (bool isMember,) = s.diamondStorage().accessManager.hasRole(GOVERNOR_ROLE, caller);
    return isMember;
  }

  /// @notice Checks whether `caller` can call `data` on `this`
  function checkCanCall(address caller, bytes calldata data) internal returns (bool) {
    IAccessManager accessManager = s.diamondStorage().accessManager;
    (bool immediate, uint32 delay) =
      AuthorityUtils.canCallWithDelay(address(accessManager), caller, address(this), bytes4(data[0:4]));
    if (!immediate) {
      if (delay > 0) {
        ParallelizerStorage storage ts = s.transmuterStorage();
        ts.consumingSchedule = true;
        accessManager.consumeScheduledOp(caller, data);
        ts.consumingSchedule = false;
      } else {
        return false;
      }
    }
    return true;
  }

  /// @notice Internal function version of `diamondCut`
  function diamondCut(FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) internal {
    uint256 diamondCutLength = _diamondCut.length;
    for (uint256 facetIndex; facetIndex < diamondCutLength; facetIndex++) {
      bytes4[] memory functionSelectors = _diamondCut[facetIndex].functionSelectors;
      address facetAddress = _diamondCut[facetIndex].facetAddress;

      if (functionSelectors.length == 0) {
        revert NoSelectorsProvidedForFacetForCut(facetAddress);
      }

      FacetCutAction action = _diamondCut[facetIndex].action;
      if (action == FacetCutAction.Add) {
        _addFunctions(facetAddress, functionSelectors);
      } else if (action == FacetCutAction.Replace) {
        _replaceFunctions(facetAddress, functionSelectors);
      } else if (action == FacetCutAction.Remove) {
        _removeFunctions(facetAddress, functionSelectors);
      }
    }

    emit DiamondCut(_diamondCut, _init, _calldata);
    _initializeDiamondCut(_init, _calldata);
  }

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    PRIVATE FUNCTIONS                                                
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Does a delegate call on `_init` with `_calldata`
  function _initializeDiamondCut(address _init, bytes memory _calldata) private {
    if (_init == address(0)) {
      return;
    }
    _enforceHasContractCode(_init);
    (bool success, bytes memory error) = _init.delegatecall(_calldata);
    if (!success) {
      if (error.length > 0) {
        assembly ("memory-safe") {
          let returndata_size := mload(error)
          revert(add(32, error), returndata_size)
        }
      } else {
        revert InitializationFunctionReverted(_init, _calldata);
      }
    }
  }

  /// @notice Adds a new function to the diamond proxy
  /// @dev Reverts if selectors are already existing
  function _addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
    if (_facetAddress == address(0)) {
      revert CannotAddSelectorsToZeroAddress(_functionSelectors);
    }
    DiamondStorage storage ds = s.diamondStorage();
    uint16 selectorCount = uint16(ds.selectors.length);
    _enforceHasContractCode(_facetAddress);
    uint256 functionSelectorsLength = _functionSelectors.length;
    for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
      bytes4 selector = _functionSelectors[selectorIndex];
      address oldFacetAddress = ds.selectorInfo[selector].facetAddress;
      if (oldFacetAddress != address(0)) {
        revert CannotAddFunctionToDiamondThatAlreadyExists(selector);
      }
      ds.selectorInfo[selector] = FacetInfo(_facetAddress, selectorCount);
      ds.selectors.push(selector);
      selectorCount++;
    }
  }

  /// @notice Upgrades a function in the diamond proxy
  /// @dev Reverts if selectors do not already exist
  function _replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
    DiamondStorage storage ds = s.diamondStorage();
    if (_facetAddress == address(0)) {
      revert CannotReplaceFunctionsFromFacetWithZeroAddress(_functionSelectors);
    }
    _enforceHasContractCode(_facetAddress);
    uint256 functionSelectorsLength = _functionSelectors.length;
    for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
      bytes4 selector = _functionSelectors[selectorIndex];
      address oldFacetAddress = ds.selectorInfo[selector].facetAddress;
      // Can't replace immutable functions -- functions defined directly in the diamond in this case
      if (oldFacetAddress == address(this)) {
        revert CannotReplaceImmutableFunction(selector);
      }
      if (oldFacetAddress == _facetAddress) {
        revert CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(selector);
      }
      if (oldFacetAddress == address(0)) {
        revert CannotReplaceFunctionThatDoesNotExists(selector);
      }
      // Replace old facet address
      ds.selectorInfo[selector].facetAddress = _facetAddress;
    }
  }

  /// @notice Removes a function in the diamond proxy
  /// @dev Reverts if selectors do not already exist
  function _removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
    DiamondStorage storage ds = s.diamondStorage();
    uint256 selectorCount = ds.selectors.length;
    if (_facetAddress != address(0)) {
      revert RemoveFacetAddressMustBeZeroAddress(_facetAddress);
    }
    uint256 functionSelectorsLength = _functionSelectors.length;
    for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
      bytes4 selector = _functionSelectors[selectorIndex];
      FacetInfo memory oldFacetAddressAndSelectorPosition = ds.selectorInfo[selector];
      if (oldFacetAddressAndSelectorPosition.facetAddress == address(0)) {
        revert CannotRemoveFunctionThatDoesNotExist(selector);
      }

      // Can't remove immutable functions -- functions defined directly in the diamond
      if (oldFacetAddressAndSelectorPosition.facetAddress == address(this)) {
        revert CannotRemoveImmutableFunction(selector);
      }
      // Replace selector with last selector
      selectorCount--;
      if (oldFacetAddressAndSelectorPosition.selectorPosition != selectorCount) {
        bytes4 lastSelector = ds.selectors[selectorCount];
        ds.selectors[oldFacetAddressAndSelectorPosition.selectorPosition] = lastSelector;
        ds.selectorInfo[lastSelector].selectorPosition = oldFacetAddressAndSelectorPosition.selectorPosition;
      }
      // Delete last selector
      ds.selectors.pop();
      delete ds.selectorInfo[selector];
    }
  }

  /// @notice Checks that an address has a non void bytecode
  function _enforceHasContractCode(address _contract) private view {
    uint256 contractSize;
    assembly ("memory-safe") {
      contractSize := extcodesize(_contract)
    }
    if (contractSize == 0) {
      revert ContractHasNoCode();
    }
  }
}

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

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

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title ICbETH
/// @notice Interface for the `cbETH` contract
interface ICbETH {
  function exchangeRate() external view returns (uint256);
}

File 10 of 31 : ISfrxETH.sol
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title ISfrxETH
/// @notice Interface for the `sfrxETH` contract
interface ISfrxETH {
  function pricePerShare() external view returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IKeyringGuard
/// @notice Interface for the `KeyringGuard` contract
interface IKeyringGuard {
  function isAuthorized(address from, address to) external returns (bool passed);
}

File 12 of 31 : AuthorityUtils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/AuthorityUtils.sol)

pragma solidity ^0.8.20;

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

library AuthorityUtils {
    /**
     * @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility
     * for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.
     * This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.
     */
    function canCallWithDelay(
        address authority,
        address caller,
        address target,
        bytes4 selector
    ) internal view returns (bool immediate, uint32 delay) {
        (bool success, bytes memory data) = authority.staticcall(
            abi.encodeCall(IAuthority.canCall, (caller, target, selector))
        );
        if (success) {
            if (data.length >= 0x40) {
                (immediate, delay) = abi.decode(data, (bool, uint32));
            } else if (data.length >= 0x20) {
                immediate = abi.decode(data, (bool));
            }
        }
        return (immediate, delay);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/manager/IAccessManager.sol)

pragma solidity ^0.8.20;

import {Time} from "../../utils/types/Time.sol";

interface IAccessManager {
    /**
     * @dev A delayed operation was scheduled.
     */
    event OperationScheduled(
        bytes32 indexed operationId,
        uint32 indexed nonce,
        uint48 schedule,
        address caller,
        address target,
        bytes data
    );

    /**
     * @dev A scheduled operation was executed.
     */
    event OperationExecuted(bytes32 indexed operationId, uint32 indexed nonce);

    /**
     * @dev A scheduled operation was canceled.
     */
    event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);

    /**
     * @dev Informational labelling for a roleId.
     */
    event RoleLabel(uint64 indexed roleId, string label);

    /**
     * @dev Emitted when `account` is granted `roleId`.
     *
     * NOTE: The meaning of the `since` argument depends on the `newMember` argument.
     * If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,
     * otherwise it indicates the execution delay for this account and roleId is updated.
     */
    event RoleGranted(uint64 indexed roleId, address indexed account, uint32 delay, uint48 since, bool newMember);

    /**
     * @dev Emitted when `account` membership or `roleId` is revoked. Unlike granting, revoking is instantaneous.
     */
    event RoleRevoked(uint64 indexed roleId, address indexed account);

    /**
     * @dev Role acting as admin over a given `roleId` is updated.
     */
    event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);

    /**
     * @dev Role acting as guardian over a given `roleId` is updated.
     */
    event RoleGuardianChanged(uint64 indexed roleId, uint64 indexed guardian);

    /**
     * @dev Grant delay for a given `roleId` will be updated to `delay` when `since` is reached.
     */
    event RoleGrantDelayChanged(uint64 indexed roleId, uint32 delay, uint48 since);

    /**
     * @dev Target mode is updated (true = closed, false = open).
     */
    event TargetClosed(address indexed target, bool closed);

    /**
     * @dev Role required to invoke `selector` on `target` is updated to `roleId`.
     */
    event TargetFunctionRoleUpdated(address indexed target, bytes4 selector, uint64 indexed roleId);

    /**
     * @dev Admin delay for a given `target` will be updated to `delay` when `since` is reached.
     */
    event TargetAdminDelayUpdated(address indexed target, uint32 delay, uint48 since);

    error AccessManagerAlreadyScheduled(bytes32 operationId);
    error AccessManagerNotScheduled(bytes32 operationId);
    error AccessManagerNotReady(bytes32 operationId);
    error AccessManagerExpired(bytes32 operationId);
    error AccessManagerLockedRole(uint64 roleId);
    error AccessManagerBadConfirmation();
    error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);
    error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);
    error AccessManagerUnauthorizedConsume(address target);
    error AccessManagerUnauthorizedCancel(address msgsender, address caller, address target, bytes4 selector);
    error AccessManagerInvalidInitialAdmin(address initialAdmin);

    /**
     * @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
     * no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
     * & {execute} workflow.
     *
     * This function is usually called by the targeted contract to control immediate execution of restricted functions.
     * Therefore we only return true if the call can be performed without any delay. If the call is subject to a
     * previously set delay (not zero), then the function should return false and the caller should schedule the operation
     * for future execution.
     *
     * If `immediate` is true, the delay can be disregarded and the operation can be immediately executed, otherwise
     * the operation can be executed if and only if delay is greater than 0.
     *
     * NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
     * is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail
     * to identify the indirect workflow, and will consider calls that require a delay to be forbidden.
     *
     * NOTE: This function does not report the permissions of the admin functions in the manager itself. These are defined by the
     * {AccessManager} documentation.
     */
    function canCall(
        address caller,
        address target,
        bytes4 selector
    ) external view returns (bool allowed, uint32 delay);

    /**
     * @dev Expiration delay for scheduled proposals. Defaults to 1 week.
     *
     * IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,
     * disabling any scheduling usage.
     */
    function expiration() external view returns (uint32);

    /**
     * @dev Minimum setback for all delay updates, with the exception of execution delays. It
     * can be increased without setback (and reset via {revokeRole} in the case event of an
     * accidental increase). Defaults to 5 days.
     */
    function minSetback() external view returns (uint32);

    /**
     * @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.
     *
     * NOTE: When the manager itself is closed, admin functions are still accessible to avoid locking the contract.
     */
    function isTargetClosed(address target) external view returns (bool);

    /**
     * @dev Get the role required to call a function.
     */
    function getTargetFunctionRole(address target, bytes4 selector) external view returns (uint64);

    /**
     * @dev Get the admin delay for a target contract. Changes to contract configuration are subject to this delay.
     */
    function getTargetAdminDelay(address target) external view returns (uint32);

    /**
     * @dev Get the id of the role that acts as an admin for the given role.
     *
     * The admin permission is required to grant the role, revoke the role and update the execution delay to execute
     * an operation that is restricted to this role.
     */
    function getRoleAdmin(uint64 roleId) external view returns (uint64);

    /**
     * @dev Get the role that acts as a guardian for a given role.
     *
     * The guardian permission allows canceling operations that have been scheduled under the role.
     */
    function getRoleGuardian(uint64 roleId) external view returns (uint64);

    /**
     * @dev Get the role current grant delay.
     *
     * Its value may change at any point without an event emitted following a call to {setGrantDelay}.
     * Changes to this value, including effect timepoint are notified in advance by the {RoleGrantDelayChanged} event.
     */
    function getRoleGrantDelay(uint64 roleId) external view returns (uint32);

    /**
     * @dev Get the access details for a given account for a given role. These details include the timepoint at which
     * membership becomes active, and the delay applied to all operation by this user that requires this permission
     * level.
     *
     * Returns:
     * [0] Timestamp at which the account membership becomes valid. 0 means role is not granted.
     * [1] Current execution delay for the account.
     * [2] Pending execution delay for the account.
     * [3] Timestamp at which the pending execution delay will become active. 0 means no delay update is scheduled.
     */
    function getAccess(
        uint64 roleId,
        address account
    ) external view returns (uint48 since, uint32 currentDelay, uint32 pendingDelay, uint48 effect);

    /**
     * @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
     * permission might be associated with an execution delay. {getAccess} can provide more details.
     */
    function hasRole(uint64 roleId, address account) external view returns (bool isMember, uint32 executionDelay);

    /**
     * @dev Give a label to a role, for improved role discoverability by UIs.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {RoleLabel} event.
     */
    function labelRole(uint64 roleId, string calldata label) external;

    /**
     * @dev Add `account` to `roleId`, or change its execution delay.
     *
     * This gives the account the authorization to call any function that is restricted to this role. An optional
     * execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
     * that is restricted to members of this role. The user will only be able to execute the operation after the delay has
     * passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
     *
     * If the account has already been granted this role, the execution delay will be updated. This update is not
     * immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
     * called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
     * operation executed in the 3 hours that follows this update was indeed scheduled before this update.
     *
     * Requirements:
     *
     * - the caller must be an admin for the role (see {getRoleAdmin})
     * - granted role must not be the `PUBLIC_ROLE`
     *
     * Emits a {RoleGranted} event.
     */
    function grantRole(uint64 roleId, address account, uint32 executionDelay) external;

    /**
     * @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
     * no effect.
     *
     * Requirements:
     *
     * - the caller must be an admin for the role (see {getRoleAdmin})
     * - revoked role must not be the `PUBLIC_ROLE`
     *
     * Emits a {RoleRevoked} event if the account had the role.
     */
    function revokeRole(uint64 roleId, address account) external;

    /**
     * @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
     * the role this call has no effect.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * Emits a {RoleRevoked} event if the account had the role.
     */
    function renounceRole(uint64 roleId, address callerConfirmation) external;

    /**
     * @dev Change admin role for a given role.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {RoleAdminChanged} event
     */
    function setRoleAdmin(uint64 roleId, uint64 admin) external;

    /**
     * @dev Change guardian role for a given role.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {RoleGuardianChanged} event
     */
    function setRoleGuardian(uint64 roleId, uint64 guardian) external;

    /**
     * @dev Update the delay for granting a `roleId`.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {RoleGrantDelayChanged} event.
     */
    function setGrantDelay(uint64 roleId, uint32 newDelay) external;

    /**
     * @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {TargetFunctionRoleUpdated} event per selector.
     */
    function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;

    /**
     * @dev Set the delay for changing the configuration of a given target contract.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {TargetAdminDelayUpdated} event.
     */
    function setTargetAdminDelay(address target, uint32 newDelay) external;

    /**
     * @dev Set the closed flag for a contract.
     *
     * Closing the manager itself won't disable access to admin methods to avoid locking the contract.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     *
     * Emits a {TargetClosed} event.
     */
    function setTargetClosed(address target, bool closed) external;

    /**
     * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
     * operation is not yet scheduled, has expired, was executed, or was canceled.
     */
    function getSchedule(bytes32 id) external view returns (uint48);

    /**
     * @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
     * been scheduled.
     */
    function getNonce(bytes32 id) external view returns (uint32);

    /**
     * @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
     * choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
     * required for the caller. The special value zero will automatically set the earliest possible time.
     *
     * Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
     * the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
     * scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
     *
     * Emits a {OperationScheduled} event.
     *
     * NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
     * this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
     * contract if it is using standard Solidity ABI encoding.
     */
    function schedule(
        address target,
        bytes calldata data,
        uint48 when
    ) external returns (bytes32 operationId, uint32 nonce);

    /**
     * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
     * execution delay is 0.
     *
     * Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
     * operation wasn't previously scheduled (if the caller doesn't have an execution delay).
     *
     * Emits an {OperationExecuted} event only if the call was scheduled and delayed.
     */
    function execute(address target, bytes calldata data) external payable returns (uint32);

    /**
     * @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
     * operation that is cancelled.
     *
     * Requirements:
     *
     * - the caller must be the proposer, a guardian of the targeted function, or a global admin
     *
     * Emits a {OperationCanceled} event.
     */
    function cancel(address caller, address target, bytes calldata data) external returns (uint32);

    /**
     * @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
     * (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
     *
     * This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,
     * with all the verifications that it implies.
     *
     * Emit a {OperationExecuted} event.
     */
    function consumeScheduledOp(address caller, bytes calldata data) external;

    /**
     * @dev Hashing function for delayed operations.
     */
    function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);

    /**
     * @dev Changes the authority of a target managed by this manager instance.
     *
     * Requirements:
     *
     * - the caller must be a global admin
     */
    function updateAuthority(address target, address newAuthority) external;
}

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

pragma solidity ^0.8.20;

/**
 * @dev Standard interface for permissioning originally defined in Dappsys.
 */
interface IAuthority {
    /**
     * @dev Returns true if the caller can invoke on a target the function identified by a function selector.
     */
    function canCall(address caller, address target, bytes4 selector) external view returns (bool allowed);
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

pragma solidity ^0.8.20;

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

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
            if (denominator <= prod1) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

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

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

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

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

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

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

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

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

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

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        uint256 mLen = m.length;

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        uint256 exp;
        unchecked {
            exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
            value >>= exp;
            result += exp;

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

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

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

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

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

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

            result += SafeCast.toUint(value > 1);
        }
        return result;
    }

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

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

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

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

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

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

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

            result += SafeCast.toUint(value > (1 << 8) - 1);
        }
        return result;
    }

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

import {Math} from "../math/Math.sol";
import {SafeCast} from "../math/SafeCast.sol";

/**
 * @dev This library provides helpers for manipulating time-related objects.
 *
 * It uses the following types:
 * - `uint48` for timepoints
 * - `uint32` for durations
 *
 * While the library doesn't provide specific types for timepoints and duration, it does provide:
 * - a `Delay` type to represent duration that can be programmed to change value automatically at a given point
 * - additional helper functions
 */
library Time {
    using Time for *;

    /**
     * @dev Get the block timestamp as a Timepoint.
     */
    function timestamp() internal view returns (uint48) {
        return SafeCast.toUint48(block.timestamp);
    }

    /**
     * @dev Get the block number as a Timepoint.
     */
    function blockNumber() internal view returns (uint48) {
        return SafeCast.toUint48(block.number);
    }

    // ==================================================== Delay =====================================================
    /**
     * @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the
     * future. The "effect" timepoint describes when the transitions happens from the "old" value to the "new" value.
     * This allows updating the delay applied to some operation while keeping some guarantees.
     *
     * In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for
     * some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set
     * the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should
     * still apply for some time.
     *
     *
     * The `Delay` type is 112 bits long, and packs the following:
     *
     * ```
     *   | [uint48]: effect date (timepoint)
     *   |           | [uint32]: value before (duration)
     *   ↓           ↓       ↓ [uint32]: value after (duration)
     * 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
     * ```
     *
     * NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently
     * supported.
     */
    type Delay is uint112;

    /**
     * @dev Wrap a duration into a Delay to add the one-step "update in the future" feature
     */
    function toDelay(uint32 duration) internal pure returns (Delay) {
        return Delay.wrap(duration);
    }

    /**
     * @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
     * change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
     */
    function _getFullAt(
        Delay self,
        uint48 timepoint
    ) private pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
        (valueBefore, valueAfter, effect) = self.unpack();
        return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
    }

    /**
     * @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the
     * effect timepoint is 0, then the pending value should not be considered.
     */
    function getFull(Delay self) internal view returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
        return _getFullAt(self, timestamp());
    }

    /**
     * @dev Get the current value.
     */
    function get(Delay self) internal view returns (uint32) {
        (uint32 delay, , ) = self.getFull();
        return delay;
    }

    /**
     * @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to
     * enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the
     * new delay becomes effective.
     */
    function withUpdate(
        Delay self,
        uint32 newValue,
        uint32 minSetback
    ) internal view returns (Delay updatedDelay, uint48 effect) {
        uint32 value = self.get();
        uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));
        effect = timestamp() + setback;
        return (pack(value, newValue, effect), effect);
    }

    /**
     * @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).
     */
    function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
        uint112 raw = Delay.unwrap(self);

        valueAfter = uint32(raw);
        valueBefore = uint32(raw >> 32);
        effect = uint48(raw >> 64);

        return (valueBefore, valueAfter, effect);
    }

    /**
     * @dev pack the components into a Delay object.
     */
    function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {
        return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));
    }
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

/// @title IManager
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This interface is an authorized fork of Angle's `IManager` interface
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IManager.sol
interface IManager {
  /// @notice Returns the amount of collateral managed by the Manager
  /// @return balances Balances of all the subCollaterals handled by the manager
  /// @dev MUST NOT revert
  function totalAssets() external view returns (uint256[] memory balances, uint256 totalValue);

  /// @notice Hook to invest `amount` of `collateral`
  /// @dev MUST revert if the manager cannot accept these funds
  /// @dev MUST have received the funds beforehand
  function invest(uint256 amount) external;

  /// @notice Sends `amount` of `collateral` to the `to` address
  /// @dev Called when `tokenP` are burnt and during redemptions
  //  @dev MUST revert if there are not funds enough available
  /// @dev MUST be callable only by the parallelizer
  function release(address asset, address to, uint256 amount) external;

  /// @notice Gives the maximum amount of collateral immediately available for a transfer
  /// @dev Useful for integrators using `quoteIn` and `quoteOut`
  function maxAvailable() external view returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

/// @title IParallelizerOracle
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This interface is an authorized fork of Angle's `IParallelizerOracle` interface
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IParallelizerOracle.sol
interface IParallelizerOracle {
  /// @notice Reads the oracle value for asset to use in a redemption to compute the collateral ratio
  function readRedemption() external view returns (uint256);

  /// @notice Reads the oracle value for asset to use in a mint. It should be comprehensive of the
  /// deviation from the target price
  function readMint() external view returns (uint256);

  /// @notice Reads the oracle value for asset to use in a burn transaction as well as the ratio
  /// between the current price and the target price for the asset
  function readBurn() external view returns (uint256 oracleValue, uint256 ratio);

  /// @notice Reads the oracle value for asset
  function read() external view returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

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

/// @title ITokenP
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @notice Interface for the stablecoins `tokenP` contracts
/// @dev This interface is an authorized fork of Angle's `IAgToken` interface
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IAgToken.sol
interface ITokenP is IERC20 {
  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    MINTER ROLE ONLY FUNCTIONS                                            
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Lets a whitelisted contract mint tokenPs
  /// @param account Address to mint to
  /// @param amount Amount to mint
  function mint(address account, uint256 amount) external;

  /// @notice Burns `amount` tokens from a `burner` address after being asked to by `sender`
  /// @param amount Amount of tokens to burn
  /// @param burner Address to burn from
  /// @param sender Address which requested the burn from `burner`
  /// @dev This method is to be called by a contract with the minter right after being requested
  /// to do so by a `sender` address willing to burn tokens from another `burner` address
  /// @dev The method checks the allowance between the `sender` and the `burner`
  function burnFrom(uint256 amount, address burner, address sender) external;

  /// @notice Burns `amount` tokens from a `burner` address
  /// @param amount Amount of tokens to burn
  /// @param burner Address to burn from
  /// @dev This method is to be called by a contract with a minter right on the tokenP after being
  /// requested to do so by an address willing to burn tokens from its address
  function burnSelf(uint256 amount, address burner) external;

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    EXTERNAL FUNCTIONS                                                
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Amount of decimals of the stablecoin
  function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { LibStorage as s } from "./LibStorage.sol";

/// @title LibDiamondEtherscan
/// @notice Allow to verify a diamond proxy on Etherscan
/// @dev Forked from https://github.com/zdenham/diamond-etherscan/blob/main/contracts/libraries/LibDiamondEtherscan.sol
library LibDiamondEtherscan {
  event Upgraded(address indexed implementation);

  /// @notice Internal version of `setDummyImplementation`
  function setDummyImplementation(address implementationAddress) internal {
    s.implementationStorage().implementation = implementationAddress;
    emit Upgraded(implementationAddress);
  }

  /// @notice Internal version of `implementation`
  function dummyImplementation() internal view returns (address) {
    return s.implementationStorage().implementation;
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import { IManager } from "contracts/interfaces/IManager.sol";

import "../Storage.sol";

/// @title LibManager
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev Managed collateral assets may be handled through external smart contracts or directly through this library
/// @dev There is no implementation at this point for a managed collateral handled through this library, and
/// a new specific `ManagerType` would need to be added in this case
/// @dev This library is an authorized fork of Angle's `LibManager` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibManager.sol
library LibManager {
  /// @notice Checks to which address managed funds must be transferred
  function transferRecipient(bytes memory config) internal view returns (address recipient) {
    (ManagerType managerType, bytes memory data) = parseManagerConfig(config);
    recipient = address(this);
    if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (address));
  }

  /// @notice Performs a transfer of `token` for a collateral that is managed to a `to` address
  /// @dev `token` may not be the actual collateral itself, as some collaterals have subcollaterals associated
  /// with it
  /// @dev Eventually pulls funds from strategies
  function release(address token, address to, uint256 amount, bytes memory config) internal {
    (ManagerType managerType, bytes memory data) = parseManagerConfig(config);
    if (managerType == ManagerType.EXTERNAL) abi.decode(data, (IManager)).release(token, to, amount);
  }

  /// @notice Gets the balances of all the tokens controlled through `managerData`
  /// @return balances An array of size `subCollaterals` with current balances of all subCollaterals
  /// including the one corresponding to the `managerData` given
  /// @return totalValue The value of all the `subCollaterals` in `collateral`
  /// @dev `subCollaterals` must always have as first token (index 0) the collateral itself
  function totalAssets(bytes memory config) internal view returns (uint256[] memory balances, uint256 totalValue) {
    (ManagerType managerType, bytes memory data) = parseManagerConfig(config);
    if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (IManager)).totalAssets();
  }

  /// @notice Calls a hook if needed after new funds have been transfered to a manager
  function invest(uint256 amount, bytes memory config) internal {
    (ManagerType managerType, bytes memory data) = parseManagerConfig(config);
    if (managerType == ManagerType.EXTERNAL) abi.decode(data, (IManager)).invest(amount);
  }

  /// @notice Returns available underlying tokens, for instance if liquidity is fully used and
  /// not withdrawable the function will return 0
  function maxAvailable(bytes memory config) internal view returns (uint256 available) {
    (ManagerType managerType, bytes memory data) = parseManagerConfig(config);
    if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (IManager)).maxAvailable();
  }

  /// @notice Decodes the `managerData` associated to a collateral
  function parseManagerConfig(bytes memory config) internal pure returns (ManagerType managerType, bytes memory data) {
    (managerType, data) = abi.decode(config, (ManagerType, bytes));
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import { IParallelizerOracle } from "contracts/interfaces/IParallelizerOracle.sol";
import { AggregatorV3Interface } from "contracts/interfaces/external/chainlink/AggregatorV3Interface.sol";
import { IMorphoOracle } from "contracts/interfaces/external/morpho/IMorphoOracle.sol";

import { LibStorage as s } from "./LibStorage.sol";

import "../../utils/Constants.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";

/// @title LibOracle
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibOracle` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibOracle.sol
library LibOracle {
  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ACTIONS SPECIFIC ORACLES                                             
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Reads the oracle value used during a redemption to compute collateral ratio for `oracleConfig`
  /// @dev This value is only sensitive to compute the collateral ratio and deduce a penalty factor
  function readRedemption(bytes memory oracleConfig) internal view returns (uint256 oracleValue) {
    (OracleReadType oracleType, OracleReadType targetType, bytes memory oracleData, bytes memory targetData,) =
      _parseOracleConfig(oracleConfig);
    if (oracleType == OracleReadType.EXTERNAL) {
      IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
      return externalOracle.readRedemption();
    } else {
      (oracleValue,) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, 0);
      return oracleValue;
    }
  }

  /// @notice Reads the oracle value used during mint operations for an asset with `oracleConfig`
  /// @dev For assets which do not rely on external oracles, this value is the minimum between the processed oracle
  /// value for the asset and its target price
  function readMint(bytes memory oracleConfig) internal view returns (uint256 oracleValue) {
    (
      OracleReadType oracleType,
      OracleReadType targetType,
      bytes memory oracleData,
      bytes memory targetData,
      bytes memory hyperparameters
    ) = _parseOracleConfig(oracleConfig);
    if (oracleType == OracleReadType.EXTERNAL) {
      IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
      return externalOracle.readMint();
    }

    (uint128 userDeviation,) = abi.decode(hyperparameters, (uint128, uint128));
    uint256 targetPrice;
    (oracleValue, targetPrice) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, userDeviation);
    if (targetPrice < oracleValue) oracleValue = targetPrice;
  }

  /// @notice Reads the oracle value used for a burn operation for an asset with `oracleConfig`
  /// @return oracleValue The actual oracle value obtained
  /// @return ratio If `oracle value < target price`, the ratio between the oracle value and the target
  /// price, otherwise `BASE_18`
  function readBurn(bytes memory oracleConfig) internal view returns (uint256 oracleValue, uint256 ratio) {
    (
      OracleReadType oracleType,
      OracleReadType targetType,
      bytes memory oracleData,
      bytes memory targetData,
      bytes memory hyperparameters
    ) = _parseOracleConfig(oracleConfig);
    if (oracleType == OracleReadType.EXTERNAL) {
      IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
      return externalOracle.readBurn();
    }
    (uint128 userDeviation, uint128 burnRatioDeviation) = abi.decode(hyperparameters, (uint128, uint128));
    uint256 targetPrice;
    (oracleValue, targetPrice) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, userDeviation);
    // Firewall in case the oracle value reported is low compared to the target
    // If the oracle value is slightly below its target, then no deviation is reported for the oracle and
    // the price of burning the stablecoin for other assets is not impacted. Also, the oracle value of this asset
    // is set to the target price, to not be open to direct arbitrage
    ratio = BASE_18;
    if (oracleValue * BASE_18 < targetPrice * (BASE_18 - burnRatioDeviation)) {
      ratio = (oracleValue * BASE_18) / targetPrice;
    } else if (oracleValue < targetPrice) {
      oracleValue = targetPrice;
    }
  }

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VIEW FUNCTIONS                                                  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Internal version of the `getOracle` function
  function getOracle(address collateral)
    internal
    view
    returns (OracleReadType, OracleReadType, bytes memory, bytes memory, bytes memory)
  {
    return _parseOracleConfig(s.transmuterStorage().collaterals[collateral].oracleConfig);
  }

  /// @notice Gets the oracle value and the ratio with respect to the target price when it comes to
  /// burning for `collateral`
  function getBurnOracle(
    address collateral,
    bytes memory oracleConfig
  )
    internal
    view
    returns (uint256 minRatio, uint256 oracleValue)
  {
    ParallelizerStorage storage ts = s.transmuterStorage();
    minRatio = BASE_18;
    address[] memory collateralList = ts.collateralList;
    uint256 length = collateralList.length;
    for (uint256 i; i < length; ++i) {
      uint256 ratioObserved = BASE_18;
      if (collateralList[i] != collateral) {
        (, ratioObserved) = readBurn(ts.collaterals[collateralList[i]].oracleConfig);
      } else {
        (oracleValue, ratioObserved) = readBurn(oracleConfig);
      }
      if (ratioObserved < minRatio) minRatio = ratioObserved;
    }
  }

  /// @notice Computes the `quoteAmount` (for Chainlink oracles) depending on a `quoteType` and a base value
  /// (e.g the target price of the asset)
  /// @dev For cases where the Chainlink feed directly looks into the value of the asset, `quoteAmount` is `BASE_18`.
  /// For others, like wstETH for which Chainlink only has an oracle for stETH, `quoteAmount` is the target price
  function quoteAmount(OracleQuoteType quoteType, uint256 baseValue) internal pure returns (uint256) {
    if (quoteType == OracleQuoteType.UNIT) return BASE_18;
    else return baseValue;
  }

  function readSpotAndTarget(
    OracleReadType oracleType,
    OracleReadType targetType,
    bytes memory oracleData,
    bytes memory targetData,
    uint256 deviation
  )
    internal
    view
    returns (uint256 oracleValue, uint256 targetPrice)
  {
    targetPrice = read(targetType, BASE_18, targetData);
    oracleValue = read(oracleType, targetPrice, oracleData);
    // System may tolerate small deviations from target
    // If the oracle value reported is reasonably close to the target
    // --> disregard the oracle value and return the target price
    if (
      targetPrice * (BASE_18 - deviation) < oracleValue * BASE_18
        && oracleValue * BASE_18 < targetPrice * (BASE_18 + deviation)
    ) oracleValue = targetPrice;
  }

  /// @notice Reads an oracle value (or a target oracle value) for an asset based on its data parsed `oracleConfig`
  function read(OracleReadType readType, uint256 baseValue, bytes memory data) internal view returns (uint256) {
    if (readType == OracleReadType.CHAINLINK_FEEDS) {
      (
        AggregatorV3Interface[] memory circuitChainlink,
        uint32[] memory stalePeriods,
        uint8[] memory circuitChainIsMultiplied,
        uint8[] memory chainlinkDecimals,
        OracleQuoteType quoteType
      ) = abi.decode(data, (AggregatorV3Interface[], uint32[], uint8[], uint8[], OracleQuoteType));
      uint256 quotePrice = quoteAmount(quoteType, baseValue);
      uint256 listLength = circuitChainlink.length;
      for (uint256 i; i < listLength; ++i) {
        quotePrice = readChainlinkFeed(
          quotePrice, circuitChainlink[i], circuitChainIsMultiplied[i], chainlinkDecimals[i], stalePeriods[i]
        );
      }
      return quotePrice;
    } else if (readType == OracleReadType.STABLE) {
      return BASE_18;
    } else if (readType == OracleReadType.NO_ORACLE) {
      return baseValue;
    } else if (readType == OracleReadType.WSTETH) {
      return STETH.getPooledEthByShares(1 ether);
    } else if (readType == OracleReadType.CBETH) {
      return CBETH.exchangeRate();
    } else if (readType == OracleReadType.RETH) {
      return RETH.getExchangeRate();
    } else if (readType == OracleReadType.SFRXETH) {
      return SFRXETH.pricePerShare();
    } else if (readType == OracleReadType.MAX) {
      uint256 maxValue = abi.decode(data, (uint256));
      return maxValue;
    } else if (readType == OracleReadType.MORPHO_ORACLE) {
      (address contractAddress, uint256 normalizationFactor) = abi.decode(data, (address, uint256));
      return IMorphoOracle(contractAddress).price() / normalizationFactor;
    }
    // If the `OracleReadType` is `EXTERNAL`, it means that this function is called to compute a
    // `targetPrice` in which case the `baseValue` is returned here
    else {
      return baseValue;
    }
  }

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    SPECIFIC HELPERS                                                 
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Reads a Chainlink feed using a quote amount and converts the quote amount to the out-currency
  /// @param _quoteAmount The amount for which to compute the price expressed in `BASE_18`
  /// @param feed Chainlink feed to query
  /// @param multiplied Whether the ratio outputted by Chainlink should be multiplied or divided to the `quoteAmount`
  /// @param decimals Number of decimals of the corresponding Chainlink pair
  /// @return The `quoteAmount` converted in out-currency
  function readChainlinkFeed(
    uint256 _quoteAmount,
    AggregatorV3Interface feed,
    uint8 multiplied,
    uint256 decimals,
    uint32 stalePeriod
  )
    internal
    view
    returns (uint256)
  {
    (, int256 ratio,, uint256 updatedAt,) = feed.latestRoundData();
    if (ratio <= 0 || block.timestamp - updatedAt > stalePeriod) revert InvalidChainlinkRate();
    // Checking whether we should multiply or divide by the ratio computed
    if (multiplied == 1) return (_quoteAmount * uint256(ratio)) / (10 ** decimals);
    else return (_quoteAmount * (10 ** decimals)) / uint256(ratio);
  }

  /// @notice Parses an `oracleConfig` into several sub fields
  function _parseOracleConfig(bytes memory oracleConfig)
    private
    pure
    returns (OracleReadType, OracleReadType, bytes memory, bytes memory, bytes memory)
  {
    return abi.decode(oracleConfig, (OracleReadType, OracleReadType, bytes, bytes, bytes));
  }

  function updateOracle(address collateral) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    if (ts.collaterals[collateral].decimals == 0) revert NotCollateral();

    (
      OracleReadType oracleType,
      OracleReadType targetType,
      bytes memory oracleData,
      bytes memory targetData,
      bytes memory hyperparameters
    ) = _parseOracleConfig(ts.collaterals[collateral].oracleConfig);

    if (targetType != OracleReadType.MAX) revert OracleUpdateFailed();
    uint256 oracleValue = read(oracleType, BASE_18, oracleData);

    uint256 maxValue = abi.decode(targetData, (uint256));
    if (oracleValue > maxValue) {
      ts.collaterals[collateral].oracleConfig = abi.encode(
        oracleType,
        targetType,
        oracleData,
        // There are no checks whether the value increased or not
        abi.encode(oracleValue),
        hyperparameters
      );
    } else {
      revert OracleUpdateFailed();
    }
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import { LibManager } from "./LibManager.sol";
import { LibOracle } from "./LibOracle.sol";
import { LibStorage as s } from "./LibStorage.sol";
import { LibDiamond } from "./LibDiamond.sol";
import { LibWhitelist } from "./LibWhitelist.sol";

import "../../utils/Constants.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";

/// @title LibSetters
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibSetters` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibSetters.sol
library LibSetters {
  using SafeCast for uint256;

  event CollateralAdded(address indexed collateral);
  event CollateralManagerSet(address indexed collateral, ManagerStorage managerData);
  event CollateralRevoked(address indexed collateral);
  event CollateralWhitelistStatusUpdated(address indexed collateral, bytes whitelistData, uint8 whitelistStatus);
  event FeesSet(address indexed collateral, uint64[] xFee, int64[] yFee, bool mint);
  event OracleSet(address indexed collateral, bytes oracleConfig);
  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  event PauseToggled(address indexed collateral, uint256 pausedType, bool isPaused);
  event RedemptionCurveParamsSet(uint64[] xFee, int64[] yFee);
  event ReservesAdjusted(address indexed collateral, uint256 amount, bool increase);
  event StablecoinCapSet(address indexed collateral, uint256 stablecoinCap);
  event TrustedToggled(address indexed sender, bool isTrusted, TrustedType trustedType);
  event WhitelistStatusToggled(WhitelistType whitelistType, address indexed who, uint256 whitelistStatus);

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ONLY GOVERNOR ACTIONS                                              
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Internal version of `setAccessManager`
  function setAccessManager(IAccessManager _newAccessManager) internal {
    if (address(_newAccessManager).code.length == 0) revert InvalidAccessManager();
    DiamondStorage storage ds = s.diamondStorage();
    address previousAccessManager = address(ds.accessManager);
    ds.accessManager = _newAccessManager;
    emit OwnershipTransferred(previousAccessManager, address(_newAccessManager));
  }

  /// @notice Internal version of `setCollateralManager`
  function setCollateralManager(
    address collateral,
    bool checkExternalManagerBalance,
    ManagerStorage memory managerData
  )
    internal
  {
    Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    uint8 isManaged = collatInfo.isManaged;
    if (isManaged > 0 && checkExternalManagerBalance) {
      (, uint256 totalValue) = LibManager.totalAssets(collatInfo.managerData.config);
      if (totalValue > 0) revert ManagerHasAssets();
    }
    if (managerData.config.length != 0) {
      // The first subCollateral given should be the actual collateral asset
      if (address(managerData.subCollaterals[0]) != collateral) revert InvalidParams();
      // Sanity check on the manager data that is passed
      LibManager.parseManagerConfig(managerData.config);
      collatInfo.isManaged = 1;
    } else {
      collatInfo.isManaged = 0;
    }
    collatInfo.managerData = managerData;
    emit CollateralManagerSet(collateral, managerData);
  }

  /// @notice Internal version of `toggleTrusted`
  function toggleTrusted(address sender, TrustedType t) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    uint256 trustedStatus;
    if (t == TrustedType.Updater) {
      trustedStatus = 1 - ts.isTrusted[sender];
      ts.isTrusted[sender] = trustedStatus;
    } else {
      trustedStatus = 1 - ts.isSellerTrusted[sender];
      ts.isSellerTrusted[sender] = trustedStatus;
    }
    emit TrustedToggled(sender, trustedStatus == 1, t);
  }

  /// @notice Internal version of `addCollateral`
  function addCollateral(address collateral) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    Collateral storage collatInfo = ts.collaterals[collateral];
    if (collatInfo.decimals != 0) revert AlreadyAdded();
    collatInfo.decimals = uint8(IERC20Metadata(collateral).decimals());
    ts.collateralList.push(collateral);
    emit CollateralAdded(collateral);
  }

  /// @notice Internal version of `adjustStablecoins`
  function adjustStablecoins(address collateral, uint128 amount, bool increase) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    Collateral storage collatInfo = ts.collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    uint128 normalizedAmount = ((amount * BASE_27) / ts.normalizer).toUint128();
    if (increase) {
      collatInfo.normalizedStables = collatInfo.normalizedStables + uint216(normalizedAmount);
      ts.normalizedStables = ts.normalizedStables + normalizedAmount;
    } else {
      collatInfo.normalizedStables = collatInfo.normalizedStables - uint216(normalizedAmount);
      ts.normalizedStables = ts.normalizedStables - normalizedAmount;
    }
    emit ReservesAdjusted(collateral, amount, increase);
  }

  /// @notice Internal version of `revokeCollateral`
  function revokeCollateral(address collateral, bool checkExternalManagerBalance) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    Collateral storage collatInfo = ts.collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    if (collatInfo.normalizedStables > 0) revert CollateralBacked();
    uint8 isManaged = collatInfo.isManaged;
    if (isManaged > 0 && checkExternalManagerBalance) {
      (, uint256 totalValue) = LibManager.totalAssets(collatInfo.managerData.config);
      if (totalValue > 0) revert ManagerHasAssets();
    }
    delete ts.collaterals[collateral];
    address[] memory collateralListMem = ts.collateralList;
    uint256 length = collateralListMem.length;
    for (uint256 i; i < length - 1; ++i) {
      if (collateralListMem[i] == collateral) {
        ts.collateralList[i] = collateralListMem[length - 1];
        break;
      }
    }
    ts.collateralList.pop();
    emit CollateralRevoked(collateral);
  }

  /// @notice Internal version of `setOracle`
  function setOracle(address collateral, bytes memory oracleConfig) internal {
    Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    // Checks oracle validity
    LibOracle.readMint(oracleConfig);
    collatInfo.oracleConfig = oracleConfig;
    emit OracleSet(collateral, oracleConfig);
  }

  /// @notice Internal version of `setWhitelistStatus`
  function setWhitelistStatus(address collateral, uint8 whitelistStatus, bytes memory whitelistData) internal {
    Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    if (whitelistStatus == 1) {
      // Sanity check
      LibWhitelist.checkWhitelist(whitelistData, address(this));
      collatInfo.whitelistData = whitelistData;
    } else {
      // If whitelist is revoked, clear the whitelist data
      collatInfo.whitelistData = "";
    }
    collatInfo.onlyWhitelisted = whitelistStatus;
    emit CollateralWhitelistStatusUpdated(collateral, collatInfo.whitelistData, whitelistStatus);
  }

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ONLY GUARDIAN ACTIONS                                              
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Internal version of `togglePause`
  function togglePause(address collateral, ActionType action) internal {
    uint8 isLive;
    if (action == ActionType.Mint || action == ActionType.Burn) {
      Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
      if (collatInfo.decimals == 0) revert NotCollateral();
      if (action == ActionType.Mint) {
        isLive = 1 - collatInfo.isMintLive;
        collatInfo.isMintLive = isLive;
      } else {
        isLive = 1 - collatInfo.isBurnLive;
        collatInfo.isBurnLive = isLive;
      }
    } else {
      ParallelizerStorage storage ts = s.transmuterStorage();
      isLive = 1 - ts.isRedemptionLive;
      ts.isRedemptionLive = isLive;
    }
    emit PauseToggled(collateral, uint256(action), isLive == 0);
  }

  /// @notice Internal version of `setFees`
  function setFees(address collateral, uint64[] memory xFee, int64[] memory yFee, bool mint) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    Collateral storage collatInfo = ts.collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    checkFees(xFee, yFee, mint ? ActionType.Mint : ActionType.Burn);
    if (mint) {
      collatInfo.xFeeMint = xFee;
      collatInfo.yFeeMint = yFee;
    } else {
      collatInfo.xFeeBurn = xFee;
      collatInfo.yFeeBurn = yFee;
    }
    emit FeesSet(collateral, xFee, yFee, mint);
  }

  /// @notice Internal version of `setRedemptionCurveParams`
  function setRedemptionCurveParams(uint64[] memory xFee, int64[] memory yFee) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    LibSetters.checkFees(xFee, yFee, ActionType.Redeem);
    ts.xRedemptionCurve = xFee;
    ts.yRedemptionCurve = yFee;
    emit RedemptionCurveParamsSet(xFee, yFee);
  }

  /// @notice Internal version of `toggleWhitelist`
  function toggleWhitelist(WhitelistType whitelistType, address who) internal {
    ParallelizerStorage storage ts = s.transmuterStorage();
    uint256 whitelistStatus = 1 - ts.isWhitelistedForType[whitelistType][who];
    ts.isWhitelistedForType[whitelistType][who] = whitelistStatus;
    emit WhitelistStatusToggled(whitelistType, who, whitelistStatus);
  }

  /// @notice Sets the stablecoin cap that can be issued from a collateral
  function setStablecoinCap(address collateral, uint256 stablecoinCap) internal {
    Collateral storage collatInfo = s.transmuterStorage().collaterals[collateral];
    if (collatInfo.decimals == 0) revert NotCollateral();
    collatInfo.stablecoinCap = stablecoinCap;
    emit StablecoinCapSet(collateral, stablecoinCap);
  }

  /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    HELPERS                                                     
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

  /// @notice Checks the fee values given for the `mint`, `burn`, and `redeem` functions
  function checkFees(uint64[] memory xFee, int64[] memory yFee, ActionType action) internal view {
    uint256 n = xFee.length;
    if (n != yFee.length || n == 0) revert InvalidParams();
    if (
      // Mint inflexion points should be in [0,BASE_9[
      // We have: amountPostFee * (BASE_9 + yFeeMint) = amountPreFee * BASE_9
      // Hence we consider BASE_12 as the max value (100% fees) for yFeeMint
      // Burn inflexion points should be in [0,BASE_9] but fees should be constant in
      // the first segment [BASE_9, x_{n-1}[
      // Redemption inflexion points should be in [0,BASE_9]
      (action == ActionType.Mint && (xFee[n - 1] >= BASE_9 || xFee[0] != 0 || yFee[n - 1] > int256(BASE_12)))
        || (
          action == ActionType.Burn
            && (xFee[0] != BASE_9 || yFee[n - 1] > int256(BASE_9) || (n > 1 && (yFee[0] != yFee[1])))
        ) || (action == ActionType.Redeem && (xFee[n - 1] > BASE_9 || yFee[n - 1] < 0 || yFee[n - 1] > int256(BASE_9)))
    ) {
      revert InvalidParams();
    }

    for (uint256 i; i < n - 1; ++i) {
      if (
        // xFee strictly increasing and yFee increasing for mints
        // xFee strictly decreasing and yFee increasing for burns
        // xFee strictly increasing and yFee should be in [0,BASE_9] for redemptions
        (action == ActionType.Mint && (xFee[i] >= xFee[i + 1] || (yFee[i + 1] < yFee[i])))
          || (action == ActionType.Burn && (xFee[i] <= xFee[i + 1] || (yFee[i + 1] < yFee[i])))
          || (action == ActionType.Redeem && (xFee[i] >= xFee[i + 1] || yFee[i] < 0 || yFee[i] > int256(BASE_9)))
      ) revert InvalidParams();
    }

    // If a mint or burn fee is negative, we need to check that accounts atomically minting
    // (from any collateral) and then burning cannot get more than their initial value
    if (yFee[0] < 0) {
      if (!LibDiamond.isGovernor(msg.sender)) revert NotGovernor(); // Only governor can set negative fees
      ParallelizerStorage storage ts = s.transmuterStorage();
      address[] memory collateralListMem = ts.collateralList;
      uint256 length = collateralListMem.length;
      if (action == ActionType.Mint) {
        // This can be mathematically expressed by `(1-min_c(burnFee_c))<=(1+mintFee[0])`
        for (uint256 i; i < length; ++i) {
          int64[] memory burnFees = ts.collaterals[collateralListMem[i]].yFeeBurn;
          if (burnFees[0] + yFee[0] < 0) revert InvalidNegativeFees();
        }
      }
      if (action == ActionType.Burn) {
        // This can be mathematically expressed by `(1-burnFee[0])<=(1+min_c(mintFee_c))`
        for (uint256 i; i < length; ++i) {
          int64[] memory mintFees = ts.collaterals[collateralListMem[i]].yFeeMint;
          if (yFee[0] + mintFees[0] < 0) revert InvalidNegativeFees();
        }
      }
    }
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import "../../utils/Constants.sol";
import { DiamondStorage, ImplementationStorage, ParallelizerStorage } from "../Storage.sol";

/// @title LibStorage
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibStorage` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibStorage.sol
library LibStorage {
  /// @notice Returns the storage struct stored at the `DIAMOND_STORAGE_POSITION` slot
  /// @dev This struct handles the logic of the different facets used in the diamond proxy
  function diamondStorage() internal pure returns (DiamondStorage storage ds) {
    bytes32 position = DIAMOND_STORAGE_POSITION;
    assembly ("memory-safe") {
      ds.slot := position
    }
  }

  /// @notice Returns the storage struct stored at the `TRANSMUTER_STORAGE_POSITION` slot
  /// @dev This struct handles the particular logic of the Parallelizer system
  function transmuterStorage() internal pure returns (ParallelizerStorage storage ts) {
    bytes32 position = TRANSMUTER_STORAGE_POSITION;
    assembly ("memory-safe") {
      ts.slot := position
    }
  }

  /// @notice Returns the storage struct stored at the `IMPLEMENTATION_STORAGE_POSITION` slot
  /// @dev This struct handles the logic for making the contract easily usable on Etherscan
  function implementationStorage() internal pure returns (ImplementationStorage storage ims) {
    bytes32 position = IMPLEMENTATION_STORAGE_POSITION;
    assembly ("memory-safe") {
      ims.slot := position
    }
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import { IKeyringGuard } from "contracts/interfaces/external/keyring/IKeyringGuard.sol";

import { LibStorage as s } from "./LibStorage.sol";

import "../../utils/Errors.sol";
import "../Storage.sol";

/// @title LibWhitelist
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibWhitelist` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibWhitelist.sol
library LibWhitelist {
  /// @notice Checks whether `sender` is whitelisted for a collateral with `whitelistData`
  function checkWhitelist(bytes memory whitelistData, address sender) internal returns (bool) {
    (WhitelistType whitelistType, bytes memory data) = abi.decode(whitelistData, (WhitelistType, bytes));
    if (s.transmuterStorage().isWhitelistedForType[whitelistType][sender] > 0) return true;
    if (data.length != 0) {
      if (whitelistType == WhitelistType.BACKED) {
        address keyringGuard = abi.decode(data, (address));
        if (keyringGuard != address(0)) return IKeyringGuard(keyringGuard).isAuthorized(address(this), sender);
      }
    }
    return false;
  }
}

File 30 of 31 : Constants.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import { ICbETH } from "contracts/interfaces/external/coinbase/ICbETH.sol";
import { ISfrxETH } from "contracts/interfaces/external/frax/ISfrxETH.sol";
import { IStETH } from "contracts/interfaces/external/lido/IStETH.sol";
import { IRETH } from "contracts/interfaces/external/rocketPool/IRETH.sol";

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                 STORAGE SLOTS                                                  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @dev Storage position of `DiamondStorage` structure
/// @dev Equals `keccak256("diamond.standard.diamond.storage") - 1`
bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b;

/// @dev Storage position of `ParallelizerStorage` structure
/// @dev Equals `keccak256("diamond.standard.parallelizer.storage") - 1`
bytes32 constant TRANSMUTER_STORAGE_POSITION = 0x4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c75;

/// @dev Storage position of `ImplementationStorage` structure
/// @dev Equals `keccak256("eip1967.proxy.implementation") - 1`
bytes32 constant IMPLEMENTATION_STORAGE_POSITION = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                     MATHS                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

uint256 constant BASE_6 = 1e6;
uint256 constant BASE_8 = 1e8;
uint256 constant BASE_9 = 1e9;
uint256 constant BASE_12 = 1e12;
uint256 constant BPS = 1e14;
uint256 constant BASE_18 = 1e18;
uint256 constant HALF_BASE_27 = 1e27 / 2;
uint256 constant BASE_27 = 1e27;
uint256 constant BASE_36 = 1e36;
uint256 constant MAX_BURN_FEE = 999_000_000;
uint256 constant MAX_MINT_FEE = BASE_12 - 1;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                     REENTRANT                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

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

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                     REENTRANT                                                      
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

// Role IDs for the AccessManager
uint64 constant GOVERNOR_ROLE = 10;
uint64 constant GUARDIAN_ROLE = 20;

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                               COMMON ADDRESSES                                                 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

address constant PERMIT_2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address constant ODOS_ROUTER = 0xCf5540fFFCdC3d510B18bFcA6d2b9987b0772559;
ICbETH constant CBETH = ICbETH(0xBe9895146f7AF43049ca1c1AE358B0541Ea49704);
IRETH constant RETH = IRETH(0xae78736Cd615f374D3085123A210448E74Fc6393);
IStETH constant STETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
ISfrxETH constant SFRXETH = ISfrxETH(0xac3E018457B222d93114458476f3E3416Abbe38F);
address constant XEVT = 0x3Ee320c9F73a84D1717557af00695A34b26d1F1d;
address constant USDM = 0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant EURC = 0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c;

File 31 of 31 : Errors.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

error AccessManagedUnauthorized(address caller);
error AlreadyAdded();
error CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector);
error CannotAddSelectorsToZeroAddress(bytes4[] _selectors);
error CannotRemoveFunctionThatDoesNotExist(bytes4 _selector);
error CannotRemoveImmutableFunction(bytes4 _selector);
error CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors);
error CannotReplaceFunctionThatDoesNotExists(bytes4 _selector);
error CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector);
error CannotReplaceImmutableFunction(bytes4 _selector);
error ContractHasNoCode();
error CollateralBacked();
error FunctionNotFound(bytes4 _functionSelector);
error IncorrectFacetCutAction(uint8 _action);
error InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata);
error InvalidChainlinkRate();
error InvalidLengths();
error InvalidNegativeFees();
error InvalidOracleType();
error InvalidParam();
error InvalidParams();
error InvalidRate();
error InvalidSwap();
error InvalidTokens();
error InvalidAccessManager();
error ManagerHasAssets();
error NoSelectorsProvidedForFacetForCut(address _facetAddress);
error NotAllowed();
error NotCollateral();
error NotGovernor();
error NotGuardian();
error NotTrusted();
error NotTrustedOrGuardian();
error NotWhitelisted();
error OdosSwapFailed();
error OracleUpdateFailed();
error Paused();
error ReentrantCall();
error RemoveFacetAddressMustBeZeroAddress(address _facetAddress);
error TooBigAmountIn();
error TooLate();
error TooSmallAmountOut();
error ZeroAddress();
error ZeroAmount();
error SwapError();
error SlippageTooHigh();
error InsufficientFunds();

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"name":"AlreadyAdded","type":"error"},{"inputs":[],"name":"InvalidAccessManager","type":"error"},{"inputs":[],"name":"InvalidChainlinkRate","type":"error"},{"inputs":[],"name":"InvalidNegativeFees","type":"error"},{"inputs":[],"name":"InvalidParams","type":"error"},{"inputs":[],"name":"NotCollateral","type":"error"},{"inputs":[],"name":"NotGovernor","type":"error"},{"inputs":[],"name":"OracleUpdateFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"collateral","type":"address"}],"name":"CollateralAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"uint64[]","name":"xFee","type":"uint64[]"},{"indexed":false,"internalType":"int64[]","name":"yFee","type":"int64[]"},{"indexed":false,"internalType":"bool","name":"mint","type":"bool"}],"name":"FeesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"bytes","name":"oracleConfig","type":"bytes"}],"name":"OracleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"uint256","name":"pausedType","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PauseToggled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64[]","name":"xFee","type":"uint64[]"},{"indexed":false,"internalType":"int64[]","name":"yFee","type":"int64[]"}],"name":"RedemptionCurveParamsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"uint256","name":"stablecoinCap","type":"uint256"}],"name":"StablecoinCapSet","type":"event"},{"inputs":[{"internalType":"contract IAccessManager","name":"_accessManager","type":"address"},{"internalType":"address","name":"_tokenP","type":"address"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"bool","name":"targetMax","type":"bool"},{"internalType":"bytes","name":"oracleConfig","type":"bytes"},{"internalType":"uint64[]","name":"xMintFee","type":"uint64[]"},{"internalType":"int64[]","name":"yMintFee","type":"int64[]"},{"internalType":"uint64[]","name":"xBurnFee","type":"uint64[]"},{"internalType":"int64[]","name":"yBurnFee","type":"int64[]"}],"internalType":"struct CollateralSetup[]","name":"_collaterals","type":"tuple[]"},{"components":[{"internalType":"uint64[]","name":"xRedeemFee","type":"uint64[]"},{"internalType":"int64[]","name":"yRedeemFee","type":"int64[]"}],"internalType":"struct RedemptionSetup","name":"_redemptionSetup","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608080604052346015576135f6908161001a8239f35b5f80fdfe60806040526004361015610011575f80fd5b5f5f3560e01c63f2238ad414610025575f80fd5b3461159357608036600319011261159357600435906001600160a01b038216809203611593576024356001600160a01b038116809103611593576044356001600160401b038111611593573660238201121561159357806004013561008981611ecc565b916100976040519384611eab565b8183526024602084019260051b820101903682116115935760248101925b828410611d335750505050606435916001600160401b03831161159357604060031984360301126115935760405192604084018481106001600160401b038211176115575760405280600401356001600160401b038111611593576101209060043691840101611efe565b84526024810135906001600160401b0382116115935760046101459236920101611f6c565b9460208401958652803b15611d0b576001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d54168173ffffffffffffffffffffffffffffffffffffffff197fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d5416177fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a37f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7580547f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7680546fffffffffffffffffffffffffffffffff167b033b2e3c9fd0803ce8000000000000000000000000000000000000001790557fffffffffffffffffffff00ff00000000000000000000000000000000000000001691909117750100000000000000000000000000000000000000000017905580515f915b818310610bbe575050508051516102d2575080f35b818015610b245750610301826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b80549060ff8260181c1615610b155783610aea575f809161032760ff8560101c1661215e565b9362ff00008560101b169062ff000019161790555b61048c57507f3da495aea17ab24773f3161f4707961a797e39147ce4f8a8fbac0309a4a2d2e46040849260ff8251916002835216156020820152a25191519180519280518414801590610b0d575b610afe578283848015610a42575b50610a33575f198501948511948491865b610a1f57818310156104a0578061048c57508491858680156103e4575b506103d55760010191866103a9565b600486635435b28960e11b8152fd5b90506104785760016001600160401b036103fe8388611ff5565b51169082018083116104645761041c6001600160401b039188611ff5565b51161180159061044e575b8015610434575b866103c6565b50633b9aca006104448286611ff5565b5160070b1361042e565b508561045a8286611ff5565b5160070b12610427565b602488634e487b7160e01b81526011600452fd5b602486634e487b7160e01b81526021600452fd5b80634e487b7160e01b602492526021600452fd5b9295505050806104af85611fd4565b5160070b126108b4575b5080516001600160401b0381116107b057600160401b81116107b0577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7854817f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7855808210610861575b5060208201907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c788452602084208160021c91855b83811061081c575060031981169003806107c4575b505050508251926001600160401b0384116107b057600160401b84116107b0577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7954847f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c795580851061073b575b5060208101937f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c798452602084208160021c91855b8381106106f657506003198116900380610679575b5050507fdd1690e851f57f138700d42b0a081b3b1b9a97dd2cb2aabc25c926587362906492935090610672610664926040519384936040855260408501906120ec565b908382036020850152612128565b0390a18080f35b958596865b8181106106be57505050019390935590918291906106726106647fdd1690e851f57f138700d42b0a081b3b1b9a97dd2cb2aabc25c9265873629064610621565b90919760206106ec6001928b5160070b908560031b6001600160401b03809160031b9316831b921b19161790565b990192910161067e565b86875b6004811061070e57508382015560010161060c565b89519099916001916020916001600160401b0360068e901b81811b199092169216901b17920199016106f9565b610789907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c79855260208520600380880160021c820192601889831b168061078f575b500160021c019061204f565b5f6105d8565b6107aa905f198601908154905f199060200360031b1c169055565b5f61077d565b602483634e487b7160e01b81526041600452fd5b928593865b8181106107de5750505001555f80808061056b565b90919460206108126001926001600160401b03895116908560031b6001600160401b03809160031b9316831b921b19161790565b96019291016107c9565b86875b60048110610834575083820155600101610556565b86519096916001916020916001600160401b0360068b901b81811b199092169216901b179201960161081f565b6108ae907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c78855260208520600380850160021c820192601886831b168061078f57500160021c019061204f565b5f610522565b604460406001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d54168151928380926368fc2b7760e11b8252600a60048301523360248301525afa908115610a145782916109c2575b50156109b357806040518060207f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c77549182815201907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7784526020842090845b818110610991575050509080610986920390611eab565b61048c5750816104b9565b82546001600160a01b031684528695506020909301926001928301920161096f565b80633b8d9d7560e21b60049252fd5b90506040813d604011610a0c575b816109dd60409383611eab565b81010312610a08578051908115158203610a045760206109fd9101612bf6565b505f610910565b8280fd5b5080fd5b3d91506109d0565b6040513d84823e3d90fd5b80634e487b7160e01b602492526011600452fd5b600484635435b28960e11b8152fd5b9050610aea575f1985018581119081610ad657633b9aca006001600160401b03610a6c8388611ff5565b511611918215610abc575b8215610a86575b505084610398565b909150610aa857610a9c633b9aca009184611ff5565b5160070b135f80610a7e565b602485634e487b7160e01b81526011600452fd5b5085915081610acb8286611ff5565b5160070b1291610a77565b602486634e487b7160e01b81526011600452fd5b602484634e487b7160e01b81526021600452fd5b600483635435b28960e11b8152fd5b50831561038a565b600484630dcfc57f60e21b8152fd5b7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c75549080610b5760ff8460a01c1661215e565b927fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff74ff00000000000000000000000000000000000000008560a01b169116177f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755561033c565b610bce8382979697959495611ff5565b51936001600160a01b03855116610c02816001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b805460ff8160181c16611ce3576040517f313ce567000000000000000000000000000000000000000000000000000000008152602081600481875afa8015611cd8578b90611c98575b63ff000000915060181b169063ff00000019161790557f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7754600160401b811015611c845760018101807f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7755811015611c70577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7789527f83745245930c5ea665f7d67c93434aa3e54c73e6ed3f6f245cc3d5c311286bfa01805473ffffffffffffffffffffffffffffffffffffffff1916821790557f7db05e63d635a68c62fd7fd8f3107ae8ab584a383e102d1bd8a40f4c977e465f8880a26001600160a01b038551166040860151610d7a826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b60ff815460181c1615611c6157600590610d9383612199565b500181516001600160401b038111611c4d57610daf8254612017565b601f8111611c1d575b5060208b601f8311600114611b97579180610e1e94927fba11329c0b0f98b91c254755aa8d698feac3b46fab65b65fe5ab7570de2ff928969491611b8c575b508160011b915f199060031b1c19161790555b604051918291602083526020830190612065565b0390a26001600160a01b0385511660608601516080870151610e5d836001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b60ff815460181c1615611b7d57610e758b838561236e565b8251600182016001600160401b038211611b6957600160401b8211611b69579081610ea6828f9454818455836120b0565b6020860190835260208320908260021c92845b848110611b2457506003198116900380611acd575b50505050506002018151906001600160401b038211611ab957600160401b8211611ab9579081610f04828e9454818455836120b0565b6020840190835260208320908260021c92845b848110611a74575060031981169003806119ff575b50505050507f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad91610f6e610664926040519384936060855260608501906120ec565b600160408301520390a26001600160a01b038551169660a08601519760c087015198610fb7826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b9960ff8b5460181c1615610b155760019a610fd38c838561236e565b84156117b6578251818d016001600160401b0382116117a257600160401b82116117a257908161100a8f93839054818455836120b0565b6020860190885260208820908260021c92895b84811061175e57506003198116900380611703575b50505050506002018151906001600160401b0382116116ef57600160401b82116116ef579081611068828f9454818455836120b0565b6020840190875260208720908260021c92885b8481106116a65750600319811690038061162d575b50505050507f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad916110d3610664925b6040519384936060855260608501906120ec565b8560408301520390a26001600160a01b038651169061110f826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b9060ff825460181c161561161e578061048c578082549261113560ff8560081c1661215e565b9361ff008560081b169061ff00191617905561048c575060407f3da495aea17ab24773f3161f4707961a797e39147ce4f8a8fbac0309a4a2d2e49160ff8251915f835216156020820152a26001600160a01b03855116946111b3866001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b95865460ff8160181c161561160f575f80986111d460ff8460101c1661215e565b9262ff00008460101b169062ff000019161790556115975760407f3da495aea17ab24773f3161f4707961a797e39147ce4f8a8fbac0309a4a2d2e49160ff8251918d835216156020820152a280516001600160a01b03165f8181525f5160206135a15f395f51905f526020526040902060ff815460181c161561160f5760096a52b7d2dcc80cd2e40000009101557feb6fe4a9f159360e971932dac27da07532267236a5423eaa27ea9f1cc641354e60206040516a52b7d2dcc80cd2e40000008152a260208101516112b3575b506001919293949596500191906102bd565b6001600160a01b039051169660ff6112e8896001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b5460181c161561160f57600561131b896001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b604051910180545f9161132d82612017565b808552918581169081156115e857506001146115ab575b5050906113568161135b930382611eab565b612b3a565b91600a849d959410156115975760088d0361156b5761137a8185612c6c565b9160208151918180820193849201010312611593575182111561156b57604051916020830152602082526113af604083611eab565b6040519c8d94602086016113c29161216f565b604085016113cf9161216f565b6060840160a0905260c084016113e491612065565b838103601f190160808501526113f991612065565b828103601f190160a084015261140e91612065565b03601f1981018a52611420908a611eab565b611447906001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b600501908851906001600160401b038211611557576114668354612017565b601f811161151c575b50602099601f83116001146114b85782916001969798999a9b83925f946114ad575b50501b915f199060031b1c19161790555b8695949392916112a1565b015192505f80611491565b601f9291921982169a845f52805f20915f5b8d8110611506575083600198999a9b9c9d106114ee575b505050811b0190556114a2565b01515f1960f88460031b161c191690555f80806114e1565b81830151845592850192602092830192016114ca565b61154790845f5260205f20601f850160051c8101916020861061154d575b601f0160051c019061204f565b5f61146f565b909150819061153a565b634e487b7160e01b5f52604160045260245ffd5b7faa2d4fb6000000000000000000000000000000000000000000000000000000005f5260045ffd5b5f80fd5b634e487b7160e01b5f52602160045260245ffd5b9091505f5260205f2090835f925b8284106115d157505050810160200161135682611344565b9081602092548386880101520192019184906115b9565b60ff191660208087019190915292151560051b850190920192506113569150839050611344565b630dcfc57f60e21b5f5260045ffd5b80630dcfc57f60e21b60049252fd5b93889489915b81831061166e575050505001558a6110d36106647f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad5f611090565b602061169b8598839495965160070b908760031b6001600160401b03809160031b9316831b921b19161790565b970193019190611633565b9d9e9d898a5b600481106116c35750848201559d9e9d850161107b565b845190949188916020916001600160401b03600689901b81811b199092169216901b17920194016116ac565b602486634e487b7160e01b81526041600452fd5b9389948a915b818310611720575050505001558b5f808080611032565b602061175385986001600160401b03849596975116908760031b6001600160401b03809160031b9316831b921b19161790565b970193019190611709565b85908b8c5b600481106117765750818601550161101d565b855160209096019589946001600160401b03918216600684901b90811b92901b19909316179101611763565b602487634e487b7160e01b81526041600452fd5b6003810183516001600160401b03811161155757600160401b811161155757816117e78f93839054818455836120b0565b60208601905f5260205f20908260021c925f5b8481106119bb57506003198116900380611960575b505050505060040181516001600160401b03811161155757600160401b81116115575781611843828f9454818455836120b0565b60208401905f5260205f20908260021c925f5b8481106119175750600319811690038061189e575b50505050507f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad916110d3610664926110bf565b935f945f915b8183106118df575050505001558a6110d36106647f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad5f61186b565b602061190c8598839495965160070b908760031b6001600160401b03809160031b9316831b921b19161790565b9701930191906118a4565b9d9e9d5f5f5b600481106119345750848201559d9e9d8501611856565b845190949188916020916001600160401b03600689901b81811b199092169216901b179201940161191d565b935f945f915b81831061197d575050505001558b5f80808061180f565b60206119b085986001600160401b03849596975116908760031b6001600160401b03809160031b9316831b921b19161790565b970193019190611966565b85905f5f5b600481106119d3575081860155016117fa565b855160209096019589946001600160401b03918216600684901b90811b92901b199093161791016119c0565b84905b808210611a3c57505050015589610f6e6106647f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad5f610f2c565b9091946020611a6a600192885160070b908660031b6001600160401b03809160031b9316831b921b19161790565b9601920190611a02565b85865b60048110611a8c575084820155600101610f17565b84519094916001916020916001600160401b03600689901b81811b199092169216901b1792019401611a77565b60248c634e487b7160e01b81526041600452fd5b84905b808210611ae65750505001558a5f808080610ece565b9091946020611b1a6001926001600160401b03895116908660031b6001600160401b03809160031b9316831b921b19161790565b9601920190611ad0565b85865b60048110611b3c575084820155600101610eb9565b84519094916001916020916001600160401b03600689901b81811b199092169216901b1792019401611b27565b60248d634e487b7160e01b81526041600452fd5b60048b630dcfc57f60e21b8152fd5b90508301515f610df7565b50828c52808c2090601f1983168d5b818110611c05575092610e1e9492600192827fba11329c0b0f98b91c254755aa8d698feac3b46fab65b65fe5ab7570de2ff928989610611bed575b5050811b019055610e0a565b8501515f1960f88460031b161c191690555f80611be1565b9192602060018192868a015181550194019201611ba6565b611c4790838d5260208d20601f840160051c8101916020851061154d57601f0160051c019061204f565b5f610db8565b60248b634e487b7160e01b81526041600452fd5b60048a630dcfc57f60e21b8152fd5b602489634e487b7160e01b81526032600452fd5b602489634e487b7160e01b81526041600452fd5b506020813d8211611cd0575b81611cb160209383611eab565b81010312611ccc57611cc763ff00000091612009565b610c4b565b8a80fd5b3d9150611ca4565b6040513d8d823e3d90fd5b60048a7ff411c327000000000000000000000000000000000000000000000000000000008152fd5b7fa98154e2000000000000000000000000000000000000000000000000000000005f5260045ffd5b83356001600160401b03811161159357820160e06023198236030112611593576040519160e083018381106001600160401b038211176115575760405260248201356001600160a01b03811681036115935783526044820135801515810361159357602084015260648201356001600160401b0381116115935760249083010136601f82011215611593578035611dc981611ee3565b91611dd76040519384611eab565b818352366020838301011161159357815f9260208093018386013783010152604084015260848201356001600160401b03811161159357611e1e9060243691850101611efe565b606084015260a48201356001600160401b03811161159357611e469060243691850101611f6c565b608084015260c48201356001600160401b03811161159357611e6e9060243691850101611efe565b60a084015260e4820135926001600160401b03841161159357611e9b602094936024869536920101611f6c565b60c08201528152019301926100b5565b90601f801991011681019081106001600160401b0382111761155757604052565b6001600160401b0381116115575760051b60200190565b6001600160401b03811161155757601f01601f191660200190565b9080601f8301121561159357813590611f1682611ecc565b92611f246040519485611eab565b82845260208085019360051b82010191821161159357602001915b818310611f4c5750505090565b82356001600160401b038116810361159357815260209283019201611f3f565b9080601f8301121561159357813590611f8482611ecc565b92611f926040519485611eab565b82845260208085019360051b82010191821161159357602001915b818310611fba5750505090565b82358060070b810361159357815260209283019201611fad565b805115611fe15760200190565b634e487b7160e01b5f52603260045260245ffd5b8051821015611fe15760209160051b010190565b519060ff8216820361159357565b90600182811c92168015612045575b602083101461203157565b634e487b7160e01b5f52602260045260245ffd5b91607f1691612026565b81811061205a575050565b5f815560010161204f565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b8181029291811591840414171561209c57565b634e487b7160e01b5f52601160045260245ffd5b91908082106120be57505050565b6120ea925f52600360205f2091601882850160021c840194831b168061078f57500160021c019061204f565b565b90602080835192838152019201905f5b8181106121095750505090565b82516001600160401b03168452602093840193909201916001016120fc565b90602080835192838152019201905f5b8181106121455750505090565b825160070b845260209384019390920191600101612138565b60ff166001039060ff821161209c57565b90600a8210156115975752565b51906fffffffffffffffffffffffffffffffff8216820361159357565b6121a290612b3a565b600a85949695939293101561159757600184146122a05760408180518101031261159357612206926fffffffffffffffffffffffffffffffff826121f760406121f060206121ff970161217c565b920161217c565b501696612c6c565b8093613085565b9280670de0b6b3a764000003670de0b6b3a7640000811161209c5761222b9083612089565b670de0b6b3a7640000850290858204670de0b6b3a7640000148615171561209c5781119182612272575b505061226a575b8281106122665750565b9150565b91508161225c565b909150670de0b6b3a76400000180670de0b6b3a76400001161209c576122989083612089565b115f80612255565b508093945060209250809150518101031261159357602001516001600160a01b038116809103611593576020600491604051928380927f5ade93550000000000000000000000000000000000000000000000000000000082525afa90811561233b575f9161230c575090565b90506020813d602011612333575b8161232760209383611eab565b81010312611593575190565b3d915061231a565b6040513d5f823e3d90fd5b9060070b9060070b0190677fffffffffffffff198212677fffffffffffffff83131761209c57565b9092919281519381518514801590612aec575b6123ed57600381101580611597578115948580612a76575b80156129e5575b828115612955575b506123ed575f198701968711965f885b61209c578181101561256457836115975787806124fb575b8015612484575b8481156123fc575b506123ed57600101886123b8565b635435b28960e11b5f5260045ffd5b9050611597576002851480612412575b846123df565b506001600160401b036124258289611ff5565b51166001820180831161209c576124446001600160401b03918a611ff5565b51161180159061246e575b8061240c5750633b9aca006124648288611ff5565b5160070b1361240c565b505f61247a8288611ff5565b5160070b1261244f565b505f93506001851480156123d757506001600160401b036124a58289611ff5565b5116600182019081831161209c576001600160401b036124c5838b611ff5565b511610908115916124d7575b506123d7565b6124e2915087611ff5565b5160070b6124f08288611ff5565b5160070b135f6124d1565b506001600160401b0361250e8289611ff5565b5116600182019081831161209c576001600160401b0361252e838b611ff5565b51161190811591612540575b506123d0565b61254b915087611ff5565b5160070b6125598288611ff5565b5160070b135f61253a565b5050955092509290925f61257785611fd4565b5160070b12612587575b50505050565b604460406001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d54168151928380926368fc2b7760e11b8252600a60048301523360248301525afa90811561233b575f9161290b575b50156128fc5760405191828360207f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775492838152017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775f5260205f20925f5b8181106128da57505061265792500384611eab565b825193611597576127fd575b600114612671575b80612581565b5f5b828110612680575061266b565b60026126bc6001600160a01b036126978486611ff5565b51166001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b016040519081602082549182815201915f5260205f20905f915b8160038401106127c05793612735938193612715935f9754918181106127ac575b818110612795575b81811061277e575b1061276d575b500382611eab565b61272b61272188611fd4565b5160070b91611fd4565b5160070b90612346565b60070b1261274557600101612673565b7f11336121000000000000000000000000000000000000000000000000000000005f5260045ffd5b60c01d60070b81526020015f61270d565b9260206001918460801c60070b8152019301612707565b9260206001918460401c60070b81520193016126ff565b9260206001918460070b81520193016126f7565b926001608060049286548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b60608201520194019201916126d6565b5f5b83811061280c5750612663565b60046128236001600160a01b036126978487611ff5565b016040519081602082549182815201915f5260205f20905f915b81600384011061289d578461288d94612880945f979461287b9454918181106127ac578181106127955781811061277e571061276d57500382611eab565b611fd4565b5160070b61272b88611fd4565b60070b12612745576001016127ff565b926001608060049286548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b606082015201940192019161283d565b84546001600160a01b0316835260019485019488945060209093019201612642565b633b8d9d7560e21b5f5260045ffd5b90506040813d60401161294d575b8161292660409383611eab565b810103126115935780519081151582036115935760206129469101612bf6565b505f6125e3565b3d9150612919565b905061159757600283148061296b575b826123a8565b505f198701878111908161209c57633b9aca006001600160401b03612990838a611ff5565b5116119182156129cb575b82156129a9575b5050612965565b90915061209c576129bf633b9aca009186611ff5565b5160070b135f806129a2565b505f9150816129da8288611ff5565b5160070b129161299b565b505f915060018314806129f8575b6123a0565b50633b9aca006001600160401b03612a0f87611fd4565b511614801590612a51575b806123a057506001871180156129f35750612a3484611fd4565b5160070b845160011015611fe157604085015160070b14156123a0565b505f19870187811161209c57612a6c633b9aca009186611ff5565b5160070b13612a1a565b505f19870187811161209c57633b9aca006001600160401b03612a998389611ff5565b51161090811591612acf575b8115612ab2575b50612399565b64e8d4a510009150612ac49086611ff5565b5160070b135f612aac565b90506001600160401b03612ae287611fd4565b5116151590612aa5565b508415612381565b81601f8201121561159357805190612b0b82611ee3565b92612b196040519485611eab565b8284526020838301011161159357815f9260208093018386015e8301015290565b8051810160a08260208301920312611593576020820151600a81101561159357604083015193600a8510156115935760608401516001600160401b03811161159357836020612b8b92870101612af4565b9360808101516001600160401b03811161159357846020612bae92840101612af4565b9360a0820151916001600160401b03831161159357612bd09201602001612af4565b919493929190565b8115612be2570490565b634e487b7160e01b5f52601260045260245ffd5b519063ffffffff8216820361159357565b9080601f83011215611593578151612c1e81611ecc565b92612c2c6040519485611eab565b81845260208085019260051b82010192831161159357602001905b828210612c545750505090565b60208091612c6184612009565b815201910190612c47565b600a8110156115975780612e74575090815182019160a081602085019403126115935760208101516001600160401b0381116115935781019280603f85011215611593576020840151612cbe81611ecc565b94612ccc6040519687611eab565b8186526020808088019360051b830101019083821161159357604001915b818310612e545750505060408201516001600160401b03811161159357820181603f8201121561159357602081015190612d2382611ecc565b91612d316040519384611eab565b8083526020808085019260051b840101019184831161159357604001905b828210612e3c5750505060608301516001600160401b03811161159357826020612d7b92860101612c07565b9160808401516001600160401b0381116115935760a0916020612da092870101612c07565b930151600281101561159357670de0b6b3a7640000612dc3919694929596613426565b938351915f935b838510612dda5750505050505090565b90919293949695612e2f6001916001600160a01b03612df9898c611ff5565b511660ff612e078a87611ff5565b511660ff612e158b89611ff5565b51169163ffffffff612e278c8b611ff5565b511693613465565b9697950193929190612dca565b60208091612e4984612bf6565b815201910190612d4f565b82516001600160a01b038116810361159357815260209283019201612cea565b60038103612e8a575050670de0b6b3a764000090565b60028103612ea0575050670de0b6b3a764000090565b60048103612ef3575050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561233b575f9161230c575090565b60058103612f38575050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561233b575f9161230c575090565b60068103612f7d5750506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561233b575f9161230c575090565b60078103612fc2575050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561233b575f9161230c575090565b60088103612fe3575060208151918180820193849201010312611593575190565b600903613078576040818051810103126115935760208101516001600160a01b03811680910361159357602060406004930151916040519384809263501ad8ff60e11b82525afa801561233b575f90613044575b6130419250612bd8565b90565b506020823d602011613070575b8161305e60209383611eab565b81010312611593576130419151613037565b3d9150613051565b50670de0b6b3a764000090565b92919092600a811015611597578061325257508051810160a082602083019203126115935760208201516001600160401b0381116115935782019381603f860112156115935760208501516130d981611ecc565b956130e76040519788611eab565b8187526020808089019360051b830101019084821161159357604001915b8183106132325750505060408301516001600160401b0381116115935783019082603f830112156115935760208201519161313f83611ecc565b9261314d6040519485611eab565b8084526020808086019260051b840101019185831161159357604001905b82821061321a5750505060608401516001600160401b0381116115935783602061319792870101612c07565b9260808501516001600160401b0381116115935760a09160206131bc92880101612c07565b940151906002821015611593576131d7919694929596613426565b938351915f935b8385106131ee5750505050505090565b9091929394969561320d6001916001600160a01b03612df9898c611ff5565b96979501939291906131de565b6020809161322784612bf6565b81520191019061316b565b82516001600160a01b038116810361159357815260209283019201613105565b919290916003810361326d57505050670de0b6b3a764000090565b6002810361327b5750905090565b600481036132cf57505050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561233b575f9161230c575090565b6005810361331557505050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561233b575f9161230c575090565b6006810361335b575050506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561233b575f9161230c575090565b600781036133a157505050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561233b575f9161230c575090565b600881036133c357505060208151918180820193849201010312611593575190565b60090361342157506040818051810103126115935760208101516001600160a01b03811680910361159357602060406004930151916040519384809263501ad8ff60e11b82525afa801561233b575f90613044576130419250612bd8565b905090565b6002811015611597576130415750670de0b6b3a764000090565b519069ffffffffffffffffffff8216820361159357565b604d811161209c57600a0a90565b91909360a06001600160a01b0394956004604051809781937ffeaf968c000000000000000000000000000000000000000000000000000000008352165afa90811561233b575f945f9261354a575b505f851391821592613530575b50506135085760ff166001036134ed576134e161304193926134e792612089565b91613457565b90612bd8565b613503906134fd61304194613457565b90612089565b612bd8565b7fae193563000000000000000000000000000000000000000000000000000000005f5260045ffd5b429081039250821161209c5763ffffffff16105f806134c0565b9450905060a0843d60a011613598575b8161356760a09383611eab565b810103126115935761357884613440565b50602084015161358f608060608701519601613440565b5093905f6134b3565b3d915061355a56fe4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7aa2646970667358221220148c5b80053dd83b1f0de97c2c0279a8d424b040e1818d591cfde1d464395a9464736f6c634300081c0033

Deployed Bytecode

0x60806040526004361015610011575f80fd5b5f5f3560e01c63f2238ad414610025575f80fd5b3461159357608036600319011261159357600435906001600160a01b038216809203611593576024356001600160a01b038116809103611593576044356001600160401b038111611593573660238201121561159357806004013561008981611ecc565b916100976040519384611eab565b8183526024602084019260051b820101903682116115935760248101925b828410611d335750505050606435916001600160401b03831161159357604060031984360301126115935760405192604084018481106001600160401b038211176115575760405280600401356001600160401b038111611593576101209060043691840101611efe565b84526024810135906001600160401b0382116115935760046101459236920101611f6c565b9460208401958652803b15611d0b576001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d54168173ffffffffffffffffffffffffffffffffffffffff197fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d5416177fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a37f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7580547f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7680546fffffffffffffffffffffffffffffffff167b033b2e3c9fd0803ce8000000000000000000000000000000000000001790557fffffffffffffffffffff00ff00000000000000000000000000000000000000001691909117750100000000000000000000000000000000000000000017905580515f915b818310610bbe575050508051516102d2575080f35b818015610b245750610301826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b80549060ff8260181c1615610b155783610aea575f809161032760ff8560101c1661215e565b9362ff00008560101b169062ff000019161790555b61048c57507f3da495aea17ab24773f3161f4707961a797e39147ce4f8a8fbac0309a4a2d2e46040849260ff8251916002835216156020820152a25191519180519280518414801590610b0d575b610afe578283848015610a42575b50610a33575f198501948511948491865b610a1f57818310156104a0578061048c57508491858680156103e4575b506103d55760010191866103a9565b600486635435b28960e11b8152fd5b90506104785760016001600160401b036103fe8388611ff5565b51169082018083116104645761041c6001600160401b039188611ff5565b51161180159061044e575b8015610434575b866103c6565b50633b9aca006104448286611ff5565b5160070b1361042e565b508561045a8286611ff5565b5160070b12610427565b602488634e487b7160e01b81526011600452fd5b602486634e487b7160e01b81526021600452fd5b80634e487b7160e01b602492526021600452fd5b9295505050806104af85611fd4565b5160070b126108b4575b5080516001600160401b0381116107b057600160401b81116107b0577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7854817f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7855808210610861575b5060208201907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c788452602084208160021c91855b83811061081c575060031981169003806107c4575b505050508251926001600160401b0384116107b057600160401b84116107b0577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7954847f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c795580851061073b575b5060208101937f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c798452602084208160021c91855b8381106106f657506003198116900380610679575b5050507fdd1690e851f57f138700d42b0a081b3b1b9a97dd2cb2aabc25c926587362906492935090610672610664926040519384936040855260408501906120ec565b908382036020850152612128565b0390a18080f35b958596865b8181106106be57505050019390935590918291906106726106647fdd1690e851f57f138700d42b0a081b3b1b9a97dd2cb2aabc25c9265873629064610621565b90919760206106ec6001928b5160070b908560031b6001600160401b03809160031b9316831b921b19161790565b990192910161067e565b86875b6004811061070e57508382015560010161060c565b89519099916001916020916001600160401b0360068e901b81811b199092169216901b17920199016106f9565b610789907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c79855260208520600380880160021c820192601889831b168061078f575b500160021c019061204f565b5f6105d8565b6107aa905f198601908154905f199060200360031b1c169055565b5f61077d565b602483634e487b7160e01b81526041600452fd5b928593865b8181106107de5750505001555f80808061056b565b90919460206108126001926001600160401b03895116908560031b6001600160401b03809160031b9316831b921b19161790565b96019291016107c9565b86875b60048110610834575083820155600101610556565b86519096916001916020916001600160401b0360068b901b81811b199092169216901b179201960161081f565b6108ae907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c78855260208520600380850160021c820192601886831b168061078f57500160021c019061204f565b5f610522565b604460406001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d54168151928380926368fc2b7760e11b8252600a60048301523360248301525afa908115610a145782916109c2575b50156109b357806040518060207f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c77549182815201907f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7784526020842090845b818110610991575050509080610986920390611eab565b61048c5750816104b9565b82546001600160a01b031684528695506020909301926001928301920161096f565b80633b8d9d7560e21b60049252fd5b90506040813d604011610a0c575b816109dd60409383611eab565b81010312610a08578051908115158203610a045760206109fd9101612bf6565b505f610910565b8280fd5b5080fd5b3d91506109d0565b6040513d84823e3d90fd5b80634e487b7160e01b602492526011600452fd5b600484635435b28960e11b8152fd5b9050610aea575f1985018581119081610ad657633b9aca006001600160401b03610a6c8388611ff5565b511611918215610abc575b8215610a86575b505084610398565b909150610aa857610a9c633b9aca009184611ff5565b5160070b135f80610a7e565b602485634e487b7160e01b81526011600452fd5b5085915081610acb8286611ff5565b5160070b1291610a77565b602486634e487b7160e01b81526011600452fd5b602484634e487b7160e01b81526021600452fd5b600483635435b28960e11b8152fd5b50831561038a565b600484630dcfc57f60e21b8152fd5b7f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c75549080610b5760ff8460a01c1661215e565b927fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff74ff00000000000000000000000000000000000000008560a01b169116177f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c755561033c565b610bce8382979697959495611ff5565b51936001600160a01b03855116610c02816001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b805460ff8160181c16611ce3576040517f313ce567000000000000000000000000000000000000000000000000000000008152602081600481875afa8015611cd8578b90611c98575b63ff000000915060181b169063ff00000019161790557f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7754600160401b811015611c845760018101807f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7755811015611c70577f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7789527f83745245930c5ea665f7d67c93434aa3e54c73e6ed3f6f245cc3d5c311286bfa01805473ffffffffffffffffffffffffffffffffffffffff1916821790557f7db05e63d635a68c62fd7fd8f3107ae8ab584a383e102d1bd8a40f4c977e465f8880a26001600160a01b038551166040860151610d7a826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b60ff815460181c1615611c6157600590610d9383612199565b500181516001600160401b038111611c4d57610daf8254612017565b601f8111611c1d575b5060208b601f8311600114611b97579180610e1e94927fba11329c0b0f98b91c254755aa8d698feac3b46fab65b65fe5ab7570de2ff928969491611b8c575b508160011b915f199060031b1c19161790555b604051918291602083526020830190612065565b0390a26001600160a01b0385511660608601516080870151610e5d836001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b60ff815460181c1615611b7d57610e758b838561236e565b8251600182016001600160401b038211611b6957600160401b8211611b69579081610ea6828f9454818455836120b0565b6020860190835260208320908260021c92845b848110611b2457506003198116900380611acd575b50505050506002018151906001600160401b038211611ab957600160401b8211611ab9579081610f04828e9454818455836120b0565b6020840190835260208320908260021c92845b848110611a74575060031981169003806119ff575b50505050507f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad91610f6e610664926040519384936060855260608501906120ec565b600160408301520390a26001600160a01b038551169660a08601519760c087015198610fb7826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b9960ff8b5460181c1615610b155760019a610fd38c838561236e565b84156117b6578251818d016001600160401b0382116117a257600160401b82116117a257908161100a8f93839054818455836120b0565b6020860190885260208820908260021c92895b84811061175e57506003198116900380611703575b50505050506002018151906001600160401b0382116116ef57600160401b82116116ef579081611068828f9454818455836120b0565b6020840190875260208720908260021c92885b8481106116a65750600319811690038061162d575b50505050507f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad916110d3610664925b6040519384936060855260608501906120ec565b8560408301520390a26001600160a01b038651169061110f826001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b9060ff825460181c161561161e578061048c578082549261113560ff8560081c1661215e565b9361ff008560081b169061ff00191617905561048c575060407f3da495aea17ab24773f3161f4707961a797e39147ce4f8a8fbac0309a4a2d2e49160ff8251915f835216156020820152a26001600160a01b03855116946111b3866001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b95865460ff8160181c161561160f575f80986111d460ff8460101c1661215e565b9262ff00008460101b169062ff000019161790556115975760407f3da495aea17ab24773f3161f4707961a797e39147ce4f8a8fbac0309a4a2d2e49160ff8251918d835216156020820152a280516001600160a01b03165f8181525f5160206135a15f395f51905f526020526040902060ff815460181c161561160f5760096a52b7d2dcc80cd2e40000009101557feb6fe4a9f159360e971932dac27da07532267236a5423eaa27ea9f1cc641354e60206040516a52b7d2dcc80cd2e40000008152a260208101516112b3575b506001919293949596500191906102bd565b6001600160a01b039051169660ff6112e8896001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b5460181c161561160f57600561131b896001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b604051910180545f9161132d82612017565b808552918581169081156115e857506001146115ab575b5050906113568161135b930382611eab565b612b3a565b91600a849d959410156115975760088d0361156b5761137a8185612c6c565b9160208151918180820193849201010312611593575182111561156b57604051916020830152602082526113af604083611eab565b6040519c8d94602086016113c29161216f565b604085016113cf9161216f565b6060840160a0905260c084016113e491612065565b838103601f190160808501526113f991612065565b828103601f190160a084015261140e91612065565b03601f1981018a52611420908a611eab565b611447906001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b600501908851906001600160401b038211611557576114668354612017565b601f811161151c575b50602099601f83116001146114b85782916001969798999a9b83925f946114ad575b50501b915f199060031b1c19161790555b8695949392916112a1565b015192505f80611491565b601f9291921982169a845f52805f20915f5b8d8110611506575083600198999a9b9c9d106114ee575b505050811b0190556114a2565b01515f1960f88460031b161c191690555f80806114e1565b81830151845592850192602092830192016114ca565b61154790845f5260205f20601f850160051c8101916020861061154d575b601f0160051c019061204f565b5f61146f565b909150819061153a565b634e487b7160e01b5f52604160045260245ffd5b7faa2d4fb6000000000000000000000000000000000000000000000000000000005f5260045ffd5b5f80fd5b634e487b7160e01b5f52602160045260245ffd5b9091505f5260205f2090835f925b8284106115d157505050810160200161135682611344565b9081602092548386880101520192019184906115b9565b60ff191660208087019190915292151560051b850190920192506113569150839050611344565b630dcfc57f60e21b5f5260045ffd5b80630dcfc57f60e21b60049252fd5b93889489915b81831061166e575050505001558a6110d36106647f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad5f611090565b602061169b8598839495965160070b908760031b6001600160401b03809160031b9316831b921b19161790565b970193019190611633565b9d9e9d898a5b600481106116c35750848201559d9e9d850161107b565b845190949188916020916001600160401b03600689901b81811b199092169216901b17920194016116ac565b602486634e487b7160e01b81526041600452fd5b9389948a915b818310611720575050505001558b5f808080611032565b602061175385986001600160401b03849596975116908760031b6001600160401b03809160031b9316831b921b19161790565b970193019190611709565b85908b8c5b600481106117765750818601550161101d565b855160209096019589946001600160401b03918216600684901b90811b92901b19909316179101611763565b602487634e487b7160e01b81526041600452fd5b6003810183516001600160401b03811161155757600160401b811161155757816117e78f93839054818455836120b0565b60208601905f5260205f20908260021c925f5b8481106119bb57506003198116900380611960575b505050505060040181516001600160401b03811161155757600160401b81116115575781611843828f9454818455836120b0565b60208401905f5260205f20908260021c925f5b8481106119175750600319811690038061189e575b50505050507f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad916110d3610664926110bf565b935f945f915b8183106118df575050505001558a6110d36106647f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad5f61186b565b602061190c8598839495965160070b908760031b6001600160401b03809160031b9316831b921b19161790565b9701930191906118a4565b9d9e9d5f5f5b600481106119345750848201559d9e9d8501611856565b845190949188916020916001600160401b03600689901b81811b199092169216901b179201940161191d565b935f945f915b81831061197d575050505001558b5f80808061180f565b60206119b085986001600160401b03849596975116908760031b6001600160401b03809160031b9316831b921b19161790565b970193019190611966565b85905f5f5b600481106119d3575081860155016117fa565b855160209096019589946001600160401b03918216600684901b90811b92901b199093161791016119c0565b84905b808210611a3c57505050015589610f6e6106647f8abfb482e6f6ae87066f0006f10aff1738f4182d4f66b7a084685e4a6c51cfad5f610f2c565b9091946020611a6a600192885160070b908660031b6001600160401b03809160031b9316831b921b19161790565b9601920190611a02565b85865b60048110611a8c575084820155600101610f17565b84519094916001916020916001600160401b03600689901b81811b199092169216901b1792019401611a77565b60248c634e487b7160e01b81526041600452fd5b84905b808210611ae65750505001558a5f808080610ece565b9091946020611b1a6001926001600160401b03895116908660031b6001600160401b03809160031b9316831b921b19161790565b9601920190611ad0565b85865b60048110611b3c575084820155600101610eb9565b84519094916001916020916001600160401b03600689901b81811b199092169216901b1792019401611b27565b60248d634e487b7160e01b81526041600452fd5b60048b630dcfc57f60e21b8152fd5b90508301515f610df7565b50828c52808c2090601f1983168d5b818110611c05575092610e1e9492600192827fba11329c0b0f98b91c254755aa8d698feac3b46fab65b65fe5ab7570de2ff928989610611bed575b5050811b019055610e0a565b8501515f1960f88460031b161c191690555f80611be1565b9192602060018192868a015181550194019201611ba6565b611c4790838d5260208d20601f840160051c8101916020851061154d57601f0160051c019061204f565b5f610db8565b60248b634e487b7160e01b81526041600452fd5b60048a630dcfc57f60e21b8152fd5b602489634e487b7160e01b81526032600452fd5b602489634e487b7160e01b81526041600452fd5b506020813d8211611cd0575b81611cb160209383611eab565b81010312611ccc57611cc763ff00000091612009565b610c4b565b8a80fd5b3d9150611ca4565b6040513d8d823e3d90fd5b60048a7ff411c327000000000000000000000000000000000000000000000000000000008152fd5b7fa98154e2000000000000000000000000000000000000000000000000000000005f5260045ffd5b83356001600160401b03811161159357820160e06023198236030112611593576040519160e083018381106001600160401b038211176115575760405260248201356001600160a01b03811681036115935783526044820135801515810361159357602084015260648201356001600160401b0381116115935760249083010136601f82011215611593578035611dc981611ee3565b91611dd76040519384611eab565b818352366020838301011161159357815f9260208093018386013783010152604084015260848201356001600160401b03811161159357611e1e9060243691850101611efe565b606084015260a48201356001600160401b03811161159357611e469060243691850101611f6c565b608084015260c48201356001600160401b03811161159357611e6e9060243691850101611efe565b60a084015260e4820135926001600160401b03841161159357611e9b602094936024869536920101611f6c565b60c08201528152019301926100b5565b90601f801991011681019081106001600160401b0382111761155757604052565b6001600160401b0381116115575760051b60200190565b6001600160401b03811161155757601f01601f191660200190565b9080601f8301121561159357813590611f1682611ecc565b92611f246040519485611eab565b82845260208085019360051b82010191821161159357602001915b818310611f4c5750505090565b82356001600160401b038116810361159357815260209283019201611f3f565b9080601f8301121561159357813590611f8482611ecc565b92611f926040519485611eab565b82845260208085019360051b82010191821161159357602001915b818310611fba5750505090565b82358060070b810361159357815260209283019201611fad565b805115611fe15760200190565b634e487b7160e01b5f52603260045260245ffd5b8051821015611fe15760209160051b010190565b519060ff8216820361159357565b90600182811c92168015612045575b602083101461203157565b634e487b7160e01b5f52602260045260245ffd5b91607f1691612026565b81811061205a575050565b5f815560010161204f565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b8181029291811591840414171561209c57565b634e487b7160e01b5f52601160045260245ffd5b91908082106120be57505050565b6120ea925f52600360205f2091601882850160021c840194831b168061078f57500160021c019061204f565b565b90602080835192838152019201905f5b8181106121095750505090565b82516001600160401b03168452602093840193909201916001016120fc565b90602080835192838152019201905f5b8181106121455750505090565b825160070b845260209384019390920191600101612138565b60ff166001039060ff821161209c57565b90600a8210156115975752565b51906fffffffffffffffffffffffffffffffff8216820361159357565b6121a290612b3a565b600a85949695939293101561159757600184146122a05760408180518101031261159357612206926fffffffffffffffffffffffffffffffff826121f760406121f060206121ff970161217c565b920161217c565b501696612c6c565b8093613085565b9280670de0b6b3a764000003670de0b6b3a7640000811161209c5761222b9083612089565b670de0b6b3a7640000850290858204670de0b6b3a7640000148615171561209c5781119182612272575b505061226a575b8281106122665750565b9150565b91508161225c565b909150670de0b6b3a76400000180670de0b6b3a76400001161209c576122989083612089565b115f80612255565b508093945060209250809150518101031261159357602001516001600160a01b038116809103611593576020600491604051928380927f5ade93550000000000000000000000000000000000000000000000000000000082525afa90811561233b575f9161230c575090565b90506020813d602011612333575b8161232760209383611eab565b81010312611593575190565b3d915061231a565b6040513d5f823e3d90fd5b9060070b9060070b0190677fffffffffffffff198212677fffffffffffffff83131761209c57565b9092919281519381518514801590612aec575b6123ed57600381101580611597578115948580612a76575b80156129e5575b828115612955575b506123ed575f198701968711965f885b61209c578181101561256457836115975787806124fb575b8015612484575b8481156123fc575b506123ed57600101886123b8565b635435b28960e11b5f5260045ffd5b9050611597576002851480612412575b846123df565b506001600160401b036124258289611ff5565b51166001820180831161209c576124446001600160401b03918a611ff5565b51161180159061246e575b8061240c5750633b9aca006124648288611ff5565b5160070b1361240c565b505f61247a8288611ff5565b5160070b1261244f565b505f93506001851480156123d757506001600160401b036124a58289611ff5565b5116600182019081831161209c576001600160401b036124c5838b611ff5565b511610908115916124d7575b506123d7565b6124e2915087611ff5565b5160070b6124f08288611ff5565b5160070b135f6124d1565b506001600160401b0361250e8289611ff5565b5116600182019081831161209c576001600160401b0361252e838b611ff5565b51161190811591612540575b506123d0565b61254b915087611ff5565b5160070b6125598288611ff5565b5160070b135f61253a565b5050955092509290925f61257785611fd4565b5160070b12612587575b50505050565b604460406001600160a01b037fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131d54168151928380926368fc2b7760e11b8252600a60048301523360248301525afa90811561233b575f9161290b575b50156128fc5760405191828360207f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775492838152017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775f5260205f20925f5b8181106128da57505061265792500384611eab565b825193611597576127fd575b600114612671575b80612581565b5f5b828110612680575061266b565b60026126bc6001600160a01b036126978486611ff5565b51166001600160a01b03165f525f5160206135a15f395f51905f5260205260405f2090565b016040519081602082549182815201915f5260205f20905f915b8160038401106127c05793612735938193612715935f9754918181106127ac575b818110612795575b81811061277e575b1061276d575b500382611eab565b61272b61272188611fd4565b5160070b91611fd4565b5160070b90612346565b60070b1261274557600101612673565b7f11336121000000000000000000000000000000000000000000000000000000005f5260045ffd5b60c01d60070b81526020015f61270d565b9260206001918460801c60070b8152019301612707565b9260206001918460401c60070b81520193016126ff565b9260206001918460070b81520193016126f7565b926001608060049286548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b60608201520194019201916126d6565b5f5b83811061280c5750612663565b60046128236001600160a01b036126978487611ff5565b016040519081602082549182815201915f5260205f20905f915b81600384011061289d578461288d94612880945f979461287b9454918181106127ac578181106127955781811061277e571061276d57500382611eab565b611fd4565b5160070b61272b88611fd4565b60070b12612745576001016127ff565b926001608060049286548060070b82528060401c60070b602083015280831c60070b604083015260c01d60070b606082015201940192019161283d565b84546001600160a01b0316835260019485019488945060209093019201612642565b633b8d9d7560e21b5f5260045ffd5b90506040813d60401161294d575b8161292660409383611eab565b810103126115935780519081151582036115935760206129469101612bf6565b505f6125e3565b3d9150612919565b905061159757600283148061296b575b826123a8565b505f198701878111908161209c57633b9aca006001600160401b03612990838a611ff5565b5116119182156129cb575b82156129a9575b5050612965565b90915061209c576129bf633b9aca009186611ff5565b5160070b135f806129a2565b505f9150816129da8288611ff5565b5160070b129161299b565b505f915060018314806129f8575b6123a0565b50633b9aca006001600160401b03612a0f87611fd4565b511614801590612a51575b806123a057506001871180156129f35750612a3484611fd4565b5160070b845160011015611fe157604085015160070b14156123a0565b505f19870187811161209c57612a6c633b9aca009186611ff5565b5160070b13612a1a565b505f19870187811161209c57633b9aca006001600160401b03612a998389611ff5565b51161090811591612acf575b8115612ab2575b50612399565b64e8d4a510009150612ac49086611ff5565b5160070b135f612aac565b90506001600160401b03612ae287611fd4565b5116151590612aa5565b508415612381565b81601f8201121561159357805190612b0b82611ee3565b92612b196040519485611eab565b8284526020838301011161159357815f9260208093018386015e8301015290565b8051810160a08260208301920312611593576020820151600a81101561159357604083015193600a8510156115935760608401516001600160401b03811161159357836020612b8b92870101612af4565b9360808101516001600160401b03811161159357846020612bae92840101612af4565b9360a0820151916001600160401b03831161159357612bd09201602001612af4565b919493929190565b8115612be2570490565b634e487b7160e01b5f52601260045260245ffd5b519063ffffffff8216820361159357565b9080601f83011215611593578151612c1e81611ecc565b92612c2c6040519485611eab565b81845260208085019260051b82010192831161159357602001905b828210612c545750505090565b60208091612c6184612009565b815201910190612c47565b600a8110156115975780612e74575090815182019160a081602085019403126115935760208101516001600160401b0381116115935781019280603f85011215611593576020840151612cbe81611ecc565b94612ccc6040519687611eab565b8186526020808088019360051b830101019083821161159357604001915b818310612e545750505060408201516001600160401b03811161159357820181603f8201121561159357602081015190612d2382611ecc565b91612d316040519384611eab565b8083526020808085019260051b840101019184831161159357604001905b828210612e3c5750505060608301516001600160401b03811161159357826020612d7b92860101612c07565b9160808401516001600160401b0381116115935760a0916020612da092870101612c07565b930151600281101561159357670de0b6b3a7640000612dc3919694929596613426565b938351915f935b838510612dda5750505050505090565b90919293949695612e2f6001916001600160a01b03612df9898c611ff5565b511660ff612e078a87611ff5565b511660ff612e158b89611ff5565b51169163ffffffff612e278c8b611ff5565b511693613465565b9697950193929190612dca565b60208091612e4984612bf6565b815201910190612d4f565b82516001600160a01b038116810361159357815260209283019201612cea565b60038103612e8a575050670de0b6b3a764000090565b60028103612ea0575050670de0b6b3a764000090565b60048103612ef3575050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561233b575f9161230c575090565b60058103612f38575050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561233b575f9161230c575090565b60068103612f7d5750506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561233b575f9161230c575090565b60078103612fc2575050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561233b575f9161230c575090565b60088103612fe3575060208151918180820193849201010312611593575190565b600903613078576040818051810103126115935760208101516001600160a01b03811680910361159357602060406004930151916040519384809263501ad8ff60e11b82525afa801561233b575f90613044575b6130419250612bd8565b90565b506020823d602011613070575b8161305e60209383611eab565b81010312611593576130419151613037565b3d9150613051565b50670de0b6b3a764000090565b92919092600a811015611597578061325257508051810160a082602083019203126115935760208201516001600160401b0381116115935782019381603f860112156115935760208501516130d981611ecc565b956130e76040519788611eab565b8187526020808089019360051b830101019084821161159357604001915b8183106132325750505060408301516001600160401b0381116115935783019082603f830112156115935760208201519161313f83611ecc565b9261314d6040519485611eab565b8084526020808086019260051b840101019185831161159357604001905b82821061321a5750505060608401516001600160401b0381116115935783602061319792870101612c07565b9260808501516001600160401b0381116115935760a09160206131bc92880101612c07565b940151906002821015611593576131d7919694929596613426565b938351915f935b8385106131ee5750505050505090565b9091929394969561320d6001916001600160a01b03612df9898c611ff5565b96979501939291906131de565b6020809161322784612bf6565b81520191019061316b565b82516001600160a01b038116810361159357815260209283019201613105565b919290916003810361326d57505050670de0b6b3a764000090565b6002810361327b5750905090565b600481036132cf57505050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561233b575f9161230c575090565b6005810361331557505050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561233b575f9161230c575090565b6006810361335b575050506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561233b575f9161230c575090565b600781036133a157505050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561233b575f9161230c575090565b600881036133c357505060208151918180820193849201010312611593575190565b60090361342157506040818051810103126115935760208101516001600160a01b03811680910361159357602060406004930151916040519384809263501ad8ff60e11b82525afa801561233b575f90613044576130419250612bd8565b905090565b6002811015611597576130415750670de0b6b3a764000090565b519069ffffffffffffffffffff8216820361159357565b604d811161209c57600a0a90565b91909360a06001600160a01b0394956004604051809781937ffeaf968c000000000000000000000000000000000000000000000000000000008352165afa90811561233b575f945f9261354a575b505f851391821592613530575b50506135085760ff166001036134ed576134e161304193926134e792612089565b91613457565b90612bd8565b613503906134fd61304194613457565b90612089565b612bd8565b7fae193563000000000000000000000000000000000000000000000000000000005f5260045ffd5b429081039250821161209c5763ffffffff16105f806134c0565b9450905060a0843d60a011613598575b8161356760a09383611eab565b810103126115935761357884613440565b50602084015161358f608060608701519601613440565b5093905f6134b3565b3d915061355a56fe4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7aa2646970667358221220148c5b80053dd83b1f0de97c2c0279a8d424b040e1818d591cfde1d464395a9464736f6c634300081c0033

Block Transaction Gas Used Reward
view all blocks ##produced##

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

Validator Index Block Amount
View All Withdrawals

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

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.