Skip to content
Verified contractPartialMIT

GatedERC1155ValidationHook

Address0x0959dab9ba4ab6455c112d1e2afaa745e1a56c33
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 11,111 runs
EVM version
cancun
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,427,726
Creation transaction
0xeda1211c71…1f20c9e29f

lib/cca/src/periphery/validationHooks/GatedERC1155ValidationHook.sol

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

import {IValidationHook} from '../../interfaces/IValidationHook.sol';
import {BaseERC1155ValidationHook} from './BaseERC1155ValidationHook.sol';
import {IBaseERC1155ValidationHook} from './BaseERC1155ValidationHook.sol';
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
import {BlockNumberish} from 'blocknumberish/src/BlockNumberish.sol';

interface IGatedERC1155ValidationHook is IBaseERC1155ValidationHook {
    /// @notice The block number until which the validation check is enforced
    function expirationBlock() external view returns (uint256);
}

/// @notice Validation hook for ERC1155 tokens that requires the sender to hold a specific token until a certain block number
/// @dev It is highly recommended to make the ERC1155 soulbound (non-transferable)
contract GatedERC1155ValidationHook is IGatedERC1155ValidationHook, BaseERC1155ValidationHook, BlockNumberish {
    /// @inheritdoc IGatedERC1155ValidationHook
    uint256 public immutable expirationBlock;

    constructor(address _erc1155, uint256 _tokenId, uint256 _expirationBlock)
        BaseERC1155ValidationHook(_erc1155, _tokenId)
    {
        expirationBlock = _expirationBlock;
    }

    /// @notice Require that the `owner` and `sender` of the bid hold at least one of the required ERC1155 token
    /// @dev This check is enforced until the `expirationBlock` block number
    /// @inheritdoc IValidationHook
    function validate(uint256 maxPrice, uint128 amount, address owner, address sender, bytes calldata hookData)
        public
        view
        virtual
        override(BaseERC1155ValidationHook, IValidationHook)
    {
        if (_getBlockNumberish() < expirationBlock) {
            super.validate(maxPrice, amount, owner, sender, hookData);
        }
    }

    /// @dev Extend the existing introspection support to signal that derived contracts inherit from GatedERC1155ValidationHook
    function supportsInterface(bytes4 _interfaceId)
        public
        view
        virtual
        override(BaseERC1155ValidationHook, IERC165)
        returns (bool)
    {
        return super.supportsInterface(_interfaceId) || _interfaceId == type(IGatedERC1155ValidationHook).interfaceId;
    }
}

lib/cca/lib/blocknumberish/src/BlockNumberish.sol

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

