Skip to content
Verified contractPartialAGPL

TTUDeployerLite

Address0xce6748ae60d5c070d05ffd44e9933aa49df78a61
Balance

0 ETH

 

Transactions

10

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
License
AGPL
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
22,340,154
Creation transaction
0x790921086e…971a684641

contracts/proxy/TTUDeployerLite.sol

// SPDX-License-Identifier: AGPL v3
pragma solidity ^0.8.28;

import {ITTUDeployer} from "../interfaces/ITTUDeployer.sol";
import {TTUV2BeaconManager} from "./TTUV2BeaconManager.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ITokenTableUnlockerV2} from "../interfaces/ITokenTableUnlockerV2.sol";
import {ITTFutureTokenV2} from "../interfaces/ITTFutureTokenV2.sol";
import {ITTTrackerTokenV2} from "../interfaces/ITTTrackerTokenV2.sol";
import {ITTUFeeCollector} from "../interfaces/ITTUFeeCollector.sol";
import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IVersionable} from "../interfaces/IVersionable.sol";

// solhint-disable custom-errors
contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
    TTUV2BeaconManager public beaconManager;
    ITTUFeeCollector public override feeCollector;
    mapping(string projectId => address unlocker) public registry;
    mapping(address unlocker => bool approved) public emergencyWithdrawApprovals;
    mapping(address unlocker => bool approved) internal _emergencyWithdrawRequests;
    mapping(address unlocker => bool exists) internal _unlockers;

    modifier onlyUnlocker() {
        require(_unlockers[_msgSender()], Unauthorized());
        _;
    }

    constructor() Ownable(_msgSender()) {}

    function setBeaconManager(TTUV2BeaconManager _beaconManager) external onlyOwner {
        beaconManager = _beaconManager;
    }

    function setFeeCollector(ITTUFeeCollector feeCollector_) external onlyOwner {
        feeCollector = feeCollector_;
        emit FeeCollectorChanged(address(feeCollector));
    }

    function setEmergencyWithdrawRequestStatus(bool status) external onlyUnlocker {
        _emergencyWithdrawRequests[_msgSender()] = status;
        if (!status) emergencyWithdrawApprovals[_msgSender()] = false;
    }

    function handleEmergencyWithdrawRequest(address unlocker, bool approve) external onlyOwner {
        require(_emergencyWithdrawRequests[unlocker], MissingRequest());
        emergencyWithdrawApprovals[unlocker] = approve;
    }

    function consumeEmergencyWithdrawRequest() external onlyUnlocker returns (bool approved) {
        approved = emergencyWithdrawApprovals[_msgSender()];
        emergencyWithdrawApprovals[_msgSender()] = false;
        _emergencyWithdrawRequests[_msgSender()] = false;
    }

    function deployTTSuite(
        address projectToken,
        address existingFutureToken,
        string memory projectId,
        bool isUpgradeable,
        bool isTransferable,
        bool isCancelable,
        bool isHookable,
        bool isWithdrawable
    ) external returns (ITokenTableUnlockerV2, ITTFutureTokenV2) {
        if (registry[projectId] != address(0)) revert AlreadyDeployed();

        ITTFutureTokenV2 futureToken;
        ITokenTableUnlockerV2 unlocker;
        ITTTrackerTokenV2 trackerToken;
        if (!isUpgradeable) {
            (unlocker, futureToken, trackerToken) = _deployClonesAndInitialize(
                projectToken, existingFutureToken, isTransferable, isCancelable, isHookable, isWithdrawable
            );
        } else {
            if (existingFutureToken == address(0)) {
                futureToken = ITTFutureTokenV2(
                    address(
                        new BeaconProxy(
                            address(beaconManager.beacons("TTFutureTokenV2")),
                            abi.encodeWithSelector(ITTFutureTokenV2.initialize.selector, projectToken, isTransferable)
                        )
                    )
                );
                unlocker = ITokenTableUnlockerV2(
                    address(
                        new BeaconProxy(
                            address(beaconManager.beacons("TokenTableUnlockerV2")),
                            abi.encodeWithSelector(
                                ITokenTableUnlockerV2.initialize.selector,
                                projectToken,
                                address(futureToken),
                                this,
                                isCancelable,
                                isHookable,
                                isWithdrawable,
                                true
                            )
                        )
                    )
                );
                futureToken.setAuthorizedMinterSingleUse(address(unlocker));
            } else {
                unlocker = ITokenTableUnlockerV2(
                    address(
                        new BeaconProxy(
                            address(beaconManager.beacons("TTUV2ExternalFT")),
                            abi.encodeWithSelector(
                                ITokenTableUnlockerV2.initialize.selector,
                                projectToken,
                                existingFutureToken,
                                this,
                                isCancelable,
                                isHookable,
                                isWithdrawable,
                                true
                            )
                        )
                    )
                );
                futureToken = ITTFutureTokenV2(existingFutureToken);
            }
            trackerToken = ITTTrackerTokenV2(
                address(
                    new BeaconProxy(
                        address(beaconManager.beacons("TTTrackerTokenV2")),
                        abi.encodeWithSelector(ITTTrackerTokenV2.initialize.selector, address(unlocker))
                    )
                )
            );
        }
        unlocker.transferOwnership(msg.sender);
        emit TokenTableSuiteDeployed(
            msg.sender, projectId, address(unlocker), address(futureToken), address(trackerToken)
        );
        registry[projectId] = address(unlocker);
        _unlockers[address(unlocker)] = true;
        return (unlocker, futureToken);
    }

    function version() public pure virtual returns (string memory) {
        return "2.7.0";
    }

    function _deployClonesAndInitialize(
        address projectToken,
        address existingFutureToken,
        bool isTransferable,
        bool isCancelable,
        bool isHookable,
        bool isWithdrawable
    )
        internal
        virtual
        returns (ITokenTableUnlockerV2 unlocker, ITTFutureTokenV2 futureToken, ITTTrackerTokenV2 trackerToken)
    {
        if (existingFutureToken == address(0)) {
            futureToken = ITTFutureTokenV2(Clones.clone(beaconManager.beacons("TTFutureTokenV2").implementation()));
            futureToken.initialize(projectToken, isTransferable);
            unlocker =
                ITokenTableUnlockerV2(Clones.clone(beaconManager.beacons("TokenTableUnlockerV2").implementation()));
        } else {
            futureToken = ITTFutureTokenV2(existingFutureToken);
            unlocker = ITokenTableUnlockerV2(Clones.clone(beaconManager.beacons("TTUV2ExternalFT").implementation()));
        }

        unlocker.initialize(projectToken, address(futureToken), address(this), isCancelable, isHookable, isWithdrawable);
        trackerToken = ITTTrackerTokenV2(Clones.clone(beaconManager.beacons("TTTrackerTokenV2").implementation()));
        trackerToken.initialize(address(unlocker));
        if (existingFutureToken == address(0)) {
            futureToken.setAuthorizedMinterSingleUse(address(unlocker));
        }
    }
}

