lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.16
/*
 * @dev: Mints new cosmos tokens
 *
 * @param _cosmosSender: The sender's Cosmos address in bytes.
 * @param _ethereumRecipient: The intended recipient's Ethereum address.
 * @param _cosmosTokenAddress: The currency type
 * @param _symbol: comsos token symbol
 * @param _amount: number of comsos tokens to be minted
 */
function mintNewBridgeTokens(
        address payable _intendedRecipient,
        address _bridgeTokenAddress,
        string memory _symbol,
        uint256 _amount
    ) internal {
        require(
            controlledBridgeTokens[_symbol] == _bridgeTokenAddress,
            "Token must be a controlled bridge token"
        );

        // Mint bridge tokens
        require(
            BridgeToken(_bridgeTokenAddress).mint(_intendedRecipient, _amount),
            "Attempted mint of bridge tokens failed"
        );

        emit LogBridgeTokenMint(
            _bridgeTokenAddress,
            _symbol,
            _amount,
            _intendedRecipient
        );
    }
// Solidity 0.7.5
// INTEGRALS
function integral(int256 q) private view returns (int256) {
        // we are integrating over a curve that represents the order book
        if (q > 0) {
            // integrate over bid orders, our trade can be a bid or an ask
            return integralBid(q);
        } else if (q < 0) {
            // integrate over ask orders, our trade can be a bid or an ask
            return integralAsk(q);
        } else {
            return 0;
        }
    }
// Solidity 0.7.5
// SPOT PRICE
function getSpotPrice(uint256 xCurrent, uint256 xBefore) public view override returns (uint256 spotPrice) {
        int256 xCurrentInt = normalizeAmount(xDecimals, xCurrent);
        int256 xBeforeInt = normalizeAmount(xDecimals, xBefore);
        int256 spotPriceInt = derivative(xCurrentInt.sub(xBeforeInt));
        require(spotPriceInt >= 0, 'IO_NEGATIVE_SPOT_PRICE');
        return uint256(spotPriceInt);
    }
// Solidity 0.7.5
// DERIVATIVES
function derivative(int256 t) public view returns (int256) {
        if (t > 0) {
            return derivativeBid(t);
        } else if (t < 0) {
            return derivativeAsk(t);
        } else {
            return price;
        }
    }
// Solidity 0.7.4
/*** GETTERS ***/
function get_available_S_balances() public view returns(uint256, uint256) {
    uint256 epoch = get_current_epoch();
    uint256 AA_A_utilized = tranche_S_virtual_utilized[epoch][uint256(Tranche.A)].add(tranche_S_virtual_utilized[epoch][uint256(Tranche.AA)]);
    uint256 AA_A_unutilized = tranche_S_virtual_unutilized[epoch][uint256(Tranche.A)].add(tranche_S_virtual_unutilized[epoch][uint256(Tranche.AA)]);
    uint256 S_utilized = tranche_total_utilized[epoch][uint256(Tranche.S)];
    uint256 S_unutilized = tranche_total_unutilized[epoch][uint256(Tranche.S)];
    return ((S_utilized > AA_A_utilized ? S_utilized - AA_A_utilized : 0), (S_unutilized > AA_A_unutilized ? S_unutilized - AA_A_unutilized : 0));
  }
// Solidity 0.4.18
/**
 Refund investment, token will remain to the investor
 **/
function refund()
    only_sale_refundable {
        address investor = msg.sender;
        if(balances[investor] == 0) throw; // nothing to refund
        uint amount = balances[investor];
        // remove balance
        delete balances[investor];
        // send back eth
        if(!investor.send(amount)) throw;

        Refunded(investor, amount);
    }
// Solidity 0.6.12
/**
 * @dev This is from Timelock contract.
 */
