ThsSale

Description:

Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/ths-sale/ThsSale.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import {IThsSale} from "./interfaces/IThsSale.sol";
import {ThsSaleStorageLib, Stage, Lockup, Token, ThsSaleStorage} from "./libraries/ThsSaleStorageLib.sol";
import {ACLConsumer} from "../aux/ACLConsumer.sol";

import {IThsToken} from "../ths-token/interfaces/IThsToken.sol";
import {IThsStaking} from "src/ths-staking/interfaces/IThsStaking.sol";
import {IWhitelist} from "./interfaces/IWhitelist.sol";

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract ThsSale is UUPSUpgradeable, ReentrancyGuardUpgradeable, ACLConsumer, IThsSale {
    using SafeERC20 for IERC20;
    using SafeCast for uint256;

    // CONSTANTS & IMMUTABLES

    uint128 public constant USD_DECIMALS = 1e18;

    IThsToken public immutable thsToken;
    IThsStaking public immutable thsStaking;

    // CONSTRUCTOR & INITIALIZER

    constructor(address aclManagerAddress, address thsTokenAddress, address thsStakingAddress)
        ACLConsumer(aclManagerAddress)
    {
        require(thsTokenAddress != address(0), ZeroAddress());
        require(thsStakingAddress != address(0), ZeroAddress());
        _disableInitializers();
        thsToken = IThsToken(thsTokenAddress);
        thsStaking = IThsStaking(thsStakingAddress);
    }

    function initialize(address _treasury, address _whitelist) external initializer {
        require(_treasury != address(0), ZeroAddress());

        __UUPSUpgradeable_init();
        __ReentrancyGuard_init();
        setTreasury(_treasury);
        setWhitelist(_whitelist);
    }

    // USER-EXPOSED FUNCTIONS

    function buy(uint256 stageId, address receiver, address token, uint128 amountIn, bool stakeThs)
        external
        nonReentrant
        returns (uint128 thsAmount)
    {
        require(receiver != address(0), ZeroAddress());
        require(amountIn > 0, ZeroAmount());

        address whitelist = ThsSaleStorageLib.getStorage().whitelist;
        if (whitelist != address(0)) {
            bool isUserWhitelisted = IWhitelist(whitelist).isWhitelisted(receiver);
            require(isUserWhitelisted, AddressNotWhitelisted(receiver));
        }

        thsAmount = _buy(stageId, receiver, token, amountIn, stakeThs, true);
    }

    function claimThs(uint48 lockupId, bool stakeThs) external nonReentrant {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        Lockup memory lockup = s.lockups[lockupId];

        _validateLockup(lockup);

        delete s.lockups[lockupId];

        if (stakeThs) {
            thsToken.transfer(address(thsStaking), lockup.amount);
            thsStaking.stakeAt(msg.sender, lockup.amount, block.timestamp.toUint48());
        } else {
            thsToken.transfer(msg.sender, lockup.amount);
        }

        emit ThsClaimed(msg.sender, lockupId, lockup.amount, stakeThs);
    }

    // OWNER FUNCTIONS

    function buyPrePaidForUser(uint256 stageId, address receiver, address token, uint128 amountIn, bool stakeThs)
        external
        onlyOtcSaleExecutor
        returns (uint128 thsAmount)
    {
        require(receiver != address(0), ZeroAddress());
        require(amountIn > 0, ZeroAmount());
        thsAmount = _buy(stageId, receiver, token, amountIn, stakeThs, false);
    }

    function setStage(uint256 stageId, uint48 startAt, uint48 endAt, uint128 usdPerThs, uint128 maxThsAmount)
        external
        onlySaleOperator
    {
        require(usdPerThs > 0, InvalidUsdPerThs());
        require(maxThsAmount > 0, InvalidMaxThsAmount());
        require(startAt < endAt, InvalidStageTimings());

        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        uint256 stagesLength = s.stages.length;
        require(stageId < stagesLength + 1, InvalidStageId());

        Stage memory newStage = Stage({
            startAt: startAt,
            endAt: endAt,
            usdPerThs: usdPerThs,
            maxThsAmount: maxThsAmount,
            boughtThsAmount: 0
        });

        if (stageId == stagesLength) {
            s.stages.push(newStage);
        } else {
            newStage.boughtThsAmount = s.stages[stageId].boughtThsAmount;
            s.stages[stageId] = newStage;
        }

        emit StageSet(stageId, startAt, endAt, usdPerThs, maxThsAmount);
    }

    function setSlaDuration(uint48 duration) external onlySaleOperator {
        require(duration > 0, InvalidSlaDuration());
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        s.slaDuration = duration;

        emit SlaDurationSet(duration);
    }

    function setWhitelist(address _whitelist) public onlyProtocolAdmin {
        ThsSaleStorageLib.getStorage().whitelist = _whitelist;
        emit WhitelistSet(_whitelist);
    }

    function setToken(address token, uint128 usdPerToken, bool isActive) external onlySaleOperator {
        require(token != address(0), ZeroAddress());
        require(usdPerToken > 0, InvalidUsdPerToken());
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        s.tokensData[token] = Token({isActive: isActive, usdPerToken: usdPerToken});

        emit TokenSet(token, usdPerToken, isActive);
    }

    function setTreasury(address _treasury) public onlyProtocolAdmin {
        require(_treasury != address(0), ZeroAddress());
        ThsSaleStorageLib.getStorage().treasury = _treasury;
    }

    function getLockup(uint48 lockupId) external view returns (Lockup memory) {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        return s.lockups[lockupId];
    }

    function getLockupsByUser(address user) external view returns (Lockup[] memory) {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        uint48 lastLockupId = s.lastLockupId;
        mapping(uint48 => Lockup) storage storageLockups = s.lockups;

        uint48 userLockupsCount = 0;

        for (uint48 i = 0; i < lastLockupId + 1; i++) {
            if (storageLockups[i].user == user) {
                userLockupsCount++;
            }
        }

        Lockup[] memory userLockups = new Lockup[](userLockupsCount);

        uint48 currentIndex = 0;
        for (uint48 i = 0; i < lastLockupId + 1; i++) {
            if (storageLockups[i].user == user) {
                userLockups[currentIndex] = storageLockups[i];
                currentIndex++;
            }
        }

        return userLockups;
    }

    function getStage(uint256 stageId) external view returns (Stage memory) {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        return s.stages[stageId];
    }

    function getTokenData(address token) external view returns (Token memory) {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        return s.tokensData[token];
    }

    function calculateThsAmount(uint256 stageId, address paymentToken, uint128 amountIn)
        external
        view
        returns (uint128 thsAmount)
    {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        Stage memory stage = s.stages[stageId];
        Token memory tokenData = s.tokensData[paymentToken];

        return _calculateThsAmount(tokenData.usdPerToken, stage.usdPerThs, amountIn);
    }

    function getSlaDuration() external view returns (uint48) {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        return s.slaDuration;
    }

    // INTERNAL FUNCTIONS

    function _buy(
        uint256 stageId,
        address receiver,
        address paymentToken,
        uint128 amountIn,
        bool stakeThs,
        bool shouldTransferToken
    ) internal returns (uint128 thsAmount) {
        ThsSaleStorage storage s = ThsSaleStorageLib.getStorage();
        Stage memory stage = s.stages[stageId];
        Token memory tokenData = s.tokensData[paymentToken];
        address treasury = s.treasury;

        thsAmount = _calculateThsAmount(tokenData.usdPerToken, stage.usdPerThs, amountIn);

        _validateBuyData(stage, tokenData, thsAmount);

        if (shouldTransferToken) {
            IERC20(paymentToken).safeTransferFrom(msg.sender, treasury, amountIn);
        }

        uint48 slaDuration = s.slaDuration;

        uint48 lockupId = 0;

        if (stakeThs) {
            _stakeOnBuy(receiver, thsAmount, slaDuration);
        } else {
            lockupId = _lockUp(s, receiver, thsAmount, slaDuration);
        }

        s.stages[stageId].boughtThsAmount = stage.boughtThsAmount + thsAmount;

        emit ThsBought(
            receiver,
            stageId,
            lockupId,
            paymentToken,
            amountIn,
            thsAmount,
            stakeThs,
            uint48(block.timestamp) + slaDuration
        );
    }

    function _stakeOnBuy(address receiver, uint128 thsAmount, uint48 slaDuration) internal {
        uint48 stakeStartAt = block.timestamp.toUint48() + slaDuration;

        thsToken.mint(address(thsStaking), thsAmount);
        thsStaking.stakeAt(receiver, thsAmount, stakeStartAt);
    }

    function _lockUp(ThsSaleStorage storage s, address receiver, uint128 thsAmount, uint48 slaDuration)
        internal
        returns (uint48 lockupId)
    {
        lockupId = ++s.lastLockupId;
        uint48 unlockAt = block.timestamp.toUint48() + slaDuration;

        thsToken.mint(address(this), thsAmount);

        s.lockups[lockupId] = Lockup({user: receiver, amount: thsAmount, unlockAt: unlockAt});

        emit ThsLocked(receiver, lockupId, thsAmount, unlockAt);
    }

    function _validateBuyData(Stage memory stage, Token memory tokenData, uint128 thsAmount) internal view {
        require(tokenData.isActive, InactiveToken());

        require(thsAmount > 0, ZeroAmount());

        require((stage.boughtThsAmount + thsAmount <= stage.maxThsAmount), StageMaxThsAmountExceeded());

        require(stage.startAt <= block.timestamp, StageNotStarted());
        require(stage.endAt > block.timestamp, StageEnded());
    }

    function _validateLockup(Lockup memory lockup) internal view {
        require(lockup.user == msg.sender, LockupNotFound());

        require(block.timestamp >= lockup.unlockAt, LockupNotUnlocked());
    }

    function _calculateThsAmount(uint128 usdPerToken, uint128 usdPerThs, uint128 tokenAmount)
        internal
        pure
        returns (uint128 thsAmount)
    {
        uint256 usdAmount = uint256(tokenAmount) * usdPerToken;
        thsAmount = Math.mulDiv(usdAmount, USD_DECIMALS, usdPerThs).toUint128();
    }

    // UUPS UPGRADE

    function _authorizeUpgrade(address newImplementation) internal override onlyProtocolAdmin {}
}
"
    },
    "src/ths-sale/interfaces/IThsSale.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

