Skip to content
Verified contractPartialMIT

Sale

Address0x4edf071a7dee52fbe663df7873994725ba91cdc7
Balance

0 ETH

 

Transactions

70

 

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
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
21,210,235
Creation transaction
0x1f90c0990b…d90f5dc039

src/Sale.sol

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

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

contract Sale is BaseSale {
    constructor()
        BaseSale(
            0xdAC17F958D2ee523a2206206994597C13D831ec7, // USDT
            0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, // USDC
            0x6B175474E89094C44Da98b954EedeAC495271d0F, // DAI
            0x5726C14663A1EaD4A7D320E8A653c9710b2A2E89, // Butterin Cards
            0x7cd51FA7E155805C34F333ba493608742A67Da8e // Mined JPEG
        )
    {}
}

lib/openzeppelin-contracts/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);
    }
}

lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @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`.
     *
     * 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 approved 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;

    /**
     * @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 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) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * 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;

    /**
     * @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;

    /**
     * @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 address zero.
     *
     * 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);
}

lib/openzeppelin-contracts/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

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

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

pragma solidity ^0.8.20;

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

lib/solidity-lib/contracts/libraries/TransferHelper.sol

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >=0.6.0;

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
    }

    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
    }

    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
    }
}

src/BaseSale.sol

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

import {TransferHelper} from "solidity-lib/TransferHelper.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {IERC721} from "openzeppelin/token/ERC721/IERC721.sol";
import {Ownable} from "openzeppelin/access/Ownable.sol";
import {SaleStructs} from "./SaleStructs.sol";

/** @notice Sale contract for SIR
    @notice Accepts USDT, USDC & DAI
    @notice Users can lock up to 5 Buterin Cards or Mined JPEGs to boost their token allocations
    @notice Users can withdraw their deposits before 24 hours have passed
    @notice Users can withdraw their NFTs 1 year after the sale ended
 */
abstract contract BaseSale is SaleStructs, Ownable {
    address internal immutable _USDT;
    address internal immutable _USDC;
    address internal immutable _DAI;

    IERC721 internal immutable _BUTERIN_CARDS;
    IERC721 internal immutable _MINED_JPEG;

    uint8 private constant _USDT_DECIMALS = 6;
    uint8 private constant _USDC_DECIMALS = 6;
    uint8 private constant _DAI_DECIMALS = 18;

    SaleState private _state;

    mapping(address contributor => Contribution) private _contributions;

    ////////////////////////////////////////////////////////////////////////////////
    //////////////// S T A T E - C H A N G I N G  F U N C T I O N S ///////////////
    //////////////////////////////////////////////////////////////////////////////

    constructor(
        address USDT_,
        address USDC_,
        address DAI_,
        address buterinCards,
        address minedJPEG
    ) Ownable(msg.sender) {
        _USDT = USDT_;
        _USDC = USDC_;
        _DAI = DAI_;
        _BUTERIN_CARDS = IERC721(buterinCards);
        _MINED_JPEG = IERC721(minedJPEG);
    }

    /** @notice Deposits USDT, USDC or DAI and, optionally, locks up to 5 Buterin Cards or Mined JPEGs
        @notice Users can deposit multiple times
        @notice Once one stablecoin is deposited, the user cannot deposit another stablecoin
        @param stablecoin The stablecoin to deposit
        @param amountNoDecimals The amount to deposit in the stablecoin without decimals
        @param buterinCardIds The IDs of the Buterin Cards to lock
        @param minedJpegIds The IDs of the Mined JPEGs to lock
     */
    function depositAndLockNfts(
        Stablecoin stablecoin,
        uint24 amountNoDecimals,
        uint16[] calldata buterinCardIds,
        uint8[] calldata minedJpegIds
    ) external {
        // maxAmountNoDecimals ensures that the total contributions do not exceed MAX_CONTRIBUTIONS_NO_DECIMALS
        unchecked {
            if (amountNoDecimals == 0) revert NullDeposit();

            // Revert if sale is over
            SaleState memory state_ = _state;
            if (state_.timeSaleEnded > 0) revert SaleIsOver();

            // Limit the contribution if it exceeds the maximum
            uint24 maxAmountNoDecimals = MAX_CONTRIBUTIONS_NO_DECIMALS -
                state_.totalContributionsNoDecimals;
            if (amountNoDecimals >= maxAmountNoDecimals) {
                if (amountNoDecimals > maxAmountNoDecimals) {
                    // Truncate the contribution
                    amountNoDecimals = maxAmountNoDecimals;

                    // Emit event
                    emit DepositWasReduced();
                }

                // End sale
                _endSale(state_);
            }

            // Update _state
            state_.totalContributionsNoDecimals += amountNoDecimals;

            // Update contribution
            Contribution memory contribution = contributions(msg.sender);
            if (
                contribution.amountFinalNoDecimals +
                    contribution.amountWithdrawableNoDecimals ==
                0
            ) {
                // 1st contribution
                contribution.stablecoin = stablecoin;
            } else if (stablecoin != contribution.stablecoin) {
                revert WrongStablecoin();
            }
            contribution.amountWithdrawableNoDecimals += amountNoDecimals;
            contribution.timeLastContribution = uint40(block.timestamp);

            // Lock NFTs
            _lockNfts(buterinCardIds, minedJpegIds, contribution);

            // Save contribution and _state
            _state = state_;
            _contributions[msg.sender] = contribution;

            // Emit event
            emit Deposit(stablecoin, amountNoDecimals);

            // Transfer tokens to the contract
            TransferHelper.safeTransferFrom(
                stablecoin == Stablecoin.USDT
                    ? _USDT
                    : stablecoin == Stablecoin.USDC
                    ? _USDC
                    : _DAI,
                msg.sender,
                address(this),
                _addDecimals(stablecoin, amountNoDecimals)
            );
        }
    }

    /** @notice Contributors can withdraw their deposits before 24 hours have passed
     */
    function withdraw() external {
        // Revert if sale is over
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded > 0) revert SaleIsOver();

        // Revert if the user has made no contribution in the last 24 hours
        Contribution memory contribution = contributions(msg.sender);
        if (contribution.amountWithdrawableNoDecimals == 0)
            revert NullDeposit();

        // Update contribution
        uint24 amountWithdrawableNoDecimals = contribution
            .amountWithdrawableNoDecimals;
        contribution.amountWithdrawableNoDecimals = 0;
        _contributions[msg.sender] = contribution;

        // Update _state
        unchecked {
            // amountWithdrawableNoDecimals is always less than or equal to totalContributionsNoDecimals
            state_.totalContributionsNoDecimals -= amountWithdrawableNoDecimals;
        }
        _state = state_;

        // Emit event
        emit Withdrawal(contribution.stablecoin, amountWithdrawableNoDecimals);

        // Transfer tokens to the user
        TransferHelper.safeTransfer(
            contribution.stablecoin == Stablecoin.USDT
                ? _USDT
                : contribution.stablecoin == Stablecoin.USDC
                ? _USDC
                : _DAI,
            msg.sender,
            _addDecimals(contribution.stablecoin, amountWithdrawableNoDecimals)
        );
    }

    /** @notice Locks up to 5 Buterin Cards or Mined JPEGs
        @param buterinCardIds The IDs of the Buterin Cards to lock
        @param minedJpegIds The IDs of the Mined JPEGs to lock
     */
    function lockNfts(
        uint16[] calldata buterinCardIds,
        uint8[] calldata minedJpegIds
    ) external {
        // Revert if sale is over
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded > 0) revert SaleIsOver();

        // Lock NFTs
        Contribution memory contribution = contributions(msg.sender);
        _lockNfts(buterinCardIds, minedJpegIds, contribution);

        // Save contribution
        _contributions[msg.sender] = contribution;
    }

    /** @notice Withdraws the Buterin Cards and Mined JPEGs locked by the user
        @notice Users can withdraw their NFTs 1 year after the sale ended
     */
    function withdrawNfts() external {
        // i++ will never overflow
        unchecked {
            // Revert if it is less than 1 year since the sale ended
            uint40 timeSaleEnded = _state.timeSaleEnded;
            if (
                timeSaleEnded == 0 || block.timestamp < timeSaleEnded + 365 days
            ) revert NftsLocked();

            // Withdraw NFTs
            Contribution memory contribution = contributions(msg.sender);
            LockedButerinCards memory lockedButerinCards = contribution
                .lockedButerinCards;
            LockedMinedJpegs memory lockedMinedJpegs = contribution
                .lockedMinedJpegs;

            if (lockedButerinCards.number == 0 && lockedMinedJpegs.number == 0)
                revert NoNfts();

            // Transfer Buterin Cards
            for (uint256 i = 0; i < lockedButerinCards.number; ++i) {
                _BUTERIN_CARDS.transferFrom(
                    address(this),
                    msg.sender,
                    lockedButerinCards.ids[i]
                );
                emit ButerinCardUnlocked(lockedButerinCards.ids[i]);
            }

            // Transfer Mined JPEGs
            for (uint256 i = 0; i < lockedMinedJpegs.number; ++i) {
                _MINED_JPEG.transferFrom(
                    address(this),
                    msg.sender,
                    lockedMinedJpegs.ids[i]
                );
                emit MinedJpegUnlocked(lockedMinedJpegs.ids[i]);
            }

            // Update contribution
            contribution.lockedButerinCards.number = 0;
            contribution.lockedMinedJpegs.number = 0;

            // Save contribution
            _contributions[msg.sender] = contribution;
        }
    }

    ////////////////////////////////////////////////////////////////////////////////
    ///////////////////////// O W N E R  F U N C T I O N S ////////////////////////
    //////////////////////////////////////////////////////////////////////////////

    /** @notice Ends the sale prematurely
     */
    function endSale() external onlyOwner {
        // Get _state
        SaleState memory state_ = _state;

        // Revert if sale is already over
        if (state_.timeSaleEnded > 0) revert SaleIsOver();

        // End sale
        _endSale(state_);

        // Update _state
        _state = state_;
    }

    /** @notice Withdraws all USDT, USDC & DAI from the contract if the sale is over
     */
    function withdrawFunds() external onlyOwner {
        // Revert if sale is live
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded == 0) revert SaleIsLive();

        // Withdraw USDT
        TransferHelper.safeTransfer(
            _USDT,
            msg.sender,
            IERC20(_USDT).balanceOf(address(this))
        );

        // Withdraw USDC
        TransferHelper.safeTransfer(
            _USDC,
            msg.sender,
            IERC20(_USDC).balanceOf(address(this))
        );

        // Withdraw DAI
        TransferHelper.safeTransfer(
            _DAI,
            msg.sender,
            IERC20(_DAI).balanceOf(address(this))
        );
    }

    /** @notice Withdraws any ERC20 token in case any worthy token (that is not USDT, USDC or DAI) was sent to the contract
     */
    function withdrawExoticERC20(address token) external onlyOwner {
        // Revert if sale is live
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded == 0) revert SaleIsLive();

        TransferHelper.safeTransfer(
            token,
            msg.sender,
            IERC20(token).balanceOf(address(this))
        );
    }

    /** @notice Just in case something goes wrong, owner can unlock all NFTs
     */
    function unlockAllNfts() external onlyOwner {
        // It simulates that the sale ended on Jan 1, 1970, which effectively allows every contributor to withdraw their NFTs
        // It also haults deposits.
        _state.timeSaleEnded = 1;
    }

    ////////////////////////////////////////////////////////////////////////////////
    //////////////////// R E A D -  O N L Y  F U N C T I O N S ////////////////////
    //////////////////////////////////////////////////////////////////////////////

    function state() public view returns (SaleState memory) {
        return _state;
    }

    /** @notice Returns the contribution of a user including stablecoin of choice, (un)withdrawable amounts, and locked NFTs
        @param contributor The address of the contributor
     */
    function contributions(
        address contributor
    ) public view returns (Contribution memory) {
        unchecked {
            Contribution memory contribution = _contributions[contributor];
            if (
                block.timestamp >=
                contribution.timeLastContribution + 24 hours ||
                _state.timeSaleEnded > 0
            ) {
                // If 24 hours have passed since the last deposit, the user cannot withdraw the previous deposit
                contribution.amountFinalNoDecimals += contribution
                    .amountWithdrawableNoDecimals;
                contribution.amountWithdrawableNoDecimals = 0;
            }
            return contribution;
        }
    }

    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////// P R I V A T E  F U N C T I O N S ///////////////////////
    //////////////////////////////////////////////////////////////////////////////

    function _endSale(SaleState memory state_) private {
        // Update last deposit time
        state_.timeSaleEnded = uint40(block.timestamp);

        // Emit event
        emit SaleEnded(uint40(block.timestamp));
    }

    function _lockNfts(
        uint16[] calldata buterinCardIds,
        uint8[] calldata minedJpegIds,
        Contribution memory contribution
    ) private {
        // Revert if the total of locked NFTs exceeds 5
        if (
            buterinCardIds.length +
                minedJpegIds.length +
                contribution.lockedButerinCards.number +
                contribution.lockedMinedJpegs.number >
            5
        ) revert TooManyNfts();

        // ++i will never overflow
        unchecked {
            // Update contribution
            for (uint256 i = 0; i < buterinCardIds.length; ++i) {
                contribution.lockedButerinCards.ids[
                    contribution.lockedButerinCards.number++
                ] = buterinCardIds[i];
                emit ButerinCardLocked(buterinCardIds[i]);
            }

            for (uint256 i = 0; i < minedJpegIds.length; ++i) {
                contribution.lockedMinedJpegs.ids[
                    contribution.lockedMinedJpegs.number++
                ] = minedJpegIds[i];
                emit MinedJpegLocked(minedJpegIds[i]);
            }

            // Transfer Buterin Cards
            for (uint256 i = 0; i < buterinCardIds.length; ++i) {
                _BUTERIN_CARDS.transferFrom(
                    msg.sender,
                    address(this),
                    buterinCardIds[i]
                );
            }

            // Transfer Mined JPEGs
            for (uint256 i = 0; i < minedJpegIds.length; ++i) {
                _MINED_JPEG.transferFrom(
                    msg.sender,
                    address(this),
                    minedJpegIds[i]
                );
            }
        }
    }

    function _addDecimals(
        Stablecoin stablecoin,
        uint256 amountNoDecimals
    ) private pure returns (uint256) {
        unchecked {
            if (stablecoin == Stablecoin.USDT) {
                return amountNoDecimals * 10 ** _USDT_DECIMALS;
            }
            if (stablecoin == Stablecoin.USDC) {
                return amountNoDecimals * 10 ** _USDC_DECIMALS;
            }
            return amountNoDecimals * 10 ** _DAI_DECIMALS;
        }
    }
}

src/SaleStructs.sol

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

contract SaleStructs {
    uint24 public constant MAX_CONTRIBUTIONS_NO_DECIMALS = 500_000; // [$]

    event SaleEnded(uint40 timeSaleEnded);
    event DepositWasReduced();

    event Deposit(Stablecoin stablecoin, uint24 amountNoDecimals);
    event Withdrawal(Stablecoin stablecoin, uint24 amountNoDecimals);
    event ButerinCardLocked(uint16 tokenId);
    event MinedJpegLocked(uint8 tokenId);
    event ButerinCardUnlocked(uint16 tokenId);
    event MinedJpegUnlocked(uint8 tokenId);

    error WrongStablecoin();
    error NullDeposit();
    error SaleIsOver();
    error TooManyNfts();
    error NftsLocked();
    error SaleIsLive();
    error NoNfts();

    enum Stablecoin {
        USDT,
        USDC,
        DAI
    }

    struct LockedButerinCards {
        uint8 number;
        uint16[5] ids;
    }

    struct LockedMinedJpegs {
        uint8 number;
        uint8[5] ids;
    }

    struct Contribution {
        Stablecoin stablecoin;
        uint24 amountFinalNoDecimals;
        uint24 amountWithdrawableNoDecimals;
        uint40 timeLastContribution;
        LockedButerinCards lockedButerinCards;
        LockedMinedJpegs lockedMinedJpegs;
    }

    struct SaleState {
        uint24 totalContributionsNoDecimals;
        uint40 timeSaleEnded;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": [
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "solidity-lib/=lib/solidity-lib/contracts/libraries/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.