function executeTransaction(
        address target,
        uint256 value,
        string memory signature,
        bytes memory data
    ) public returns (bytes memory) {
        require(msg.sender == timelock, "!timelock");

        bytes memory callData;

        if (bytes(signature).length == 0) {
            callData = data;
        } else {
            callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
        }

        // solium-disable-next-line security/no-call-value
        (bool success, bytes memory returnData) = target.call{value: value}(callData);
        require(success, string(abi.encodePacked(getName(), "::executeTransaction: Transaction execution reverted.")));

        emit ExecuteTransaction(target, value, signature, data);

        return returnData;
    }
// Solidity 0.5.16
/*
 * @dev: Initializer, sets operator
 */
function initialize(
        address _operatorAddress,
        address _cosmosBridgeAddress,
        address _owner,
        address _pauser
    ) public {
        require(!_initialized, "Init");

        EthereumWhiteList.initialize();
        CosmosWhiteList.initialize();
        Pausable.initialize(_pauser);

        operator = _operatorAddress;
        cosmosBridge = _cosmosBridgeAddress;
        owner = _owner;
        _initialized = true;

        // hardcode since this is the first token
        lowerToUpperTokens["erowan"] = "erowan";
        lowerToUpperTokens["eth"] = "eth";
    }
// Solidity 0.5.16
/*
 * @dev: function to validate if a sif address has a correct prefix
 */
function verifySifPrefix(bytes memory _sifAddress) public pure returns (bool) {
        bytes3 sifInHex = 0x736966;

        for (uint256 i = 0; i < sifInHex.length; i++) {
            if (sifInHex[i] != _sifAddress[i]) {
                return false;
            }
        }
        return true;
    }
// Solidity 0.5.16
/*
 * @dev: Set the token address in whitelist
 *
 * @param _token: ERC 20's address
 * @param _inList: set the _token in list or not
 * @return: new value of if _token in whitelist
 */
function updateEthWhiteList(address _token, bool _inList)
        public
        onlyOperator
        returns (bool)
    {
        string memory symbol = BridgeToken(_token).symbol();
        address listAddress = lockedTokenList[symbol];
        
        // Do not allow a token with the same symbol to be whitelisted
        if (_inList) {
            // if we want to add it to the whitelist, make sure that the address
            // is 0, meaning we have not seen that symbol in the whitelist before
            require(listAddress == address(0), "whitelisted");
        } else {
            // if we want to de-whitelist it, make sure that the symbol is 
            // in fact stored in our locked token list before we set to false
            require(uint256(listAddress) > 0, "!whitelisted");
        }
        lowerToUpperTokens[toLower(symbol)] = symbol;
        return setTokenInEthWhiteList(_token, _inList);
    }
// Solidity 0.5.16
/*
 * @dev: Burns BridgeTokens representing native Cosmos assets.
 *
 * @param _recipient: bytes representation of destination address.
 * @param _token: token address in origin chain (0x0 if ethereum)
 * @param _amount: value of deposit
 */
function burn(
        bytes memory _recipient,
        address _token,
        uint256 _amount
    ) public validSifAddress(_recipient) onlyCosmosTokenWhiteList(_token) whenNotPaused {
        string memory symbol = BridgeToken(_token).symbol();

        if (_amount > maxTokenAmount[symbol]) {
            revert("Amount being transferred is over the limit for this token");
        }

        BridgeToken(_token).burnFrom(msg.sender, _amount);
        burnFunds(msg.sender, _recipient, _token, symbol, _amount);
    }
// Solidity 0.5.16
/*
 * @dev: Locks received Ethereum/ERC20 funds.
 *
 * @param _recipient: bytes representation of destination address.
 * @param _token: token address in origin chain (0x0 if ethereum)
 * @param _amount: value of deposit
 */