import {IThsSaleErrors} from "./IThsSaleErrors.sol";
import {IThsSaleEvents} from "./IThsSaleEvents.sol";
import {Lockup, Stage, Token} from "../libraries/ThsSaleStorageLib.sol";

interface IThsSale is IThsSaleErrors, IThsSaleEvents {
    function buy(uint256 stageId, address receiver, address paymentToken, uint128 amountIn, bool stakeThs)
        external
        returns (uint128 thsAmount);

    function claimThs(uint48 lockupId, bool stakeThs) external;

    function buyPrePaidForUser(uint256 stageId, address receiver, address paymentToken, uint128 amountIn, bool stakeThs)
        external
        returns (uint128 thsAmount);

    function setStage(uint256 stageId, uint48 startAt, uint48 endAt, uint128 usdPerThs, uint128 maxThsAmount)
        external;

    function setSlaDuration(uint48 duration) external;

    function setToken(address token, uint128 tokenPerThs, bool isActive) external;

    function setTreasury(address _treasury) external;

    function getLockup(uint48 lockupId) external view returns (Lockup memory);

    function getLockupsByUser(address user) external view returns (Lockup[] memory);

    function getStage(uint256 stageId) external view returns (Stage memory);

    function getTokenData(address token) external view returns (Token memory);

