lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/// @dev Performs a transfer of funds, this is only callable by approved extension contracts
/// the `nonReentrant` guard is intentionally not added to this function, to allow for more flexibility.
/// The calling contract should be secure and have its own `nonReentrant` guard as needed.
/// @param _receivingAddress the address to transfer to
/// @param _assetHash the asset to transfer
/// @param _amount the amount to transfer
/// @return true if success
function extensionTransfer(
        address _receivingAddress,
        address _assetHash,
        uint256 _amount
    )
        external
        returns (bool)
    {
        require(
            extensions[msg.sender] == true,
            "Invalid extension"
        );

        if (_assetHash == ETH_ASSET_HASH) {
            // we use `call` here since the _receivingAddress could be a contract
            // see https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/
            // for more info
            (bool success,  ) = _receivingAddress.call{value: _amount}("");
            require(success, "Transfer failed");
            return true;
        }

        ERC20 token = ERC20(_assetHash);
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(
                token.approve.selector,
                _receivingAddress,
                _amount
            )
        );

        return true;
    }
// Solidity 0.6.12
/// @dev Marks an asset as registered by associating it to a specified Switcheo TradeHub proxy and asset hash
/// @param _assetHash the address of the asset to mark
/// @param _proxyAddress the associated proxy address on Switcheo TradeHub
/// @param _toAssetHash the associated asset hash on Switcheo TradeHub
function _markAssetAsRegistered(
        address _assetHash,
        bytes memory _proxyAddress,
        bytes memory _toAssetHash
    )
        private
    {
        require(_proxyAddress.length == 20, "Invalid proxyAddress");
        require(
            registry[_assetHash] == bytes32(0),
            "Asset already registered"
        );

        bytes32 value = keccak256(abi.encodePacked(
            _proxyAddress,
            _toAssetHash
        ));

        registry[_assetHash] = value;
    }
// Solidity 0.6.12
/// @dev Validates that an asset's registration matches the given params
/// @param _assetHash the address of the asset to check
/// @param _proxyAddress the expected proxy address on Switcheo TradeHub
/// @param _toAssetHash the expected asset hash on Switcheo TradeHub
function _validateAssetRegistration(
        address _assetHash,
        bytes memory _proxyAddress,
        bytes memory _toAssetHash
    )
        private
        view
    {
        require(_proxyAddress.length == 20, "Invalid proxyAddress");
        bytes32 value = keccak256(abi.encodePacked(
            _proxyAddress,
            _toAssetHash
        ));
        require(registry[_assetHash] == value, "Asset not registered");
    }
// Solidity 0.6.12
/// @dev validates the asset registration and calls the CCM contract
function _lock(
        address _fromAssetHash,
        bytes memory _targetProxyHash,
        bytes memory _toAssetHash,
        bytes memory _toAddress,
        uint256 _amount,
        uint256 _feeAmount,
        bytes memory _feeAddress
    )
        private
    {
        require(_targetProxyHash.length == 20, "Invalid targetProxyHash");
        require(_toAssetHash.length > 0, "Empty toAssetHash");
        require(_toAddress.length > 0, "Empty toAddress");
        require(_amount > 0, "Amount must be more than zero");
        require(_feeAmount < _amount, "Fee amount cannot be greater than amount");

        _validateAssetRegistration(_fromAssetHash, _targetProxyHash, _toAssetHash);

        TransferTxArgs memory txArgs = TransferTxArgs({
            fromAssetHash: Utils.addressToBytes(_fromAssetHash),
            toAssetHash: _toAssetHash,
            toAddress: _toAddress,
            amount: _amount,
            feeAmount: _feeAmount,
            feeAddress: _feeAddress,
            fromAddress: abi.encodePacked(msg.sender),
            nonce: _getNextNonce()
        });

        bytes memory txData = _serializeTransferTxArgs(txArgs);
        CCM ccm = _getCcm();
        require(
            ccm.crossChain(counterpartChainId, _targetProxyHash, "unlock", txData),
            "EthCrossChainManager crossChain executed error!"
        );

        emit LockEvent(_fromAssetHash, msg.sender, counterpartChainId, _toAssetHash, _toAddress, txData);
    }
