lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.4
/**
 * @notice enable spender to spend tokens on behalf of holder
 * @param holder address on whose behalf tokens may be spent
 * @param spender recipient of allowance
 * @param amount quantity of tokens approved for spending
 */
function _approve (
    address holder,
    address spender,
    uint amount
  ) virtual internal {
    require(holder != address(0), 'ERC20: approve from the zero address');
    require(spender != address(0), 'ERC20: approve to the zero address');

    ERC20BaseStorage.layout().allowances[holder][spender] = amount;

    emit Approval(holder, spender, amount);
  }
// Solidity 0.8.4
/**
 * @notice mint tokens for given account
 * @param account recipient of minted tokens
 * @param amount quantity of tokens minted
 */
function _mint (
    address account,
    uint amount
  ) virtual internal {
    require(account != address(0), 'ERC20: mint to the zero address');

    _beforeTokenTransfer(address(0), account, amount);

    ERC20BaseStorage.Layout storage l = ERC20BaseStorage.layout();
    l.totalSupply += amount;
    l.balances[account] += amount;

    emit Transfer(address(0), account, amount);
  }
// Solidity 0.8.4
/**
 * @notice burn tokens held by given account
 * @param account holder of burned tokens
 * @param amount quantity of tokens burned
 */
function _burn (
    address account,
    uint amount
  ) virtual internal {
    require(account != address(0), 'ERC20: burn from the zero address');

    _beforeTokenTransfer(account, address(0), amount);

    ERC20BaseStorage.Layout storage l = ERC20BaseStorage.layout();
    uint256 balance = l.balances[account];
    require(balance >= amount, "ERC20: burn amount exceeds balance");
    unchecked {
      l.balances[account] = balance - amount;
    }
    l.totalSupply -= amount;

    emit Transfer(account, address(0), amount);
  }
// Solidity 0.8.4
/**
 * @notice transfer tokens from holder to recipient
 * @param holder owner of tokens to be transferred
 * @param recipient beneficiary of transfer
 * @param amount quantity of tokens transferred
 */
function _transfer (
    address holder,
    address recipient,
    uint amount
  ) virtual internal {
    require(holder != address(0), 'ERC20: transfer from the zero address');
    require(recipient != address(0), 'ERC20: transfer to the zero address');

    _beforeTokenTransfer(holder, recipient, amount);

    ERC20BaseStorage.Layout storage l = ERC20BaseStorage.layout();
    uint256 holderBalance = l.balances[holder];
    require(holderBalance >= amount, 'ERC20: transfer amount exceeds balance');
    unchecked {
      l.balances[holder] = holderBalance - amount;
    }
    l.balances[recipient] += amount;

    emit Transfer(holder, recipient, amount);
  }
// Solidity 0.7.5
/**
 @notice stake GWS to enter warmup
 @param _amount uint
 @return bool
 */
function stake( uint _amount, address _recipient ) external returns ( bool ) {
        if( initialStake[ _recipient ] == 0 ) {
            initialStake[ _recipient ] = epoch.number.add(initialUnstakeBlock);
        }
        
        rebase();

        IERC20( GWS ).safeTransferFrom( msg.sender, address(this), _amount );

        Claim memory info = warmupInfo[ _recipient ];
        require( !info.lock, "Deposits for account are locked" );


        warmupInfo[ _recipient ] = Claim ({
            deposit: info.deposit.add( _amount ),
            gons: info.gons.add( IsGWS( sGWS ).gonsForBalance( _amount ) ),
            expiry: epoch.number.add( warmupPeriod ),
            lock: false
        });

        IERC20( sGWS ).safeTransfer( warmupContract, _amount );
        return true;
    }
// Solidity 0.7.5
/**
 @notice retrieve sGWS from warmup
 @param _recipient address
 */
function claim ( address _recipient ) public {
        Claim memory info = warmupInfo[ _recipient ];
        if ( epoch.number >= info.expiry && info.expiry != 0 ) {
            delete warmupInfo[ _recipient ];
            IWarmup( warmupContract ).retrieve( _recipient, IsGWS( sGWS ).balanceForGons( info.gons ) );
        }
    }
// Solidity 0.7.5
/**
 @notice forfeit sGWS in warmup and retrieve GWS
 */
function forfeit() external {
        Claim memory info = warmupInfo[ msg.sender ];
        delete warmupInfo[ msg.sender ];

        IWarmup( warmupContract ).retrieve( address(this), IsGWS( sGWS ).balanceForGons( info.gons ) );
        IERC20( GWS ).safeTransfer( msg.sender, info.deposit );
    }