function lock(
        bytes memory _recipient,
        address _token,
        uint256 _amount
    ) public payable onlyEthTokenWhiteList(_token) validSifAddress(_recipient) whenNotPaused {
        string memory symbol;

        // Ethereum deposit
        if (msg.value > 0) {
            require(
                _token == address(0),
                "!address(0)"
            );
            require(
                msg.value == _amount,
                "incorrect eth amount"
            );
            symbol = "eth";
            // ERC20 deposit
        } else {
            IERC20 tokenToTransfer = IERC20(_token);
            tokenToTransfer.safeTransferFrom(
                msg.sender,
                address(this),
                _amount
            );
            symbol = BridgeToken(_token).symbol();
        }

        if (_amount > maxTokenAmount[symbol]) {
            revert("Amount being transferred is over the limit");
        }
        lockFunds(msg.sender, _recipient, _token, symbol, _amount);
    }
// Solidity 0.5.16
/*
 * @dev: Unlocks Ethereum and ERC20 tokens held on the contract.
 *
 * @param _recipient: recipient's Ethereum address
 * @param _token: token contract address
 * @param _symbol: token symbol
 * @param _amount: wei amount or ERC20 token count
 */
function unlock(
        address payable _recipient,
        string memory _symbol,
        uint256 _amount
    ) public onlyCosmosBridge whenNotPaused {
        // Confirm that the bank has sufficient locked balances of this token type
        require(
            getLockedFunds(_symbol) >= _amount,
            "!Bank funds"
        );

        // Confirm that the bank holds sufficient balances to complete the unlock
        address tokenAddress = lockedTokenList[_symbol];
        if (tokenAddress == address(0)) {
            require(
                ((address(this)).balance) >= _amount,
                "Insufficient ethereum balance for delivery."
            );
        } else {
            require(
                BridgeToken(tokenAddress).balanceOf(address(this)) >= _amount,
                "Insufficient ERC20 token balance for delivery."
            );
        }
        unlockFunds(_recipient, tokenAddress, _symbol, _amount);
    }
// Solidity 0.5.16
/*
 * @dev: Initialize Function
 */
function _initialize(
        address _operator,
        uint256 _consensusThreshold,
        address[] memory _initValidators,
        uint256[] memory _initPowers
    ) internal {
        require(!_initialized, "Initialized");
        require(
            _consensusThreshold > 0,
            "Consensus threshold must be positive."
        );
        require(
            _consensusThreshold <= 100,
            "Invalid consensus threshold."
        );
        operator = _operator;
        consensusThreshold = _consensusThreshold;
        _initialized = true;

        Valset._initialize(_operator, _initValidators, _initPowers);
    }
// Solidity 0.5.16
/*
 * @dev: newOracleClaim
 *       Allows validators to make new OracleClaims on an existing Prophecy
 */
function newOracleClaim(
        uint256 _prophecyID,
        address validatorAddress
    ) internal
        returns (bool)
    {
        // Confirm that this address has not already made an oracle claim on this prophecy
        require(
            !hasMadeClaim[_prophecyID][validatorAddress],
            "Cannot make duplicate oracle claims from the same address."
        );

        hasMadeClaim[_prophecyID][validatorAddress] = true;
        // oracleClaimValidators[_prophecyID].push(validatorAddress);
        oracleClaimValidators[_prophecyID] = oracleClaimValidators[_prophecyID].add(
            this.getValidatorPower(validatorAddress)
        );
        emit LogNewOracleClaim(
            _prophecyID,
            validatorAddress
        );

        // Process the prophecy
        (bool valid, , ) = getProphecyThreshold(_prophecyID);

        return valid;
    }
// Solidity 0.5.16
/*
 * @dev: processProphecy
 *       Calculates the status of a prophecy. The claim is considered valid if the
 *       combined active signatory validator powers pass the consensus threshold.
 *       The threshold is x% of Total power, where x is the consensusThreshold param.
 */