/// @title BlockNumberish
/// A helper contract to get the current block number on different chains
/// inspired by https://github.com/ProjectOpenSea/tstorish/blob/main/src/Tstorish.sol
/// @custom:security-contact [email protected]
contract BlockNumberish {
    // Unichain chain ID.
    uint256 private constant UNICHAIN_CHAIN_ID = 130;
    /// @dev Function selector for arbBlockNumber() from: https://github.com/OffchainLabs/nitro-precompile-interfaces/blob/f49a4889b486fd804a7901203f5f663cfd1581c8/ArbSys.sol#L17
    uint32 private constant ARB_SYS_SELECTOR = 0xa3b1b31d;
    /// @dev Arbitrum system contract address (address(100))
    uint8 private constant ARB_SYS_ADDRESS = 0x64;
    /// @dev Function selector for getFlashblockNumber() from: https://github.com/Uniswap/flashblocks_number_contract/blob/a667d57f0055de80b9909c8837e872c4364853c3/src/IFlashblockNumber.sol#L70
    uint32 private constant UNICHAIN_FLASHBLOCK_NUMBER_SELECTOR = 0xe5b37c5d;
    /// @dev Unichain flashblock number address
    address private constant UNICHAIN_FLASHBLOCK_NUMBER_ADDRESS = 0x3c3A8a41E095C76b03f79f70955fFf3b03cf753E;

    /// @dev Whether to override the block number with the ArbSys precompile. Supports all Arbitrum and Orbit chains.
    bool private immutable _USE_ARB_SYS;

    constructor() {
        bool useArbSys;
        assembly {
            if extcodesize(ARB_SYS_ADDRESS) {
                mstore(0x00, ARB_SYS_SELECTOR)
                // staticcall(gas, address, argsOffset, argsSize, retOffset, retSize)
                let success := staticcall(gas(), ARB_SYS_ADDRESS, 0x1c, 0x04, 0x00, 0x20)
                // per the interface, require the call to succeed and return a 32 byte value
                useArbSys := and(success, eq(returndatasize(), 0x20))
            }
        }
        _USE_ARB_SYS = useArbSys;
    }

    /// @notice Internal view function to get the current block number.
    /// @dev Returns the Arbitrum block number on chains exposing the ArbSys precompile, standard block number elsewhere.
    function _getBlockNumberish() internal view returns (uint256 blockNumber) {
        if (_USE_ARB_SYS) {
            assembly {
                mstore(0x00, ARB_SYS_SELECTOR)
                // staticcall(gas, address, argsOffset, argsSize, retOffset, retSize)
                let success := staticcall(gas(), ARB_SYS_ADDRESS, 0x1c, 0x04, 0x00, 0x20)
                // revert if the call fails from OOG or returns malformed data
                if or(iszero(success), iszero(eq(returndatasize(), 0x20))) {
                    revert(0, 0)
                }

                // load the stored block number from memory
                blockNumber := mload(0x00)
            }
        } else {
            blockNumber = block.number;
        }
    }

    /// @notice Internal view function to get the current flashblock number.
    /// @dev Returns Unichain flashblock number on Unichain, 0 elsewhere.
    function _getFlashblockNumberish() internal view returns (uint256 flashblockNumber) {
        if (block.chainid == UNICHAIN_CHAIN_ID) {
            assembly {
                mstore(0x00, UNICHAIN_FLASHBLOCK_NUMBER_SELECTOR)
                // staticcall(gas, address, argsOffset, argsSize, retOffset, retSize)
                let success := staticcall(gas(), UNICHAIN_FLASHBLOCK_NUMBER_ADDRESS, 0x1c, 0x04, 0x00, 0x20)
                // revert if the call fails from OOG or returns malformed data
                if or(iszero(success), iszero(eq(returndatasize(), 0x20))) {
                    revert(0, 0)
                }

                // load the stored block number from memory
                flashblockNumber := mload(0x00)
            }
        }
    }
}

lib/cca/lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC-1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[ERC].
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

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

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the zero address.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {IERC1155Receiver-onERC1155Received} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `value` amount.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {IERC1155Receiver-onERC1155BatchReceived} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
     *
     * Requirements:
     *
     * - `ids` and `values` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external;
}

lib/cca/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol

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

pragma solidity ^0.8.20;

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

lib/cca/src/interfaces/IValidationHook.sol

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

/// @notice Interface for custom bid validation logic
interface IValidationHook {
    /// @notice Validate a bid
    /// @dev MUST revert if the bid is invalid
    /// @param maxPrice The maximum price the bidder is willing to pay
    /// @param amount The amount of the bid
    /// @param owner The owner of the bid
    /// @param sender The sender of the bid
    /// @param hookData Additional data to pass to the hook required for validation
    function validate(uint256 maxPrice, uint128 amount, address owner, address sender, bytes calldata hookData) external;
}

lib/cca/src/periphery/validationHooks/BaseERC1155ValidationHook.sol

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

import {IValidationHook} from '../../interfaces/IValidationHook.sol';
import {IValidationHookIntrospection, ValidationHookIntrospection} from './ValidationHookIntrospection.sol';
import {IERC1155} from '@openzeppelin/contracts/token/ERC1155/IERC1155.sol';
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';

interface IBaseERC1155ValidationHook is IValidationHookIntrospection {
    /// @notice The ERC1155 token contract that is checked for ownership
    /// @dev Callers should query the returned interface's `balanceOf` method
    function erc1155() external view returns (IERC1155);
    /// @notice The ERC1155 tokenId that is checked for ownership
    function tokenId() external view returns (uint256);
}