// Solidity 0.7.5
/**
 @notice redeem sGWS for GWS
 @param _amount uint
 @param _trigger bool
 */
function unstake( uint _amount, bool _trigger ) external {
        require( epoch.number >= initialStake[ msg.sender ] , 'Has not reached the initial unstake block' );

        if ( _trigger ) {
            rebase();
        }
        IERC20( sGWS ).safeTransferFrom( msg.sender, address(this), _amount );
        IERC20( GWS ).safeTransfer( msg.sender, _amount );
    }
// Solidity 0.7.5
/**
 @notice trigger rebase if epoch over
 */
function rebase() public {
        if( epoch.endBlock <= block.number ) {

            IsGWS( sGWS ).rebase( epoch.distribute, epoch.number );

            epoch.endBlock = epoch.endBlock.add( epoch.length );
            epoch.number++;

            if ( distributor != address(0) ) {
                IDistributor( distributor ).distribute();
            }

            uint balance = contractBalance();
            uint staked = IsGWS( sGWS ).circulatingSupply();

            if( balance <= staked ) {
                epoch.distribute = 0;
            } else {
                epoch.distribute = balance.sub( staked );
            }
        }
    }
// Solidity 0.7.5
/**
 @notice sets the contract address for LP staking
 @param _contract address
 */
function setContract( CONTRACTS _contract, address _address ) external onlyManager() {
        if( _contract == CONTRACTS.DISTRIBUTOR ) { // 0
            distributor = _address;
        } else if ( _contract == CONTRACTS.WARMUP ) { // 1
            require( warmupContract == address( 0 ), "Warmup cannot be set more than once" );
            warmupContract = _address;
        } else if ( _contract == CONTRACTS.LOCKER ) { // 2
            require( locker == address(0), "Locker cannot be set more than once" );
            locker = _address;
        }
    }
// Solidity 0.5.0
/**
 * Link blockchain address with CNPJ - It can be a cliente or a supplier
 * The link still needs to be validated by BNDES
 * This method can only be called by BNDESToken contract because BNDESToken can pause.
 * @param cnpj Brazilian identifier to legal entities
 * @param idFinancialSupportAgreement contract number of financial contract with BNDES. It assumes 0 if it is a supplier.
 * @param salic contract number of financial contract with ANCINE. It assumes 0 if it is a supplier.
 * @param addr the address to be associated with the legal entity.
 * @param idProofHash The legal entities have to send BNDES a PDF where it assumes as responsible for an Ethereum account. 
 *                   This PDF is signed with eCNPJ and send to BNDES. 
 */
function registryLegalEntity(uint64 cnpj, uint64 idFinancialSupportAgreement, uint32 salic, 
        address addr, string memory idProofHash) onlyTokenAddress public { 

        // Endereço não pode ter sido cadastrado anteriormente
        require (isAvailableAccount(addr), "Endereço não pode ter sido cadastrado anteriormente");

        require (isValidHash(idProofHash), "O hash da declaração é inválido");

        legalEntitiesInfo[addr] = LegalEntityInfo(cnpj, idFinancialSupportAgreement, salic, idProofHash, BlockchainAccountState.WAITING_VALIDATION);
        
        // Não pode haver outro endereço cadastrado para esse mesmo subcrédito
        if (idFinancialSupportAgreement > 0) {
            address account = getBlockchainAccount(cnpj,idFinancialSupportAgreement);
            require (isAvailableAccount(account), "Cliente já está associado a outro endereço. Use a função Troca.");
        }
        else {
            address account = getBlockchainAccount(cnpj,0);
            require (isAvailableAccount(account), "Fornecedor já está associado a outro endereço. Use a função Troca.");
        }
        
        cnpjFSAddr[cnpj][idFinancialSupportAgreement] = addr;

        emit AccountRegistration(addr, cnpj, idFinancialSupportAgreement, salic, idProofHash);
    }
// Solidity 0.5.0
/**
 * Changes the original link between CNPJ and Ethereum account. 
 * The new link still needs to be validated by BNDES.
 * This method can only be called by BNDESToken contract because BNDESToken can pause and because there are 
 * additional instructions there.
 * @param cnpj Brazilian identifier to legal entities
 * @param idFinancialSupportAgreement contract number of financial contract with BNDES. It assumes 0 if it is a supplier.
 * @param salic contract number of financial contract with ANCINE. It assumes 0 if it is a supplier.
 * @param newAddr the new address to be associated with the legal entity
 * @param idProofHash The legal entities have to send BNDES a PDF where it assumes as responsible for an Ethereum account. 
 *                   This PDF is signed with eCNPJ and send to BNDES. 
 */