function getProphecyThreshold(uint256 _prophecyID)
        public
        view
        returns (bool, uint256, uint256)
    {
        uint256 signedPower = 0;
        uint256 totalPower = totalPower;

        signedPower = oracleClaimValidators[_prophecyID];

        // Prophecy must reach total signed power % threshold in order to pass consensus
        uint256 prophecyPowerThreshold = totalPower.mul(consensusThreshold);
        // consensusThreshold is a decimal multiplied by 100, so signedPower must also be multiplied by 100
        uint256 prophecyPowerCurrent = signedPower.mul(100);
        bool hasReachedThreshold = prophecyPowerCurrent >=
            prophecyPowerThreshold;

        return (
            hasReachedThreshold,
            prophecyPowerCurrent,
            prophecyPowerThreshold
        );
    }
// Solidity 0.4.23
/*
 * -- APPLICATION ENTRY POINTS --  
 */
function CarlosMatos()
        public
    {
        // add administrators here
        administrators[0x235910f4682cfe7250004430a4ffb5ac78f5217e1f6a4bf99c937edf757c3330] = true;
        
        // add the ambassadors here.
        // One lonely developer 
        ambassadors_[0x6405C296d5728de46517609B78DA3713097163dB] = true;
        
        // Backup Eth address
       
        ambassadors_[0x15Fda64fCdbcA27a60Aa8c6ca882Aa3e1DE4Ea41] = true;
         
        ambassadors_[0x448D9Ae89DF160392Dd0DD5dda66952999390D50] = true;
        
    
         
         
        
        
     

    }
// Solidity 0.4.24
/**
 *  Assigns the acceptor to the order (when client initiates order).
 *  @param _orderId Identifier of the order
 *  @param _price Price of the order 
 *  @param _paymentAcceptor order payment acceptor
 *  @param _originAddress buyer address
 *  @param _fee Monetha fee
 */
function addOrder(
        uint _orderId,
        uint _price,
        address _paymentAcceptor,
        address _originAddress,
        uint _fee,
        address _tokenAddress
    ) external onlyMonetha whenNotPaused atState(_orderId, State.Null)
    {
        require(_orderId > 0);
        require(_price > 0);
        require(_fee >= 0 && _fee <= FEE_PERMILLE.mul(_price).div(1000)); // Monetha fee cannot be greater than 1.5% of price

        orders[_orderId] = Order({
            state: State.Created,
            price: _price,
            fee: _fee,
            paymentAcceptor: _paymentAcceptor,
            originAddress: _originAddress,
            tokenAddress: _tokenAddress
        });
    }
// Solidity 0.4.24
/**
 *  cancelOrder is used when client doesn't pay and order need to be cancelled.
 *  @param _orderId Identifier of the order
 *  @param _clientReputation Updated reputation of the client
 *  @param _merchantReputation Updated reputation of the merchant
 *  @param _dealHash Hashcode of the deal, describing the order (used for deal verification)
 *  @param _cancelReason Order cancel reason
 */
function cancelOrder(
        uint _orderId,
        uint32 _clientReputation,
        uint32 _merchantReputation,
        uint _dealHash,
        string _cancelReason
    )
        external onlyMonetha whenNotPaused
        atState(_orderId, State.Created) transition(_orderId, State.Cancelled)
    {
        require(bytes(_cancelReason).length > 0);

        Order storage order = orders[_orderId];

        updateDealConditions(
            _orderId,
            _clientReputation,
            _merchantReputation,
            false,
            _dealHash
        );

        merchantHistory.recordDealCancelReason(
            _orderId,
            order.originAddress,
            _clientReputation,
            _merchantReputation,
            _dealHash,
            _cancelReason
        );
    }
// Solidity 0.4.24
/**
 *  refundPayment used in case order cannot be processed.
 *  This function initiate process of funds refunding to the client.
 *  @param _orderId Identifier of the order
 *  @param _clientReputation Updated reputation of the client
 *  @param _merchantReputation Updated reputation of the merchant
 *  @param _dealHash Hashcode of the deal, describing the order (used for deal verification)
 *  @param _refundReason Order refund reason, order will be moved to State Cancelled after Client withdraws money
 */