// Solidity 0.6.12
/// @dev validate the signature for lockFromWallet
function _validateLockFromWallet(
        address _walletOwner,
        address _assetHash,
        bytes memory _targetProxyHash,
        bytes memory _toAssetHash,
        bytes memory _feeAddress,
        uint256[] memory _values,
        uint8 _v,
        bytes32[] memory _rs
    )
        private
    {
        bytes32 message = keccak256(abi.encodePacked(
            "sendTokens",
            _assetHash,
            _targetProxyHash,
            _toAssetHash,
            _feeAddress,
            _values[0],
            _values[1],
            _values[2]
        ));

        require(seenMessages[message] == false, "Message already seen");
        seenMessages[message] = true;
        _validateSignature(message, _walletOwner, _v, _rs[0], _rs[1]);
    }
// Solidity 0.6.12
/// @dev transfers funds from a Wallet contract into this contract
/// the difference between this contract's before and after balance must equal _amount
/// this is assumed to be sufficient in ensuring that the expected amount
/// of funds were transferred in
function _transferInFromWallet(
        address payable _walletAddress,
        address _assetHash,
        uint256 _amount,
        uint256 _callAmount
    )
        private
    {
        Wallet wallet = Wallet(_walletAddress);
        if (_assetHash == ETH_ASSET_HASH) {
            uint256 before = address(this).balance;

            wallet.sendETHToCreator(_callAmount);

            uint256 transferred = address(this).balance.sub(before);
            require(transferred == _amount, "ETH transferred does not match the expected amount");
            return;
        }

        ERC20 token = ERC20(_assetHash);
        uint256 before = token.balanceOf(address(this));

        wallet.sendERC20ToCreator(_assetHash, _callAmount);

        uint256 transferred = token.balanceOf(address(this)).sub(before);
        require(transferred == _amount, "Tokens transferred does not match the expected amount");
    }
// Solidity 0.6.12
/// @dev transfers funds from an address into this contract
/// for ETH transfers, we only check that msg.value == _amount, and _callAmount is ignored
/// for token transfers, the difference between this contract's before and after balance must equal _amount
/// these checks are assumed to be sufficient in ensuring that the expected amount
/// of funds were transferred in
function _transferIn(
        address _assetHash,
        uint256 _amount,
        uint256 _callAmount
    )
        private
    {
        if (_assetHash == ETH_ASSET_HASH) {
            require(msg.value == _amount, "ETH transferred does not match the expected amount");
            return;
        }

        ERC20 token = ERC20(_assetHash);
        uint256 before = token.balanceOf(address(this));
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(
                token.transferFrom.selector,
                msg.sender,
                address(this),
                _callAmount
            )
        );
        uint256 transferred = token.balanceOf(address(this)).sub(before);
        require(transferred == _amount, "Tokens transferred does not match the expected amount");
    }
// Solidity 0.6.12
/// @dev transfers funds from this contract to the _toAddress
function _transferOut(
        address _toAddress,
        address _assetHash,
        uint256 _amount
    )
        private
    {
        if (_assetHash == ETH_ASSET_HASH) {
            // we use `call` here since the _receivingAddress could be a contract
            // see https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/
            // for more info
            (bool success,  ) = _toAddress.call{value: _amount}("");
            require(success, "Transfer failed");
            return;
        }

        ERC20 token = ERC20(_assetHash);
        _callOptionalReturn(
            token,
            abi.encodeWithSelector(
                token.transfer.selector,
                _toAddress,
                _amount
            )
        );
    }
// Solidity 0.6.12
/// @dev validates a signature against the specified user address
function _validateSignature(
        bytes32 _message,
        address _user,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    )
        private
        pure
    {
        bytes32 prefixedMessage = keccak256(abi.encodePacked(
            "\x19Ethereum Signed Message:\n32",
            _message
        ));

        require(
            _user == ecrecover(prefixedMessage, _v, _r, _s),
            "Invalid signature"
        );
    }
// Solidity 0.8.10
/**
 * @dev Mint function
 */