    function calculateThsAmount(uint256 stageId, address paymentToken, uint128 amountIn)
        external
        view
        returns (uint128 thsAmount);

    function getSlaDuration() external view returns (uint48);
}
"
    },
    "src/ths-sale/libraries/ThsSaleStorageLib.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

struct Stage {
    uint64 startAt;
    uint64 endAt;
    uint128 usdPerThs;
    uint128 maxThsAmount;
    uint128 boughtThsAmount;
}

struct Lockup {
    address user;
    uint128 amount;
    uint48 unlockAt;
}

struct Token {
    bool isActive;
    uint128 usdPerToken; // 18 decimals by default
}

struct ThsSaleStorage {
    address treasury;
    uint48 slaDuration;
    uint48 lastLockupId;
    Stage[] stages;
    mapping(address => Token) tokensData;
    mapping(uint48 => Lockup) lockups;
    address whitelist;
}

library ThsSaleStorageLib {
    bytes32 private constant THS_SALE_STORAGE_POSITION = bytes32(uint256(keccak256("ths-sale.storage")) - 1);

    function getStorage() internal pure returns (ThsSaleStorage storage s) {
        bytes32 position = THS_SALE_STORAGE_POSITION;
        assembly {
            s.slot := position
        }
    }
}
"
    },
    "src/aux/ACLConsumer.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import {IACLManager} from "./interfaces/IACLManager.sol";
import {ICommonErrors} from "../common/interfaces/ICommonErrors.sol";
import {ACLRoles} from "./lib/ACLRoles.sol";

abstract contract ACLConsumer is ICommonErrors {
    // IMMUTABLES

    IACLManager public immutable aclManager;

    // MODIFIERS

    modifier onlyProtocolAdmin() {
        aclManager.checkRole(ACLRoles.PROTOCOL_ADMIN_ROLE, msg.sender);
        _;
    }

    modifier onlyWhitelistOperator() {
        aclManager.checkRole(ACLRoles.WHITELIST_OPERATOR_ROLE, msg.sender);
        _;
    }

    modifier onlySaleOperator() {
        aclManager.checkRole(ACLRoles.SALE_OPERATOR_ROLE, msg.sender);
        _;
    }

    modifier onlyOtcSaleExecutor() {
        aclManager.checkRole(ACLRoles.OTC_SALE_EXECUTOR_ROLE, msg.sender);
        _;
    }

    modifier onlyRewardsDistributor() {
        aclManager.checkRole(ACLRoles.REWARDS_DISTRIBUTOR_ROLE, msg.sender);
        _;
    }

    // CONSTRUCTOR

    constructor(address aclManagerAddress) {
        require(aclManagerAddress != address(0), ZeroAddress());
        aclManager = IACLManager(aclManagerAddress);
    }
}
"
    },
    "src/ths-token/interfaces/IThsToken.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {IERC1363} from "@openzeppelin/contracts/interfaces/IERC1363.sol";