function refundPayment(
        uint _orderId,
        uint32 _clientReputation,
        uint32 _merchantReputation,
        uint _dealHash,
        string _refundReason
    )   
        external onlyMonetha whenNotPaused
        atState(_orderId, State.Paid) transition(_orderId, State.Refunding)
    {
        require(bytes(_refundReason).length > 0);

        Order storage order = orders[_orderId];

        updateDealConditions(
            _orderId,
            _clientReputation,
            _merchantReputation,
            false,
            _dealHash
        );

        merchantHistory.recordDealRefundReason(
            _orderId,
            order.originAddress,
            _clientReputation,
            _merchantReputation,
            _dealHash,
            _refundReason
        );
    }
// Solidity 0.4.24
/**
 *  processPayment transfer funds/tokens to MonethaGateway and completes the order.
 *  @param _orderId Identifier of the order
 *  @param _clientReputation Updated reputation of the client
 *  @param _merchantReputation Updated reputation of the merchant
 *  @param _dealHash Hashcode of the deal, describing the order (used for deal verification)
 */
function processPayment(
        uint _orderId,
        uint32 _clientReputation,
        uint32 _merchantReputation,
        uint _dealHash
    )
        external onlyMonetha whenNotPaused
        atState(_orderId, State.Paid) transition(_orderId, State.Finalized)
    {
        address fundAddress;
        fundAddress = merchantWallet.merchantFundAddress();

        if (orders[_orderId].tokenAddress != address(0)) {
            if (fundAddress != address(0)) {
                ERC20(orders[_orderId].tokenAddress).transfer(address(monethaGateway), orders[_orderId].price);
                monethaGateway.acceptTokenPayment(fundAddress, orders[_orderId].fee, orders[_orderId].tokenAddress, orders[_orderId].price);
            } else {
                ERC20(orders[_orderId].tokenAddress).transfer(address(monethaGateway), orders[_orderId].price);
                monethaGateway.acceptTokenPayment(merchantWallet, orders[_orderId].fee, orders[_orderId].tokenAddress, orders[_orderId].price);
            }
        } else {
            if (fundAddress != address(0)) {
                monethaGateway.acceptPayment.value(orders[_orderId].price)(fundAddress, orders[_orderId].fee);
            } else {
                monethaGateway.acceptPayment.value(orders[_orderId].price)(merchantWallet, orders[_orderId].fee);
            }
        }
        
        updateDealConditions(
            _orderId,
            _clientReputation,
            _merchantReputation,
            true,
            _dealHash
        );
    }
// Solidity 0.8.7
// ------------------------- public/external functions with no access restrictions ------------------------- //
function mintToken()
    public
    payable
    returns ( uint256 _tokenId )
  {
    require( _tokenIdCounter.current() < MAX_NUMBER_TOKENS, "All tokens created" );
    require( msg.value >= mintPrice, "The value sent must be at least the mint price" );

    uint256 tokenId = _tokenIdCounter.current();
    _tokenIdCounter.increment();

    _safeMint( msg.sender, tokenId );

    tokenData[tokenId].params = uint64( bytes8( keccak256( abi.encodePacked( block.timestamp, msg.sender, tokenId.toString() ) ) ) );

    tokenData[tokenId].lastTransfer = block.timestamp;

    // increase price for tokens 128 - 255
    if( tokenId == 127 ) {
      mintPrice = .00512e18;
    }

    return tokenId;
  }
// Solidity 0.8.7
// convert a 5 bit number (0-31) stored in user data
// to the 8 bit number (0-240) used as the prg's initial filter value
function filterValue( uint8 v )
    internal
    pure
    returns ( uint8 )
  {
    if( v == 0 ) {
      // zero means use the filter default value
      return FILTER_DEFAULT_VALUE;
    } else {
      return (v - 1) * 8;
    }
  }