@openzeppelin/contracts/access/Ownable.sol

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/proxy/Clones.sol

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

pragma solidity ^0.8.20;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 */
library Clones {
    /**
     * @dev A clone instance deployment failed.
     */
    error ERC1167FailedCreateClone();

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create(0, 0x09, 0x37)
        }
        if (instance == address(0)) {
            revert ERC1167FailedCreateClone();
        }
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create2(0, 0x09, 0x37, salt)
        }
        if (instance == address(0)) {
            revert ERC1167FailedCreateClone();
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(add(ptr, 0x38), deployer)
            mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
            mstore(add(ptr, 0x14), implementation)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
            mstore(add(ptr, 0x58), salt)
            mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
            predicted := keccak256(add(ptr, 0x43), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt
    ) internal view returns (address predicted) {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

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

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

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

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

@openzeppelin/contracts/proxy/Proxy.sol

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

pragma solidity ^0.8.20;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @dev This is a virtual function that should be overridden so it returns the address to which the fallback
     * function and {_fallback} should delegate.
     */
    function _implementation() internal view virtual returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback() external payable virtual {
        _fallback();
    }
}

@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/BeaconProxy.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "./IBeacon.sol";
import {Proxy} from "../Proxy.sol";
import {ERC1967Utils} from "../ERC1967/ERC1967Utils.sol";

/**
 * @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
 *
 * The beacon address can only be set once during construction, and cannot be changed afterwards. It is stored in an
 * immutable variable to avoid unnecessary storage reads, and also in the beacon storage slot specified by
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] so that it can be accessed externally.
 *
 * CAUTION: Since the beacon address can never be changed, you must ensure that you either control the beacon, or trust
 * the beacon to not upgrade the implementation maliciously.
 *
 * IMPORTANT: Do not use the implementation logic to modify the beacon storage slot. Doing so would leave the proxy in
 * an inconsistent state where the beacon storage slot does not match the beacon address.
 */
contract BeaconProxy is Proxy {
    // An immutable address for the beacon to avoid unnecessary SLOADs before each delegate call.
    address private immutable _beacon;

    /**
     * @dev Initializes the proxy with `beacon`.
     *
     * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
     * will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
     * constructor.
     *
     * Requirements:
     *
     * - `beacon` must be a contract with the interface {IBeacon}.
     * - If `data` is empty, `msg.value` must be zero.
     */
    constructor(address beacon, bytes memory data) payable {
        ERC1967Utils.upgradeBeaconToAndCall(beacon, data);
        _beacon = beacon;
    }

    /**
     * @dev Returns the current implementation address of the associated beacon.
     */
    function _implementation() internal view virtual override returns (address) {
        return IBeacon(_getBeacon()).implementation();
    }

    /**
     * @dev Returns the beacon.
     */
    function _getBeacon() internal view virtual returns (address) {
        return _beacon;
    }
}

@openzeppelin/contracts/proxy/beacon/IBeacon.sol

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

pragma solidity ^0.8.20;

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

@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/UpgradeableBeacon.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "./IBeacon.sol";
import {Ownable} from "../../access/Ownable.sol";

/**
 * @dev This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their
 * implementation contract, which is where they will delegate all function calls.
 *
 * An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon.
 */
contract UpgradeableBeacon is IBeacon, Ownable {
    address private _implementation;

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

    /**
     * @dev Emitted when the implementation returned by the beacon is changed.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Sets the address of the initial implementation, and the initial owner who can upgrade the beacon.
     */
    constructor(address implementation_, address initialOwner) Ownable(initialOwner) {
        _setImplementation(implementation_);
    }

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

    /**
     * @dev Upgrades the beacon to a new implementation.
     *
     * Emits an {Upgraded} event.
     *
     * Requirements:
     *
     * - msg.sender must be the owner of the contract.
     * - `newImplementation` must be a contract.
     */
    function upgradeTo(address newImplementation) public virtual onlyOwner {
        _setImplementation(newImplementation);
    }

    /**
     * @dev Sets the implementation contract address for this beacon
     *
     * Requirements:
     *
     * - `newImplementation` must be a contract.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert BeaconInvalidImplementation(newImplementation);
        }
        _implementation = newImplementation;
        emit Upgraded(newImplementation);
    }
}

@openzeppelin/contracts/utils/Address.sol

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/Context.sol

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

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

@openzeppelin/contracts/utils/StorageSlot.sol

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

pragma solidity ^0.8.20;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

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

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

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

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

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

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

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

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

contracts/interfaces/IOwnable.sol

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

interface IOwnable {
    function renounceOwnership() external;

    function transferOwnership(address newOwner) external;

    function owner() external view returns (address);
}

contracts/interfaces/ITTFutureTokenV2.sol

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

import {IERC721AQueryableUpgradeable} from "erc721a-upgradeable/contracts/interfaces/IERC721AQueryableUpgradeable.sol";
import {IVersionable} from "./IVersionable.sol";

/**
 * @title ITTFutureTokenV2
 * @author Jack Xu @ EthSign
 * @dev The lightweight interface for TTFutureTokenV2(.5.x), which handles unlocking schedule ownership for TokenTable.
 */
interface ITTFutureTokenV2 is IERC721AQueryableUpgradeable, IVersionable {
    event DidSetBaseURI(string newURI);

    /**
     * @dev 0x7f63bd0f
     */
    error NotPermissioned();

    /**
     * @dev This contract should be deployed with `TTUDeployerLite`, which calls this function with the correct parameters.
     * @param projectToken The address of the token that the founder intends to unlock and distribute.
     * @param isTransferable If the FutureTokens (aka schedules) can be transfered once minted.
     */
    function initialize(address projectToken, bool isTransferable) external;

    /**
     * @notice This contract should be deployed with `TTUDeployerLite`, which calls this function with the correct parameters.
     * @dev This function can only be called once.
     * @param authorizedMinter_ The address which is authorized to mint new FutureTokens. This is set to the corresponding Unlocker in the deployer.
     */
    function setAuthorizedMinterSingleUse(address authorizedMinter_) external;

    /**
     * @notice Safely mints a new FutureToken to the specified address.
     * @dev This function can only be called by the authorized minter.
     * @param to The recipient of the new FutureToken.
     * @return tokenId The minted token ID (aka actual ID or schedule ID).
     */
    function safeMint(address to) external returns (uint256 tokenId);

    /**
     * @notice Updates the base URI.
     * @dev This function can only be called by the owner of the authorized minter, which is usually the founder.
     * @param uri The new base URI.
     */
    function setURI(string calldata uri) external;

    /**
     * @notice Gets information regarding the unlocking schedule associated with this FutureToken.
     * @param tokenId The actual ID or schedule ID.
     * @return deltaAmountClaimable The amount of unlocked and unclaimed funds currently eligible to be claimed by the owner of the given ID.
     * @return amountAlreadyClaimed The amount of unlocked and claimed funds of the given ID.
     * @return isCancelable If the schedule associated with this ID can be canceled by the founder.
     */
    function getClaimInfo(uint256 tokenId)
        external
        view
        returns (uint256 deltaAmountClaimable, uint256 amountAlreadyClaimed, bool isCancelable);
}

contracts/interfaces/ITTHook.sol

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

/**
 * @title ITTHook
 * @author Jack Xu @ EthSign
 */
interface ITTHook {
    /**
     * @notice Forwards the call context from the hooked contract.
     * @dev Reverts within hooks will revert the hooked contract as well.
     * @param originalMsgData Forwarded calldata from the called function.
     * @param originalMsgSender Forwarded sender from the called function.
     */
    function didCall(bytes calldata originalMsgData, address originalMsgSender) external;
}

contracts/interfaces/ITTTrackerTokenV2.sol

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

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

interface ITTTrackerTokenV2 is IVersionable {
    /**
     * @dev This contract should be deployed with `TTUDeployerLite`, which calls this function with the correct parameters.
     * @param ttuInstance_ The address of the corresponding Unlocker.
     */
    function initialize(address ttuInstance_) external;
}

contracts/interfaces/ITTUDeployer.sol

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

import {ITokenTableUnlockerV2} from "./ITokenTableUnlockerV2.sol";
import {ITTFutureTokenV2} from "./ITTFutureTokenV2.sol";
import {ITTUFeeCollector} from "./ITTUFeeCollector.sol";

/**
 * @title TTUDeployer
 * @author Jack Xu @ EthSign
 * @dev This is the deployer for all TokenTable core and proxy contracts. All initial setup and configuration is automatically done here.
 * To save gas and enable easy upgradeability, all deployed contracts are `Clone` or `BeaconProxy` instances.
 * You should avoid deploying TokenTable contracts individually unless you know what you're doing.
 */
interface ITTUDeployer {
    event TTUDeployerInitialized(
        address unlockerImpl,
        address futureTokenImpl,
        address trackerTokenImpl,
        address beaconManagerImpl,
        address feeCollector
    );
    event TokenTableSuiteDeployed(
        address by, string projectId, address unlocker, address futureToken, address trackerToken
    );
    event FeeCollectorChanged(address feeCollector);

    /**
     * @dev 0xa6ef0ba1
     */
    error AlreadyDeployed();

    /**
     * @dev 0x82b42900
     */
    error Unauthorized();

    /**
     * @dev 0xad78f5dc
     */
    error MissingRequest();

    /**
     * @notice Exposes the fee collector variable.
     * @return An instance of the fee collector.
     */
    function feeCollector() external returns (ITTUFeeCollector);

    /**
     * @notice This function is called when an unlocker wants to initiate or cancel an emergency withdraw request.
     * @dev Only callable by a deployed unlocker.
     */
    function setEmergencyWithdrawRequestStatus(bool status) external;

    /**
     * @notice This function resets the approval to false while returning the current status.
     * @dev Only callable by a deployed unlocker.
     * @return approved If the withdraw request was approved.
     */
    function consumeEmergencyWithdrawRequest() external returns (bool approved);

    /**
     * @notice Deploys and configures a new set of TokenTable products that uses an existing NFT as FutureToken.
     * @dev Emits `TokenTableSuiteDeployed`. Throws: `AlreadyDeployed`.
     * @param projectToken The project token address.
     * @param projectId A unique projectId, otherwise it will revert.
     * @param isUpgradeable When set to false, a `Clone` instead of a `BeaconProxy` is created to prevent future upgradeability.
     * @param isTransferable Allow FutureToken to be transferable. Ignored if an existing FutureToken is supplied.
     * @param isCancelable Allow unlocking schedules to be cancelled in the Unlocker.
     * @param isHookable Allow Unlocker to call an external hook.
     * @param isWithdrawable Allow the founder to withdraw deposited funds.
     */
    function deployTTSuite(
        address projectToken,
        address existingFutureToken,
        string memory projectId,
        bool isUpgradeable,
        bool isTransferable,
        bool isCancelable,
        bool isHookable,
        bool isWithdrawable
    ) external returns (ITokenTableUnlockerV2, ITTFutureTokenV2);

    /**
     * @notice Allows external parties to query if an emergency withdraw request is approved.
     * @return If the withdraw request is approved.
     */
    function emergencyWithdrawApprovals(address unlocker) external view returns (bool);
}

contracts/interfaces/ITTUFeeCollector.sol

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

import {IOwnable} from "./IOwnable.sol";
import {IVersionable} from "./IVersionable.sol";

/**
 * @title ITTUFeeCollector
 * @author Jack Xu @ EthSign
 * @dev This contract handles TokenTable service fee calculation.
 */
interface ITTUFeeCollector is IOwnable, IVersionable {
    event DefaultFeeSetBips(uint256 bips);
    event DefaultFeeSet(uint256 fee);
    event CustomFeeSetBips(address unlockerAddress, uint256 bips);
    event CustomFeeSetFixed(address unlockerAddress, uint256 fixedFee);

    /**
     * @dev 0xc9034e18
     */
    error FeesTooHigh();

    /**
     * @notice Returns the amount of fees to collect. A fixed fee will always override a dynamic fee.
     * @param unlockerAddress The address of the Unlocker (or any contract that uses the fee collector). Used to fetch pricing.
     * @param tokenTransferred The number of tokens transferred.
     * @return tokensCollected The number of tokens to collect as fees.
     */
    function getFee(address unlockerAddress, uint256 tokenTransferred)
        external
        view
        returns (uint256 tokensCollected);

    /**
     * @notice Returns the fee token address.
     * @param unlockerAddress The address of the Unlocker (or any contract that uses the fee collector). Used to fetch pricing.
     */
    function getFeeToken(address unlockerAddress) external view returns (address tokenAddress);
}

contracts/interfaces/ITokenTableUnlockerV2.sol

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

import {IOwnable} from "./IOwnable.sol";
import {IVersionable} from "./IVersionable.sol";
import {Preset, Actual} from "./TokenTableUnlockerV2DataModels.sol";
import {ITTHook} from "./ITTHook.sol";
import {ITTUDeployer} from "./ITTUDeployer.sol";
import {ITTFutureTokenV2} from "./ITTFutureTokenV2.sol";

/**
 * @title ITokenTableUnlockerV2
 * @author Jack Xu @ EthSign
 * @dev The lightweight interface for TokenTableUnlockerV2(.5.x), which handles token unlocking and distribution for TokenTable.
 */
abstract contract ITokenTableUnlockerV2 is IOwnable, IVersionable {
    event PresetCreated(bytes32 presetId, uint256 batchId);
    event ActualCreated(bytes32 presetId, uint256 actualId, address recipient, uint256 recipientId, uint256 batchId);
    event ActualCancelled(
        uint256 actualId, uint256 pendingAmountClaimable, bool didWipeClaimableBalance, uint256 batchId
    );
    event TokensClaimed(
        uint256 actualId, address caller, address to, uint256 amount, uint256 feesCharged, uint256 batchId
    );
    event TokensWithdrawn(address by, uint256 amount);
    event ClaimingDelegateSet(address delegate, bool status);
    event CreateDisabled();
    event CancelDisabled();
    event HookDisabled();
    event WithdrawDisabled();

    /**
     * @dev 0x0ef8e8dc
     */
    error InvalidPresetFormat();
    /**
     * @dev 0x7cbb15b4
     */
    error PresetExists();
    /**
     * @dev 0xbd88ff7b
     */
    error PresetDoesNotExist();
    /**
     * @dev 0x06aed316
     */
    error ActualDoesNotExist();
    /**
     * @dev 0x78c0fc43
     */
    error InvalidSkipAmount();
    /**
     * @dev 0x7f63bd0f
     */
    error NotPermissioned();
    /**
     * @dev 0x2fac9032
     */
    error AlreadyWithdrawable();

    /**
     * @dev This contract should be deployed with `TTUDeployerLite`, which calls this function with the correct parameters.
     * @param projectToken The address of the token that the founder intends to unlock and distribute.
     * @param futureToken_ The address of the associated FutureToken.
     * @param deployer_ The address of the deployer. It helps call the fee collector during claim.
     * @param isCancelable_ If the founder is allowed to cancel schedules. Can be disabled later, but cannot be enabled again.
     * @param isHookable_ If the founder is allowed to attach external hooks to function calls. Can be disabled later, but cannot be enabled again.
     * @param isWithdrawable_ If the founder is allowed to withdraw deposited tokens. Can be disabled later, but cannot be enabled again.
     */
    function initialize(
        address projectToken,
        address futureToken_,
        address deployer_,
        bool isCancelable_,
        bool isHookable_,
        bool isWithdrawable_
    ) external virtual;

    /**
     * @notice Creates an unlocking schedule preset template.
     * @dev Emits `PresetCreated`. Only callable by the owner.
     * @param presetIds These IDs can be the hashes of a plaintext preset names but really there is no restriction. Will revert if they already exist.
     * @param presets An array of `Preset` structs.
     * @param batchId Emitted as an event reserved for EthSign frontend use. This parameter has no effect on contract execution.
     * @param extraData An ERC-5750 parameter that's passed to the hook directly.
     */
    function createPresets(
        bytes32[] calldata presetIds,
        Preset[] calldata presets,
        uint256 batchId,
        bytes calldata extraData
    ) external virtual;

    /**
     * @notice Creates an actual unlocking schedule based on a preset.
     * @dev Emits `ActualCreated`. A FutureToken is minted in the process with `tokenId == actualId`.
     * @param recipients An array of token recipients for the schedules. Note that claiming eligibility can be modified by transfering the corresponding FutureToken.
     * @param actuals An array of `Actual` structs.
     * @param recipientIds Emitted as an event reserved for EthSign frontend use. This parameter has no effect on contract execution.
     * @param batchId Emitted as an event reserved for EthSign frontend use. This parameter has no effect on contract execution.
     * @param extraData An ERC-5750 parameter that's passed to the hook directly.
     */
    function createActuals(
        address[] calldata recipients,
        Actual[] calldata actuals,
        uint256[] calldata recipientIds,
        uint256 batchId,
        bytes calldata extraData
    ) external virtual;

    /**
     * @notice Withdraws existing deposit from the contract.
     * @dev Emits `TokensWithdrawn`. Only callable by the owner.
     * @param amount Amount of deposited funds the founder wishes to withdraw.
     * @param extraData An ERC-5750 parameter that's passed to the hook directly.
     */
    function withdrawDeposit(uint256 amount, bytes calldata extraData) external virtual;

    /**
     * @notice Claims claimable tokens for the specified schedules to the specified addresses respectively.
     * @dev Emits `TokensClaimed`. Only callable by the FutureToken owner.
     * @param actualIds The IDs of the unlocking schedules that we are trying to claim from.
     * @param claimTos If we want to send the claimed tokens to an address other than the caller. To send the claimed tokens to the caller (default behavior), pass in `ethers.constants.AddressZero`.
     * @param batchId Emitted as an event reserved for EthSign frontend use. This parameter has no effect on contract execution.
     * @param extraData An ERC-5750 parameter that's passed to the hook directly.
     */
    function claim(uint256[] calldata actualIds, address[] calldata claimTos, uint256 batchId, bytes calldata extraData)
        external
        virtual;

    /**
     * @notice Claims claimable tokens for the specified schedules on behalf of recipients. Claimed tokens are sent to the schedule recipients.
     * @dev Emits `TokensClaimed`. Only callable by the claiming delegate.
     * @param actualIds The IDs of the unlocking schedules that we are trying to claim from on behalf of the recipients.
     * @param batchId Emitted as an event reserved for EthSign frontend use. This parameter has no effect on contract execution.
     * @param extraData An ERC-5750 parameter that's passed to the hook directly.
     */
    function delegateClaim(uint256[] calldata actualIds, uint256 batchId, bytes calldata extraData) external virtual;

    /**
     * @notice Cancels an array of unlocking schedules effective immediately. Tokens not yet claimed but are already unlocked will be tallied.
     * @dev Emits `ActualCancelled`. Only callable by the owner.
     * @param actualIds The ID of the actual unlocking schedule that we want to cancel.
     * @param shouldWipeClaimableBalance If the unlocked and claimable balance of the canceled schedule should be wiped. This is usually used to delete an erroneously created schedule that has already started unlocking.
     * @param batchId Emitted as an event reserved for EthSign frontend use. This parameter has no effect on contract execution.
     * @param extraData An ERC-5750 parameter that's passed to the hook directly.
     * @return pendingAmountClaimables Number of tokens eligible to be claimed by the affected stakeholders at the moment of cancellation.
     */
    function cancel(
        uint256[] calldata actualIds,
        bool[] calldata shouldWipeClaimableBalance,
        uint256 batchId,
        bytes calldata extraData
    ) external virtual returns (uint256[] memory pendingAmountClaimables);

    /**
     * @notice Sets the hook contract.
     * @dev Only callable by the owner.
     * @param hook The address of the `ITTHook` hook contract.
     */
    function setHook(ITTHook hook) external virtual;

    /**
     * @notice Sets the claiming delegate who can trigger claims on behalf of recipients.
     * @param delegate The claiming delegate we wish to set.
     * @param status Whether the delegate is added(true) or revoked(false).
     * @dev Only callable by the owner.
     */
    function setClaimingDelegate(address delegate, bool status) external virtual;

    /**
     * @notice Sets if the current chain is supported by delegate.xyz
     */
    function setCurrentChainSupportsExternalDelegateRegistry(bool status) external virtual;

    /**
     * @notice Permanently disables the `createActuals()` function.
     * @dev Only callable by the owner.
     */
    function disableCreate() external virtual;

    /**
     * @notice Permanently disables the `cancel()` function.
     * @dev Only callable by the owner.
     */
    function disableCancel() external virtual;

    /**
     * @notice Permanently disables the hook.
     * @dev Only callable by the owner.
     */
    function disableHook() external virtual;

    /**
     * @notice Permanently prevents the founder from withdrawing deposits.
     * @dev Only callable by the owner.
     */
    function disableWithdraw() external virtual;

    /**
     * @notice When withdraw is disabled, this allows the owner to request an emergency withdraw of deposited tokens. This must be approved by the deployer.
     * @dev Only callable by the owner.
     */
    function setEmergencyWithdrawRequestStatus(bool status) external virtual;

    /**
     * @return The deployer instance associated with this Unlocker.
     */
    function deployer() external view virtual returns (ITTUDeployer);

    /**
     * @return The FutureToken instance associated with this Unlocker.
     */
    function futureToken() external view virtual returns (ITTFutureTokenV2);

    /**
     * @return The external hook associated with this Unlocker.
     */
    function hook() external view virtual returns (ITTHook);

    /**
     * @return Returns the array of claiming delegates who can trigger claims on behalf of schedule recipients.
     */
    function claimingDelegates() external view virtual returns (address[] memory);

    /**
     * @return If the founder is allowed to create new schedules.
     */
    function isCreateable() external view virtual returns (bool);

    /**
     * @return If the founder is allowed to cancel schedules.
     */
    function isCancelable() external view virtual returns (bool);

    /**
     * @return If the founder can attach external hooks to function calls.
     */
    function isHookable() external view virtual returns (bool);

    /**
     * @return If the founder can withdraw deposited but unclaimed tokens.
     */
    function isWithdrawable() external view virtual returns (bool);

    /**
     * @param actualId The canceled schedule ID.
     * @return The amount of tokens from canceled schedules that have been unlocked but unclaimed by the stakeholder.
     */
    function pendingAmountClaimableForCancelledActuals(uint256 actualId) external view virtual returns (uint256);

    /**
     * @notice To decode in JS, use:
     * ```js
     *  ethers.utils.defaultAbiCoder.decode(
     *      ['uint256[]', 'uint256', 'uint256[]', 'uint256[]', 'bool'],
     *      encodedPreset
     *  )
     * ```
     * @param presetId The ID of the preset we are trying to read.
     * @return An ABI-encoded `Preset`, as nested objects cannot be returned directly in Solidity.
     */
    function getEncodedPreset(bytes32 presetId) external view virtual returns (bytes memory);

    /**
     * @notice Returns the Actual struct based on the input ID.
     */
    function actuals(uint256 actualId) external view virtual returns (Actual memory);

    /**
     * @return The basis point precision of this Unlocker.
     */
    // function BIPS_PRECISION() external pure virtual returns (uint256); // Commenting this out, as this doesn't work with Hardhat upgrades plugin

    /**
     * @notice Returns if the current chain is supported by delegate.xyz
     */
    function currentChainSupportsExternalDelegateRegistry() public view virtual returns (bool);

    /**
     * @notice Calculates the amount of unlocked tokens that have yet to be claimed in an actual unlocking schedule.
     * @dev This is the most complex part of the smart contract. Quite a bit of calculations are performed here.
     * @param actualId The ID of the actual unlocking schedule that we are working with.
     * @return deltaAmountClaimable Amount of tokens claimable right now.
     * @return updatedAmountClaimed New total amount of tokens claimed. This is the sum of all previously claimed tokens and `deltaAmountClaimable`.
     */
    function calculateAmountClaimable(uint256 actualId)
        public
        view
        virtual
        returns (uint256 deltaAmountClaimable, uint256 updatedAmountClaimed);

    /**
     * @notice Simulates the amount of unlocked tokens that have yet to be claimed at a specific time in an actual unlocking schedule.
     * @dev This is the most complex part of the smart contract. Quite a bit of calculations are performed here.
     * @param actualId The ID of the actual unlocking schedule that we are working with.
     * @param claimTimestampAbsolute The simulated time of claim.
     * @return deltaAmountClaimable Amount of tokens claimable right now.
     * @return updatedAmountClaimed New total amount of tokens claimed. This is the sum of all previously claimed tokens and `deltaAmountClaimable`.
     */
    function simulateAmountClaimable(uint256 actualId, uint256 claimTimestampAbsolute)
        public
        view
        virtual
        returns (uint256 deltaAmountClaimable, uint256 updatedAmountClaimed);
}

contracts/interfaces/IVersionable.sol

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

/**
 * @title IVersionable
 * @author Jack Xu @ EthSign
 * @dev This interface is implemented by all major TokenTable contracts to keep track of their versioning for upgrade compatibility checks.
 */
interface IVersionable {
    function version() external pure returns (string memory);
}

contracts/interfaces/TokenTableUnlockerV2DataModels.sol

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

/**
 * @title TokenTableUnlockerV2DataModels.Preset
 * @author Jack Xu @ EthSign
 * @notice A `Preset` is an unlocking schedule template that contains information that's shared across all stakeholders within a single round.
 *
 * In this system, cliff unlocks are considered linear as well. This enables us to mix and match cliffs and linears at will, providing full customizability. Cliff waiting periods have a linear bip of 0 and cliff unlocking moments have a duration of 1 second.
 *
 * Note that all relative timestamps are relative to the absolute start timestamp. Absolute timestamps are standard UNIX epoch timestamps in seconds.
 *
 * `linearStartTimestampsRelative`: An array of start timestamps for each linear segment.
 * `linearEndTimestampRelative`: The timestamp that marks the end of the final linear segment.
 * `linearBips`: The basis point that is unlocked for each linear segment. Must add up to `TokenTableUnlockerV2.BIPS_PRECISION()`.
 * `numOfUnlocksForEachLinear`: The number of unlocks within each respective linear segment.
 * `stream`: If the tokens should unlock as a stream instead of a cliff at the end of linear segment subdivision.
 */
struct Preset {
    uint256[] linearStartTimestampsRelative;
    uint256 linearEndTimestampRelative;
    uint256[] linearBips;
    uint256[] numOfUnlocksForEachLinear;
    bool stream;
}

/**
 * @title TokenTableUnlockerV2DataModels.Actual
 * @author Jack Xu @ EthSign
 * @notice An `Actual` is an actual unlocking schedule for a single stakeholder and builds on top of an existing preset. An actual contains information that is different from one stakeholder to the next.
 *
 * `presetId`: The ID of the `Preset` that this `Actual` references.
 * `startTimestampAbsolute`: The timestamp of when this unlocking schedule actually starts.
 * `amountClaimed`: The amount of tokens that have already been claimed by the recipient.
 * `totalAmount`: The maximum amount of tokens that the recipient can claim throughout the entire schedule.
 */
struct Actual {
    bytes32 presetId;
    uint256 startTimestampAbsolute;
    uint256 amountClaimed;
    uint256 totalAmount;
}

contracts/proxy/TTUV2BeaconManager.sol

// SPDX-License-Identifier: AGPL v3

pragma solidity ^0.8.20;

import {UpgradeableBeacon} from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IVersionable} from "../interfaces/IVersionable.sol";

/**
 * @title TTUV2BeaconManager
 * @author Jack Xu @ EthSign
 * @dev This contract manages the upgradeable beacons that we use to seamlessly
 * upgrade TokenTableUnlocker, TTFutureToken, and TTTrackerToken on behalf of
 * our users in the future.
 *
 * This contract should be deployed using TTUDeployer.
 */
contract TTUV2BeaconManager is Ownable, IVersionable {
    // Reserved names: TokenTableUnlockerV2, TTFutureTokenV2, TTTrackerTokenV2
    mapping(string => UpgradeableBeacon) public beacons;

    constructor() Ownable(_msgSender()) {}

    function upgradeCustomBeacon(string calldata id, address newImpl) external onlyOwner {
        UpgradeableBeacon beacon = beacons[id];
        if (address(beacon) == address(0)) {
            beacons[id] = new UpgradeableBeacon(newImpl, address(this));
        } else {
            beacon.upgradeTo(newImpl);
        }
    }

    function version() external pure returns (string memory) {
        return "2.6.0";
    }
}

erc721a-upgradeable/contracts/IERC721AUpgradeable.sol

// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

/**
 * @dev Interface of ERC721A.
 */
interface IERC721AUpgradeable {
    /**
     * The caller must own the token or be an approved operator.
     */
    error ApprovalCallerNotOwnerNorApproved();

    /**
     * The token does not exist.
     */
    error ApprovalQueryForNonexistentToken();

    /**
     * Cannot query the balance for the zero address.
     */
    error BalanceQueryForZeroAddress();

    /**
     * Cannot mint to the zero address.
     */
    error MintToZeroAddress();

    /**
     * The quantity of tokens minted must be more than zero.
     */
    error MintZeroQuantity();

    /**
     * The token does not exist.
     */
    error OwnerQueryForNonexistentToken();

    /**
     * The caller must own the token or be an approved operator.
     */
    error TransferCallerNotOwnerNorApproved();

    /**
     * The token must be owned by `from`.
     */
    error TransferFromIncorrectOwner();

    /**
     * Cannot safely transfer to a contract that does not implement the
     * ERC721Receiver interface.
     */
    error TransferToNonERC721ReceiverImplementer();

    /**
     * Cannot transfer to the zero address.
     */
    error TransferToZeroAddress();

    /**
     * The token does not exist.
     */
    error URIQueryForNonexistentToken();

    /**
     * The `quantity` minted with ERC2309 exceeds the safety limit.
     */
    error MintERC2309QuantityExceedsLimit();

    /**
     * The `extraData` cannot be set on an unintialized ownership slot.
     */
    error OwnershipNotInitializedForExtraData();

    // =============================================================
    //                            STRUCTS
    // =============================================================

    struct TokenOwnership {
        // The address of the owner.
        address addr;
        // Stores the start time of ownership with minimal overhead for tokenomics.
        uint64 startTimestamp;
        // Whether the token has been burned.
        bool burned;
        // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
        uint24 extraData;
    }

    // =============================================================
    //                         TOKEN COUNTERS
    // =============================================================

    /**
     * @dev Returns the total number of tokens in existence.
     * Burned tokens will reduce the count.
     * To get the total number of tokens minted, please see {_totalMinted}.
     */
    function totalSupply() external view returns (uint256);

    // =============================================================
    //                            IERC165
    // =============================================================

    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);

    // =============================================================
    //                            IERC721
    // =============================================================

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

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables
     * (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in `owner`'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`,
     * checking first that contract recipients are aware of the ERC721 protocol
     * to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move
     * this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external payable;

    /**
     * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom}
     * whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token
     * by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the
     * zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external payable;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom}
     * for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    // =============================================================
    //                        IERC721Metadata
    // =============================================================

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

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);

    // =============================================================
    //                           IERC2309
    // =============================================================

    /**
     * @dev Emitted when tokens in `fromTokenId` to `toTokenId`
     * (inclusive) is transferred from `from` to `to`, as defined in the
     * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
     *
     * See {_mintERC2309} for more details.
     */
    event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}

erc721a-upgradeable/contracts/extensions/IERC721AQueryableUpgradeable.sol

// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

import '../IERC721AUpgradeable.sol';

/**
 * @dev Interface of ERC721AQueryable.
 */
interface IERC721AQueryableUpgradeable is IERC721AUpgradeable {
    /**
     * Invalid query range (`start` >= `stop`).
     */
    error InvalidQueryRange();

    /**
     * @dev Returns the `TokenOwnership` struct at `tokenId` without reverting.
     *
     * If the `tokenId` is out of bounds:
     *
     * - `addr = address(0)`
     * - `startTimestamp = 0`
     * - `burned = false`
     * - `extraData = 0`
     *
     * If the `tokenId` is burned:
     *
     * - `addr = <Address of owner before token was burned>`
     * - `startTimestamp = <Timestamp when token was burned>`
     * - `burned = true`
     * - `extraData = <Extra data when token was burned>`
     *
     * Otherwise:
     *
     * - `addr = <Address of owner>`
     * - `startTimestamp = <Timestamp of start of ownership>`
     * - `burned = false`
     * - `extraData = <Extra data at start of ownership>`
     */
    function explicitOwnershipOf(uint256 tokenId) external view returns (TokenOwnership memory);

    /**
     * @dev Returns an array of `TokenOwnership` structs at `tokenIds` in order.
     * See {ERC721AQueryable-explicitOwnershipOf}
     */
    function explicitOwnershipsOf(uint256[] memory tokenIds) external view returns (TokenOwnership[] memory);

    /**
     * @dev Returns an array of token IDs owned by `owner`,
     * in the range [`start`, `stop`)
     * (i.e. `start <= tokenId < stop`).
     *
     * This function allows for tokens to be queried if the collection
     * grows too big for a single call of {ERC721AQueryable-tokensOfOwner}.
     *
     * Requirements:
     *
     * - `start < stop`
     */
    function tokensOfOwnerIn(
        address owner,
        uint256 start,
        uint256 stop
    ) external view returns (uint256[] memory);

    /**
     * @dev Returns an array of token IDs owned by `owner`.
     *
     * This function scans the ownership mapping and is O(`totalSupply`) in complexity.
     * It is meant to be called off-chain.
     *
     * See {ERC721AQueryable-tokensOfOwnerIn} for splitting the scan into
     * multiple smaller scans if the collection is large enough to cause
     * an out-of-gas error (10K collections should be fine).
     */
    function tokensOfOwner(address owner) external view returns (uint256[] memory);
}

erc721a-upgradeable/contracts/interfaces/IERC721AQueryableUpgradeable.sol

// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

import '../extensions/IERC721AQueryableUpgradeable.sol';
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.