function mint(
        uint8 _quantity,
        uint256 _fromTimestamp,
        uint256 _toTimestamp,
        uint8 _maxQuantity,
        bytes calldata _signature
    ) external payable callerIsUser {
        bytes32 messageHash = generateMessageHash(msg.sender, _fromTimestamp, _toTimestamp, _maxQuantity);
        address recoveredWallet = ECDSA.recover(messageHash, _signature);

        require(recoveredWallet == signerAddress, "Invalid signature for the caller");
        require(block.timestamp >= _fromTimestamp, "Too early to mint");
        require(block.timestamp <= _toTimestamp, "The signature has expired");

        QueensAndKingsAvatars qakContract = QueensAndKingsAvatars(avatarContractAddress);
        uint16 tmpTotalSupply = qakContract.totalSupply();

        uint256 tokensLeft = totalAvatars - tmpTotalSupply;
        require(tokensLeft > 0, "No tokens left to be minted");

        if (_quantity + mintsPerUser[msg.sender] > _maxQuantity) {
            _quantity = _maxQuantity - mintsPerUser[msg.sender];
        }

        if (_quantity > tokensLeft) {
            _quantity = uint8(tokensLeft);
        }

        uint256 totalMintPrice = mintPrice * _quantity;
        require(msg.value >= totalMintPrice, "Not enough Ether provided to mint");

        if (msg.value > totalMintPrice) {
            payable(msg.sender).transfer(msg.value - totalMintPrice);
        }

        require(_quantity != 0, "Address mint limit reached");

        mintsPerUser[msg.sender] += _quantity;

        for (uint16 i; i < _quantity; i++) {
            uint16 _tokenId = _getTokenToBeMinted(tmpTotalSupply);
            qakContract.mint(_tokenId, msg.sender);
            tmpTotalSupply++;
        }
    }
// Solidity 0.8.10
/**
 * @dev mint to address
 */
function mintTo(address[] memory _addresses) external {
        require(msg.sender == sAddress, "Caller is not allowed to mint");
        require(_addresses.length > 0, "At least one token should be minted");
        require(sMintedTokens + _addresses.length <= sMintLimit, "Mint limit reached");

        QueensAndKingsAvatars qakContract = QueensAndKingsAvatars(avatarContractAddress);
        uint16 tmpTotalSupply = qakContract.totalSupply();

        sMintedTokens += uint16(_addresses.length);
        for (uint256 i; i < _addresses.length; i++) {
            qakContract.mint(_getTokenToBeMinted(tmpTotalSupply), _addresses[i]);
            tmpTotalSupply++;
        }
    }
// Solidity 0.8.10
/**
 * @dev Returns a random available token to be minted
 */
function _getTokenToBeMinted(uint16 _totalMintedTokens) private returns (uint16) {
        uint16 maxIndex = totalAvatars + sMintLimit - _totalMintedTokens;
        uint16 random = _getRandomNumber(maxIndex, _totalMintedTokens);

        uint16 tokenId = tokenMatrix[random];
        if (tokenMatrix[random] == 0) {
            tokenId = random;
        }

        tokenMatrix[maxIndex - 1] == 0 ? tokenMatrix[random] = maxIndex - 1 : tokenMatrix[random] = tokenMatrix[
            maxIndex - 1
        ];

        // IDs start from 1 instead of 0
        return tokenId + 1;
    }
// Solidity 0.8.10
/**
 * @dev Generates a pseudo-random number.
 */
function _getRandomNumber(uint16 _upper, uint16 _totalMintedTokens) private view returns (uint16) {
        uint16 random = uint16(
            uint256(
                keccak256(
                    abi.encodePacked(
                        _totalMintedTokens,
                        blockhash(block.number - 1),
                        block.coinbase,
                        block.difficulty,
                        msg.sender
                    )
                )
            )
        );

        return (random % _upper);
    }
// Solidity 0.8.7
/**
 * ROYALTY FUNCTIONS
 */
function getRoyalties(uint256) external view returns (address payable[] memory recipients, uint256[] memory bps) {
        if (_royaltyRecipient != address(0x0)) {
            recipients = new address payable[](1);
            recipients[0] = _royaltyRecipient;
            bps = new uint256[](1);
            bps[0] = _royaltyBps;
        }
        return (recipients, bps);
    }
// Solidity 0.8.2
/**
 * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
 *
 * Emits an {Upgraded} event.
 */
function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal {
        address oldImplementation = _getImplementation();

        // Initial upgrade and setup call
        _setImplementation(newImplementation);
        if (data.length > 0 || forceCall) {
            Address.functionDelegateCall(newImplementation, data);
        }

        // Perform rollback test if not already in progress
        StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
        if (!rollbackTesting.value) {
            // Trigger rollback using upgradeTo from the new implementation
            rollbackTesting.value = true;
            Address.functionDelegateCall(
                newImplementation,
                abi.encodeWithSignature(
                    "upgradeTo(address)",
                    oldImplementation
                )
            );
            rollbackTesting.value = false;
            // Check rollback was effective
            require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
            // Finally reset to the new implementation and log the upgrade
            _setImplementation(newImplementation);
            emit Upgraded(newImplementation);
        }
    }