function changeAccountLegalEntity(uint64 cnpj, uint64 idFinancialSupportAgreement, uint32 salic, 
        address newAddr, string memory idProofHash) onlyTokenAddress public {

        address oldAddr = getBlockchainAccount(cnpj, idFinancialSupportAgreement);
    
        // Tem que haver um endereço associado a esse cnpj/subcrédito
        require(!isReservedAccount(oldAddr), "Não pode trocar endereço de conta reservada");

        require(!isAvailableAccount(oldAddr), "Tem que haver um endereço associado a esse cnpj/subcrédito");

        require(isAvailableAccount(newAddr), "Novo endereço não está disponível");

        require (isChangeAccountEnabled(oldAddr), "A conta atual não está habilitada para troca");

        require (isValidHash(idProofHash), "O hash da declaração é inválido");        

        require(legalEntitiesInfo[oldAddr].cnpj==cnpj 
                    && legalEntitiesInfo[oldAddr].idFinancialSupportAgreement ==idFinancialSupportAgreement, 
                    "Dados inconsistentes de cnpj ou subcrédito");

        // Aponta o novo endereço para o novo LegalEntityInfo
        legalEntitiesInfo[newAddr] = LegalEntityInfo(cnpj, idFinancialSupportAgreement, salic, idProofHash, BlockchainAccountState.WAITING_VALIDATION);

        // Apaga o mapping do endereço antigo
        legalEntitiesInfo[oldAddr].state = BlockchainAccountState.INVALIDATED_BY_CHANGE;

        // Aponta mapping CNPJ e Subcredito para newAddr
        cnpjFSAddr[cnpj][idFinancialSupportAgreement] = newAddr;

        emit AccountChange(oldAddr, newAddr, cnpj, idFinancialSupportAgreement, salic, idProofHash); 

    }
// Solidity 0.5.0
/**
 * Validates the initial registry of a legal entity or the change of its registry
 * @param addr Ethereum address that needs to be validated
 * @param idProofHash The legal entities have to send BNDES a PDF where it assumes as responsible for an Ethereum account. 
 *                   This PDF is signed with eCNPJ and send to BNDES. 
 */
function validateRegistryLegalEntity(address addr, string memory idProofHash) public {

        require(isResponsibleForRegistryValidation(msg.sender), "Somente o responsável pela validação pode validar contas");

        require(legalEntitiesInfo[addr].state == BlockchainAccountState.WAITING_VALIDATION, "A conta precisa estar no estado Aguardando Validação");

        require(keccak256(abi.encodePacked(legalEntitiesInfo[addr].idProofHash)) == keccak256(abi.encodePacked(idProofHash)), "O hash recebido é diferente do esperado");

        legalEntitiesInfo[addr].state = BlockchainAccountState.VALIDATED;

        emit AccountValidation(addr, legalEntitiesInfo[addr].cnpj, 
            legalEntitiesInfo[addr].idFinancialSupportAgreement,
            legalEntitiesInfo[addr].salic);
    }
// Solidity 0.5.0
/**
 * The transfer funcion follows ERC20 token signature. 
 * Using them, it is possible to disburse money to the client, transfer from client to supplier and redeem.
 * @param to the Ethereum address to where the money should be sent
 * @param value how much BNDESToken the supplier wants to redeem
 */
function transfer (address to, uint256 value) public whenNotPaused returns (bool) {

        address from = msg.sender;

        require(from != to, "Não pode transferir token para si mesmo");

        if (registry.isResponsibleForDisbursement(from)) {

            require(registry.isValidatedClient(to), "O endereço não pertence a um cliente ou não está validada");

            _mint(to, value);

            emit BNDESTokenDisbursement(registry.getCNPJ(to), registry.getIdLegalFinancialAgreement(to), value);

        } else { 

            if (registry.isRedemptionAddress(to)) { 

                require(registry.isValidatedSupplier(from), "A conta do endereço não pertence a um fornecedor ou não está validada");

                _burn(from, value);

                emit BNDESTokenRedemption(registry.getCNPJ(from), value);

            } else {

                // Se nem from nem to são o Banco, eh transferencia normal

                require(registry.isValidatedClient(from), "O endereço não pertence a um cliente ou não está validada");
                require(registry.isValidatedSupplier(to), "A conta do endereço não pertence a um fornecedor ou não está validada");

                _transfer(msg.sender, to, value);

                emit BNDESTokenTransfer(registry.getCNPJ(from), registry.getIdLegalFinancialAgreement(from), 
                                registry.getCNPJ(to), value);
  
            }
        }

        return true;
    }