import {IThsTokenErrors} from "./IThsTokenErrors.sol";
import {IThsTokenEvents} from "./IThsTokenEvents.sol";

/**
 * @title THS Token Interface
 * @notice Interface for the THS token contract with ERC20, ERC20Permit, and ERC1363 functionality
 * @dev Extends standard token interfaces with minting, burning, and access control features
 */
interface IThsToken is IERC20, IERC20Permit, IERC1363, IThsTokenErrors, IThsTokenEvents {
    /**
     * @notice Checks if an address is authorized to mint tokens
     * @dev Verifies whether the specified address has minting permissions
     * @param user The address to check minting permissions for
     * @return True if the address is allowed to mint, false otherwise
     */
    function isAllowedMinter(address user) external view returns (bool);

    /**
     * @notice Mints new tokens to a specified address (authorized minters only)
     * @dev Creates new tokens and assigns them to the recipient
     * @param to The address that will receive the minted tokens
     * @param amount The amount of tokens to mint
     */
    function mint(address to, uint256 amount) external;

    /**
     * @notice Burns tokens from the caller's balance
     * @dev Destroys tokens from the caller's account, reducing total supply
     * @param amount The amount of tokens to burn
     */
    function burn(uint256 amount) external;

    /**
     * @notice Sets minting permissions for an address (admin function)
     * @dev Grants or revokes minting authorization for the specified address
     * @param user The address to modify minting permissions for
     * @param allowed Whether to grant or revoke minting permissions
     */
    function setAllowedMinter(address user, bool allowed) external;

    /**
     * @notice Sets burning permissions for an address (admin function)
     * @dev Grants or revokes burning authorization for the specified address
     * @param user The address to modify burning permissions for
     * @param allowed Whether to grant or revoke burning permissions
     */
    function setAllowedBurner(address user, bool allowed) external;

    /**
     * @notice Unpauses the token contract (admin function)
     * @dev Resumes all token operations after being paused
     */
    function unpause() external;
}
"
    },
    "src/ths-staking/interfaces/IThsStaking.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import {IThsStakingEvents} from "./IThsStakingEvents.sol";
import {IThsStakingErrors} from "./IThsStakingErrors.sol";

interface IThsStaking is IThsStakingEvents, IThsStakingErrors {
    function setTiersManager(address newTiersManagerAddress) external;
    function depositDailyRewards(uint256 totalWbtc) external;
    function stake(uint128 amount) external;
    function stakeAt(address user, uint128 amount, uint48 startAt) external;
    function unstake(uint8[] calldata tierIds, uint64[][] calldata stakeIds) external;
    function claimRewards(uint8[] calldata tierIds) external;
    function restake(uint8 tierId, uint64 stakeId) external;
    function getTiersManager() external view returns (address);
    function getLastRewardEpoch() external view returns (uint48);
    function getThsSale() external view returns (address);
    function setThsSale(address newThsSaleAddress) external;
}
"
    },
    "src/ths-sale/interfaces/IWhitelist.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

import {IWhitelistErrors} from "./IWhitelistErrors.sol";
import {IWhitelistEvents} from "./IWhitelistEvents.sol";

interface IWhitelist is IWhitelistErrors, IWhitelistEvents {
    function addToWhitelist(address _address) external;
    function addToWhitelistBatch(address[] calldata _addresses) external;

    function removeFromWhitelist(address _address) external;
    function removeFromWhitelistBatch(address[] calldata _addresses) external;

    function isWhitelisted(address _address) external view returns (bool);
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.22;

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

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

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

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

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

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

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

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

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

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

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

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

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

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC-1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

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

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

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

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

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

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

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

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._status = NOT_ENTERED;
    }

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

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol": {
      "content": "// 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 int

Tags:
ERC20, ERC165, Proxy, Mintable, Burnable, Upgradeable, Factory|addr:0x0133283f2e269b5555b13434f73279b36f05c466|verified:true|block:23450043|tx:0xf64e1ad3567e05d6c3b447c9749dfabd1d7ff3a5fb08e41879d927243e9b3e8d|first_check:1758963414

Submitted on: 2025-09-27 10:56:55

Comments

Log in to comment.

No comments yet.