// Solidity 0.8.10
/**
 * @dev update the default token Uri. 
 *
 * @param _before token uri before part.
 * @param _after token uri after part.
 *
 * Returns
 * - bool
 */
function updateDefaultUri(string memory _before, string memory _after) external onlyOwner returns (bool){
        beforeUri = _before; // update the before uri for Badbeat
        afterUri = _after; // update the after uri for Badbeat
        return true;
    }
// Solidity 0.8.10
/**
 * @dev creating new NFT on immutable x. 
 *
 * @param tokens  token details.
 * @param signature signature to verify.
 *
 * Returns
 * - bool
 *
 * Emits a {TransferEth} event.
 */
function buyNFT(tokenDetails calldata tokens, bytes calldata signature) public payable returns(bool){
        uint256 value = msg.value; 
        require(buyOnOff == true, "NFT minting is stopped");
        
        bool status = SignatureCheckerUpgradeable.isValidSignatureNow(owner(), tokens.signKey, signature);
        require(status == true, "You cannot mint NFT or a not whitelisted address");

        uint256 payableValue1 = uint256(30) * (msg.value)/ 100;
        payable(payoutAddress1).transfer(payableValue1);

        uint256 payableValue2 = msg.value - payableValue1;
        payable(payoutAddress2).transfer(payableValue2);
        emit TransferEth(msg.sender,payoutAddress1, payableValue1, payoutAddress2, 
        payableValue2, tokens.noOfTokens,tokens.catId,value);


        return true;
    }
// Solidity 0.8.10
/**
 * @dev mintinf function by only IMX. 
 *
 * @param user  msg.sender.
 * @param quantity number of token amount.
 * @param mintingBlob bytes32
 *
 * Returns
 * - bool
 *
 * Emits a {AssetMinted} event.
 */
function mintFor(
        address user,
        uint256 quantity,
        bytes calldata mintingBlob
    ) external onlyIMX {
        require(quantity == 1, "Mintable: invalid quantity");
        (uint256 id, bytes memory blueprint) = Minting.split(mintingBlob);
        _mintFor(user, id, blueprint);
        blueprints[id] = blueprint;
        emit AssetMinted(user, id, blueprint);
    }
// Solidity 0.8.13
/**
 ============================================
 Internal Functions
 @dev functions that can be called by inside contract
 ============================================
 */
function calculateRewards(uint128 _mintingAmount, uint128 remainingBoost, uint128 remainingSupply) internal pure returns (uint128, uint128) {
        uint128 boostRewards;
        uint128 finalMintingReward;
        uint128 removedBoost;

        unchecked {
            if (remainingBoost > _mintingAmount * 2) {
                boostRewards = _mintingAmount * 2;
                removedBoost = boostRewards;
            } else if (remainingBoost > 0) {
                boostRewards = _mintingAmount + remainingBoost;
                removedBoost = remainingBoost;
            } else {
                boostRewards = _mintingAmount;
                removedBoost = 0;
            }

            if (remainingSupply < _mintingAmount) {
                finalMintingReward = remainingSupply;
            } else {
                if (remainingSupply < boostRewards) {
                    finalMintingReward = remainingSupply;
                } else {
                    finalMintingReward = boostRewards;
                }
            }
        }

        return (finalMintingReward, removedBoost);
    }
// Solidity 0.4.24
/**
 * @dev Constructor function - Set the inbest token address
 * @param _startTime The time when InbestDistribution goes live
 * @param _companyWallet The wallet to allocate Company tokens
 */
function InbestDistribution(uint256 _startTime, address _companyWallet) public {
    require(_companyWallet != address(0));
    require(_startTime >= now);
    require(AVAILABLE_TOTAL_SUPPLY == AVAILABLE_PRESALE_SUPPLY.add(AVAILABLE_COMPANY_SUPPLY));
    startTime = _startTime;
    companyWallet = _companyWallet;
    IBST = new InbestToken();
    require(AVAILABLE_TOTAL_SUPPLY == IBST.totalSupply()); //To verify that totalSupply is correct

    // Allocate Company Supply
    uint256 tokensToAllocate = AVAILABLE_COMPANY_SUPPLY;
    AVAILABLE_COMPANY_SUPPLY = 0;
    allocations[companyWallet] = Allocation(uint8(AllocationType.COMPANY), 0, 0, tokensToAllocate, 0);
    AVAILABLE_TOTAL_SUPPLY = AVAILABLE_TOTAL_SUPPLY.sub(tokensToAllocate);
    LogNewAllocation(companyWallet, AllocationType.COMPANY, tokensToAllocate, grandTotalAllocated());
  }