// Solidity 0.5.0
/**
 * Using this function, the Responsible for Settlement indicates that he has made the FIAT money transfer.
 * @param redemptionTransactionHash hash of the redeem transaction in which the FIAT money settlement occurred.
 * @param receiptHash hash that proof the FIAT money transfer
 */
function notifyRedemptionSettlement(string memory redemptionTransactionHash, string memory receiptHash) 
        public whenNotPaused {
        require (registry.isResponsibleForSettlement(msg.sender), "A liquidação só não pode ser realizada pelo endereço que submeteu a transação"); 
        require (registry.isValidHash(receiptHash), "O hash do recibo é inválido");
        emit BNDESTokenRedemptionSettlement(redemptionTransactionHash, receiptHash);
    }
// Solidity 0.5.0
/**
 * Changes the original link between CNPJ and Ethereum account. 
 * The new link still needs to be validated by BNDES.
 * IMPORTANT: The BNDESTOKENs are transfered from the original to the new Ethereum address 
 * @param cnpj Brazilian identifier to legal entities
 * @param idFinancialSupportAgreement contract number of financial contract with BNDES. It assumes 0 if it is a supplier.
 * @param salic contract number of financial contract with ANCINE. It assumes 0 if it is a supplier.
 * @param idProofHash The legal entities have to send BNDES a PDF where it assumes as responsible for an Ethereum account. 
 *                   This PDF is signed with eCNPJ and send to BNDES. 
 */
function changeAccountLegalEntity(uint64 cnpj, uint64 idFinancialSupportAgreement, uint32 salic, string memory idProofHash) 
        public whenNotPaused {
        
        address oldAddr = registry.getBlockchainAccount(cnpj, idFinancialSupportAgreement);
        address newAddr = msg.sender;
        
        registry.changeAccountLegalEntity(cnpj, idFinancialSupportAgreement, salic, msg.sender, idProofHash);

        // Se há saldo no enderecoAntigo, precisa transferir
        if (balanceOf(oldAddr) > 0) {
            _transfer(oldAddr, newAddr, balanceOf(oldAddr));
        }

    }
// Solidity 0.5.17
/**
 * @notice Returns the estimated per-block borrow interest rate for this cToken after some change
 * @return The borrow interest rate per block, scaled by 1e18
 */
function estimateBorrowRatePerBlockAfterChange(uint256 change, bool repay) external view returns (uint256) {
        uint256 cashPriorNew;
        uint256 totalBorrowsNew;

        if (repay) {
            cashPriorNew = add_(getCashPrior(), change);
            totalBorrowsNew = sub_(totalBorrows, change);
        } else {
            cashPriorNew = sub_(getCashPrior(), change);
            totalBorrowsNew = add_(totalBorrows, change);
        }
        return interestRateModel.getBorrowRate(cashPriorNew, totalBorrowsNew, totalReserves);
    }
// Solidity 0.5.17
/**
 * @notice Sender borrows assets from the protocol to their own address
 * @param borrowAmount The amount of the underlying asset to borrow
 * @param isNative The amount is in native or not
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function borrowInternal(uint256 borrowAmount, bool isNative) internal nonReentrant returns (uint256) {
        uint256 error = accrueInterest();
        if (error != uint256(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
            return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED);
        }
        // borrowFresh emits borrow-specific logs on errors, so we don't need to
        return borrowFresh(msg.sender, borrowAmount, isNative);
    }
// Solidity 0.5.17
/**
 * @notice Sender repays their own borrow
 * @param repayAmount The amount to repay
 * @param isNative The amount is in native or not
 * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
 */
function repayBorrowInternal(uint256 repayAmount, bool isNative) internal nonReentrant returns (uint256, uint256) {
        uint256 error = accrueInterest();
        if (error != uint256(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
            return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0);
        }
        // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to
        return repayBorrowFresh(msg.sender, msg.sender, repayAmount, isNative);
    }