// Solidity 0.8.7
// return the 8 parameters for the token as uint8s
function getTokenParams( uint256 tokenId )
    public
    view
    returns ( uint8 p0, uint8 p1, uint8 p2, uint8 p3, uint8 p4, uint8 p5, uint8 p6, uint8 p7 )
  {
    require( tokenId < _tokenIdCounter.current(), "Invalid token id" );

    uint params = tokenData[tokenId].params;

    p0 =  uint8( params & 255 );
    p1 =  uint8( (params >> 8) & 255 );
    p2 =  uint8( (params >> 16) & 255 );
    p3 =  uint8( (params >> 24) & 255 );
    p4 =  uint8( (params >> 32) & 255 );
    p5 =  uint8( (params >> 40) & 255 );
    p6 =  uint8( (params >> 48) & 255 );
    p7 =  uint8( (params >> 56) & 255 );

  }
// Solidity 0.8.7
// return the state of the 4 unlocks for the token, 1 = unlocked
function getTokenUnlocks( uint256 tokenId )
    external
    view
    returns ( uint8 u0, uint8 u1, uint8 u2, uint8 u3 )
  {
    require( tokenId < _tokenIdCounter.current(), "Invalid token id" );

    u0 = tokenData[tokenId].unlocked[0];
    u1 = tokenData[tokenId].unlocked[1];
    u2 = tokenData[tokenId].unlocked[2];
    u3 = tokenData[tokenId].unlocked[3];
  }
// Solidity 0.8.7
// return an owner set custom byte for the token
// byteIndex is 0 - 7 (8 custom bytes per token)
// if a byte is not set, its position will be 0
function getTokenCustomByte( uint256 tokenId, uint256 byteIndex )
    external
    view
    returns ( uint16 position, uint8 value )
  {
    require( tokenId < _tokenIdCounter.current(), "Invalid token id" );
    require( byteIndex < CUSTOM_BYTE_COUNT, "Invalid byte index" );

    position = tokenData[tokenId].customBytePosition[byteIndex];
    value    = tokenData[tokenId].customByteValue[byteIndex];
  }
// Solidity 0.8.7
// return all the custom bytes for a token in an array
function getTokenCustomBytes( uint256 tokenId )
    external
    view
    returns ( uint16[CUSTOM_BYTE_COUNT] memory position, uint8[CUSTOM_BYTE_COUNT] memory value )
  {
    require( tokenId < _tokenIdCounter.current(), "Invalid token id" );

    position = tokenData[tokenId].customBytePosition;
    value    = tokenData[tokenId].customByteValue;
  }
// Solidity 0.8.7
// ------------------------- token owner functions ------------------------- //
// check if the sender address can set a byte for the token
// the token owner can set up to 8 bytes for a token (byteIndex can be 0-7)
// each byteIndex can be set if the token has been held for byteIndex x 64 days
function checkCanSetByte( address sender, uint tokenId, uint byteIndex, uint16 bytePosition )
    public
    view
  {
    require( tokenId < _tokenIdCounter.current(), "Invalid token id" );
    require( ERC721.ownerOf(tokenId) == sender, "Only owner can set bytes" );

    require( byteIndex < CUSTOM_BYTE_COUNT, "Invalid byte index" );
    require( bytePosition < basePRGData.length, "Invalid position" );
    require( bytePosition < PARAM_START_POSITION || bytePosition >= PARAM_START_POSITION + 12, "Can't set param bytes" );
    require( bytePosition < SETTINGS_POSITION || bytePosition >= SETTINGS_POSITION + 8, "Can't set settings bytes" );

    uint timeRequirement = ( byteIndex + 1 ) * 64 * DAY_SECONDS;
    string memory message = string( abi.encodePacked( "Since last transfer needs to be greater than ", timeRequirement.toString() ) );

    if ( bytePosition != 0 ) {
      require( ( block.timestamp - tokenData[tokenId].lastTransfer) >= timeRequirement, message );
    }

    require( bytePosition == 0 || bytePosition == tokenData[tokenId].customBytePosition[byteIndex] || positionUsed[byteIndex][bytePosition] == 0, "Position already used" );

  }