// Solidity 0.4.24
/**
 * @dev Allow the owner or admins of the contract to assign a new allocation
 * @param _recipient The recipient of the allocation
 * @param _totalAllocated The total amount of IBST tokens available to the receipient (after vesting and cliff)
 */
function setAllocation (address _recipient, uint256 _totalAllocated) public onlyOwnerOrAdmin {
    require(_recipient != address(0));
    require(startTime > now); //Allocations are allowed only before starTime
    require(AVAILABLE_PRESALE_SUPPLY >= _totalAllocated); //Current allocation must be less than remaining presale supply
    require(allocations[_recipient].totalAllocated == 0 && _totalAllocated > 0); // Must be the first and only allocation for this recipient
    require(_recipient != companyWallet); // Receipient of presale allocation can't be company wallet

    // Allocate
    AVAILABLE_PRESALE_SUPPLY = AVAILABLE_PRESALE_SUPPLY.sub(_totalAllocated);
    allocations[_recipient] = Allocation(uint8(AllocationType.PRESALE), startTime.add(CLIFF), startTime.add(CLIFF).add(VESTING), _totalAllocated, 0);
    AVAILABLE_TOTAL_SUPPLY = AVAILABLE_TOTAL_SUPPLY.sub(_totalAllocated);
    LogNewAllocation(_recipient, AllocationType.PRESALE, _totalAllocated, grandTotalAllocated());
  }
// Solidity 0.4.24
/**
 * @dev Transfer a recipients available allocation to their address
 * @param _recipient The address to withdraw tokens for
 */
function transferTokens (address _recipient) public {
   require(_recipient != address(0));
   require(now >= startTime); //Tokens can't be transfered until start date
   require(_recipient != companyWallet); // Tokens allocated to COMPANY can't be withdrawn.
   require(now >= allocations[_recipient].endCliff); // Cliff period must be ended
   // Receipient can't claim more IBST tokens than allocated
   require(allocations[_recipient].amountClaimed < allocations[_recipient].totalAllocated);

   uint256 newAmountClaimed;
   if (allocations[_recipient].endVesting > now) {
     // Transfer available amount based on vesting schedule and allocation
     newAmountClaimed = allocations[_recipient].totalAllocated.mul(now.sub(allocations[_recipient].endCliff)).div(allocations[_recipient].endVesting.sub(allocations[_recipient].endCliff));
   } else {
     // Transfer total allocated (minus previously claimed tokens)
     newAmountClaimed = allocations[_recipient].totalAllocated;
   }

   //Transfer
   uint256 tokensToTransfer = newAmountClaimed.sub(allocations[_recipient].amountClaimed);
   allocations[_recipient].amountClaimed = newAmountClaimed;
   require(IBST.transfer(_recipient, tokensToTransfer));
   grandTotalClaimed = grandTotalClaimed.add(tokensToTransfer);
   LogIBSTClaimed(_recipient, allocations[_recipient].allocationType, tokensToTransfer, newAmountClaimed, grandTotalClaimed);
 }
// Solidity 0.4.24
/**
 * @dev Transfer IBST tokens from Company allocation to reicipient address - Only owner and admins can execute
 * @param _recipient The address to transfer tokens for
 * @param _tokensToTransfer The amount of IBST tokens to transfer
 */
function manualContribution(address _recipient, uint256 _tokensToTransfer) public onlyOwnerOrAdmin {
   require(_recipient != address(0));
   require(_recipient != companyWallet); // Company can't withdraw tokens for itself
   require(_tokensToTransfer > 0); // The amount must be valid
   require(now >= startTime); // Tokens cant't be transfered until start date
   //Company can't trasnfer more tokens than allocated
   require(allocations[companyWallet].amountClaimed.add(_tokensToTransfer) <= allocations[companyWallet].totalAllocated);

   //Transfer
   allocations[companyWallet].amountClaimed = allocations[companyWallet].amountClaimed.add(_tokensToTransfer);
   require(IBST.transfer(_recipient, _tokensToTransfer));
   grandTotalClaimed = grandTotalClaimed.add(_tokensToTransfer);
   LogIBSTClaimed(_recipient, uint8(AllocationType.COMPANY), _tokensToTransfer, allocations[companyWallet].amountClaimed, grandTotalClaimed);
 }