// Solidity 0.5.17
/**
 * @notice The sender liquidates the borrowers collateral.
 *  The collateral seized is transferred to the liquidator.
 * @param borrower The borrower of this cToken to be liquidated
 * @param repayAmount The amount of the underlying borrowed asset to repay
 * @param cTokenCollateral The market in which to seize collateral from the borrower
 * @param isNative The amount is in native or not
 * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.
 */
function liquidateBorrowInternal(
        address borrower,
        uint256 repayAmount,
        CTokenInterface cTokenCollateral,
        bool isNative
    ) internal nonReentrant returns (uint256, uint256) {
        uint256 error = accrueInterest();
        if (error != uint256(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed
            return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0);
        }

        error = cTokenCollateral.accrueInterest();
        if (error != uint256(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed
            return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0);
        }

        // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to
        return liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral, isNative);
    }
// Solidity 0.5.17
/**
 * @notice Accrues interest and reduces reserves by transferring from msg.sender
 * @param addAmount Amount of addition to reserves
 * @param isNative The amount is in native or not
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _addReservesInternal(uint256 addAmount, bool isNative) internal nonReentrant returns (uint256) {
        uint256 error = accrueInterest();
        if (error != uint256(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed.
            return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED);
        }

        // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to.
        (error, ) = _addReservesFresh(addAmount, isNative);
        return error;
    }
// Solidity 0.8.7
//mint a @param number of NFTs in presale
function presaleMint(uint256 number, uint8 _v, bytes32 _r, bytes32 _s) onlyValidAccess(_v,  _r, _s) public payable {
        State saleState_ = saleState();
        require(saleState_ != State.NoSale, "Sale in not open yet!");
        require(saleState_ != State.PublicSale, "Presale has closed, Check out Public Sale!");
        require(numberOfTokensPresale + number <= 750, "Not enough NFTs left to mint..");
        require(mintsPerAddress[msg.sender] + number <= 5, "Maximum 5 Mints per Address allowed!");
        require(msg.value >= mintCost(number), "Not sufficient ETH to mint this amount of NFTs");
        
        for (uint256 i = 0; i < number; i++) {
            uint256 tid = tokenId();
            _safeMint(msg.sender, tid);
            mintsPerAddress[msg.sender] += 1;
            numberOfTotalTokens += 1;
        }

    }
// Solidity 0.8.7
//mint a @param number of NFTs in public sale
function publicSaleMint(uint256 number) public payable {
        State saleState_ = saleState();
        require(saleState_ == State.PublicSale, "Public Sale in not open yet!");
        require(numberOfTotalTokens + number <= maxTotalTokens - (maxReservedMintsTeam + maxReservedMintsGiveaways - _reservedMintsTeam - _reservedMintsGiveaways), "Not enough NFTs left to mint..");
        require(number <= 5, "Maximum 5 Mints per Address allowed!");
        require(msg.value >= mintCost(number), "Not sufficient ETH to mint this amount of NFTs");


        for (uint256 i = 0; i < number; i++) {
            uint256 tid = tokenId();
            _safeMint(msg.sender, tid);
            mintsPerAddress[msg.sender] += 1;
            numberOfTotalTokens += 1;
        }
    }
// Solidity 0.8.7
//reserved NFTs for creator
function reservedMintTeam(uint number, address recipient) public onlyOwner {
        require(_reservedMintsTeam + number <= maxReservedMintsTeam, "Not enough Reserved NFTs left to mint..");

        for (uint i = 0; i < number; i++) {
            _safeMint(recipient, tokenId());
            mintsPerAddress[recipient] += 1;
            numberOfTotalTokens += 1;
            _reservedMintsTeam += 1;
        }    
        
    }
// Solidity 0.8.7
//retrieve all funds recieved from minting
function withdraw() public onlyOwner {
        uint256 balance = accountBalance();
        require(balance > 0, 'No Funds to withdraw, Balance is 0');
        
        _withdraw(shareholder5, (balance * 20) / 100);
        _withdraw(shareholder4, (balance * 20) / 100);
        _withdraw(shareholder3, (balance * 20) / 100);
        _withdraw(shareholder2, (balance * 20) / 100);
        _withdraw(shareholder1, accountBalance()); //to avoid dust eth, gets a little more than 20%
    }
// Solidity 0.8.7
//see current state of sale
//see the current state of the sale
function saleState() public view returns(State){
        if (presaleLaunchTime == 0 || paused == true) {
            return State.NoSale;
        }
        else if (publicSaleLaunchTime == 0) {
            return State.Presale;
        }
        else {
            return State.PublicSale;
        }
    }