/// @notice Base validation hook for ERC1155 tokens
/// @dev This hook validates that the sender is the owner of a specific ERC1155 tokenId
///      It is highly recommended to make the ERC1155 soulbound (non-transferable)
contract BaseERC1155ValidationHook is IBaseERC1155ValidationHook, ValidationHookIntrospection {
    /// @inheritdoc IBaseERC1155ValidationHook
    IERC1155 public immutable erc1155;
    /// @inheritdoc IBaseERC1155ValidationHook
    uint256 public immutable tokenId;

    /// @notice Error thrown when the token address is invalid
    error InvalidTokenAddress();
    /// @notice Error thrown when the sender is not the owner of the ERC1155 tokenId
    error NotOwnerOfERC1155Token(uint256 tokenId);
    /// @notice Error thrown when the sender is not the owner of the ERC1155 token
    error SenderMustBeOwner();

    /// @notice Emitted when the ERC1155 tokenId is set
    /// @param tokenAddress The address of the ERC1155 token
    /// @param tokenId The ID of the ERC1155 token
    event ERC1155TokenIdSet(address indexed tokenAddress, uint256 tokenId);

    constructor(address _erc1155, uint256 _tokenId) {
        if (_erc1155 == address(0)) revert InvalidTokenAddress();
        erc1155 = IERC1155(_erc1155);
        tokenId = _tokenId;
        emit ERC1155TokenIdSet(_erc1155, tokenId);
    }

    /// @notice Require that the `owner` and `sender` of the bid hold at least one of the required ERC1155 token
    /// @inheritdoc IValidationHook
    function validate(uint256, uint128, address owner, address sender, bytes calldata) public view virtual {
        if (sender != owner) revert SenderMustBeOwner();
        if (erc1155.balanceOf(owner, tokenId) == 0) revert NotOwnerOfERC1155Token(tokenId);
    }

    /// @dev Extend the existing introspection support to signal that derived contracts inherit from BaseERC1155ValidationHook
    function supportsInterface(bytes4 _interfaceId)
        public
        view
        virtual
        override(ValidationHookIntrospection, IERC165)
        returns (bool)
    {
        return super.supportsInterface(_interfaceId) || _interfaceId == type(IBaseERC1155ValidationHook).interfaceId;
    }
}

lib/cca/src/periphery/validationHooks/ValidationHookIntrospection.sol

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

import {IValidationHook} from '../../interfaces/IValidationHook.sol';
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';

interface IValidationHookIntrospection is IValidationHook, IERC165 {}

/// @notice Base contract for validation hooks supporting basic introspection
/// @dev Offchain interfaces and integrators should query `supportsInterface` to identify supported hook interfaces
abstract contract ValidationHookIntrospection is IValidationHookIntrospection {
    /// @inheritdoc IERC165
    function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool) {
        return _interfaceId == type(IValidationHook).interfaceId || _interfaceId == type(IERC165).interfaceId;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 11111,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/cca/lib/forge-std/src/",
    "cca/=lib/cca/src/",
    "continuous-clearing-auction/=lib/cca/src/",
    "permit2/=lib/cca/lib/permit2/",
    "solady/=lib/cca/lib/solady/src/",
    "liquidity-launcher/=lib/cca/lib/liquidity-launcher/",
    "blocknumberish/=lib/cca/lib/blocknumberish/",
    "@uniswap/blocknumberish/=lib/cca/lib/blocknumberish/",
    "@openzeppelin/contracts/=lib/cca/lib/openzeppelin-contracts/contracts/",
    "@uniswap/v4-core/=lib/cca/lib/v4-periphery/lib/v4-core/",
    "@uniswap/v4-periphery/=lib/cca/lib/v4-periphery/",
    "uniswap-hooks/=lib/uniswap-hooks/src/",
    "launcher/=lib/liquidity-launcher-src/src/",
    "oz47/=lib/cca/lib/permit2/lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/cca/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/cca/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/cca/lib/forge-gas-snapshot/src/",
    "halmos-cheatcodes/=lib/cca/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "liquidity-launcher-src/=lib/liquidity-launcher-src/src/",
    "openzeppelin-contracts/=lib/cca/lib/openzeppelin-contracts/",
    "solmate/=lib/cca/lib/permit2/lib/solmate/src/",
    "v4-core/=lib/cca/lib/v4-periphery/lib/v4-core/src/",
    "v4-periphery/=lib/cca/lib/v4-periphery/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.