lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.17
/// @param _amount amount in BASED to deposit
function deposit(uint _amount) public {
        require(_amount > 0, "Nothing to deposit");

        uint _pool = balance();
        based.transferFrom(msg.sender, address(this), _amount);
        uint _after = balance();
        _amount = _after.sub(_pool); // Additional check for deflationary baseds
        uint shares = 0;
        if (totalSupply() == 0) {
            shares = _amount;
        } else {
            shares = (_amount.mul(totalSupply())).div(_pool);
        }
        _mint(msg.sender, shares);
    }
// Solidity 0.5.17
/**
 	 * Passthrough to `Lockup.difference` function.
 	 */
function difference(
		WithdrawStorage withdrawStorage,
		address _property,
		address _user
	)
		private
		view
		returns (
			uint256 _reward,
			uint256 _holdersAmount,
			uint256 _holdersPrice,
			uint256 _interestAmount,
			uint256 _interestPrice
		)
	{
		/**
		 * Gets and passes the last recorded cumulative sum of the maximum mint amount.
		 */
		uint256 _last = withdrawStorage.getLastCumulativeGlobalHoldersPrice(
			_property,
			_user
		);
		return ILockup(config().lockup()).difference(_property, _last);
	}
// Solidity 0.5.17
/**
 	 * Returns the holder reward.
 	 */
function _calculateAmount(address _property, address _user)
		private
		view
		returns (uint256 _amount, uint256 _price)
	{
		WithdrawStorage withdrawStorage = getStorage();

		/**
		 * Gets the latest cumulative sum of the maximum mint amount,
		 * and the difference to the previous withdrawal of holder reward unit price.
		 */
		(uint256 reward, , uint256 _holdersPrice, , ) = difference(
			withdrawStorage,
			_property,
			_user
		);

		/**
		 * Gets the ownership ratio of the passed user and the Property.
		 */
		uint256 balance = ERC20Mintable(_property).balanceOf(_user);

		/**
		 * Multiplied by the number of tokens to the holder reward unit price.
		 */
		uint256 value = _holdersPrice.mul(balance);

		/**
		 * Returns the result after adjusted decimals to 10^18, and the latest cumulative sum of the maximum mint amount.
		 */
		return (value.divBasis().divBasis(), reward);
	}
// Solidity 0.5.17
/**
 	 * Returns the total rewards currently available for withdrawal. (For calling from inside the contract)
 	 */
function _calculateWithdrawableAmount(address _property, address _user)
		private
		view
		returns (uint256 _amount, uint256 _price)
	{
		/**
		 * Gets the latest withdrawal reward amount.
		 */
		(uint256 _value, uint256 price) = _calculateAmount(_property, _user);

		/**
		 * If the passed Property has not authenticated, returns always 0.
		 */
		if (
			IMetricsGroup(config().metricsGroup()).hasAssets(_property) == false
		) {
			return (0, price);
		}

		/**
		 * Gets the reward amount of before DIP4.
		 */
		uint256 legacy = __legacyWithdrawableAmount(_property, _user);

		/**
		 * Gets the reward amount in saved without withdrawal and returns the sum of all values.
		 */
		uint256 value = _value
			.add(getStorage().getPendingWithdrawal(_property, _user))
			.add(legacy);
		return (value, price);
	}
// Solidity 0.5.17
/**
 	 * Returns the cumulative sum of the holder rewards of the passed Property.
 	 */
function calculateTotalWithdrawableAmount(address _property)
		external
		view
		returns (uint256)
	{
		(, uint256 _amount, , , ) = ILockup(config().lockup()).difference(
			_property,
			0
		);

		/**
		 * Adjusts decimals to 10^18 and returns the result.
		 */
		return _amount.divBasis().divBasis();
	}
// Solidity 0.5.17
/**
 	 * Returns the reward amount of the calculation model before DIP4.
 	 * It can be calculated by subtracting "the last cumulative sum of reward unit price" from
 	 * "the current cumulative sum of reward unit price," and multiplying by the balance of the user.
 	 */
function __legacyWithdrawableAmount(address _property, address _user)
		private
		view
		returns (uint256)
	{
		WithdrawStorage withdrawStorage = getStorage();
		uint256 _last = withdrawStorage.getLastWithdrawalPrice(
			_property,
			_user
		);
		uint256 price = withdrawStorage.getCumulativePrice(_property);
		uint256 priceGap = price.sub(_last);
		uint256 balance = ERC20Mintable(_property).balanceOf(_user);
		uint256 value = priceGap.mul(balance);
		return value.divBasis();
	}
// Solidity 0.5.13
/**
 * @notice Approves tokens from signatory to be spent by `spender`
 * @param spender The address to receive the tokens
 * @param rawAmount The amount of tokens to be sent to spender
 * @param nonce The contract state required to match the signature
 * @param expiry The time at which to expire the signature
 * @param v The recovery byte of the signature
 * @param r Half of the ECDSA signature pair
 * @param s Half of the ECDSA signature pair
 */
function approveBySig(address spender, uint rawAmount, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) public {
        bytes32 structHash = keccak256(abi.encode(APPROVE_TYPE_HASH, spender, rawAmount, nonce, expiry));
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
        address signatory = ecrecover(digest, v, r, s);
        require(signatory != address(0), "DMG::approveBySig: invalid signature");
        require(nonce == nonces[signatory]++, "DMG::approveBySig: invalid nonce");
        require(now <= expiry, "DMG::approveBySig: signature expired");

        uint128 amount;
        if (rawAmount == uint(- 1)) {
            amount = uint128(- 1);
        } else {
            amount = SafeBitMath.safe128(rawAmount, "DMG::approveBySig: amount exceeds 128 bits");
        }
        _approveTokens(signatory, spender, amount);
    }
// Solidity 0.6.12
// these are for communication from router to gateway
function encodeFromRouterToGateway(address _from, bytes calldata _data)
        internal
        pure
        returns (bytes memory res)
    {
        // abi decode may revert, but the encoding is done by L1 gateway, so we trust it
        return abi.encode(_from, _data);
    }
// Solidity 0.4.20
/**
 * Multiply two uint256 values, throw in case of overflow.
 *
 * @param x first value to multiply
 * @param y second value to multiply
 * @return x * y
 */
function safeMul (uint256 x, uint256 y)
  pure internal
  returns (uint256 z) {
    if (y == 0) return 0; // Prevent division by zero at the next line
    assert (x <= MAX_UINT256 / y);
    return x * y;
  }
// Solidity 0.4.20
/**
 * Transfer given number of tokens from message sender to given recipient.
 *
 * @param _to address to transfer tokens to the owner of
 * @param _value number of tokens to transfer to the owner of given address
 * @return true if tokens were transferred successfully, false otherwise
 */
function transfer (address _to, uint256 _value)
  public returns (bool success) {
    uint256 fromBalance = accounts [msg.sender];
    if (fromBalance < _value) return false;
    if (_value > 0 && msg.sender != _to) {
      accounts [msg.sender] = safeSub (fromBalance, _value);
      accounts [_to] = safeAdd (accounts [_to], _value);
    }
    Transfer (msg.sender, _to, _value);
    return true;
  }
// Solidity 0.4.20
/**
 * Burn given number of tokens belonging to message sender.
 *
 * @param _value number of tokens to burn
 * @return true on success, false on error
 */
function burnTokens (uint256 _value) public returns (bool success) {
    if (_value > accounts [msg.sender]) return false;
    else if (_value > 0) {
      accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
      tokenCount = safeSub (tokenCount, _value);

      Transfer (msg.sender, address (0), _value);
      return true;
    } else return true;
  }
// Solidity 0.8.10
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
        require(!paused, "the contract is paused");
        uint256 supply = totalSupply();
        require(_mintAmount > 0, "need to mint at least 1 NFT");
        require(
            _mintAmount <= maxMintAmount,
            "max mint amount per session exceeded"
        );
        require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

        /// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
        if (msg.sender != owner()) {
            if (onlyWhitelisted == true) {
                require(isWhitelisted(msg.sender), "user is not whitelisted");
                uint256 ownerMintedCount = addressMintedBalance[msg.sender];
                require(
                    ownerMintedCount + _mintAmount <= nftPerAddressLimit,
                    "max NFT per address exceeded"
                );
            }
            /// @notice Address balance should be greater or equal to the mint amount
            require(msg.value >= cost * _mintAmount, "insufficient funds");
        }

        for (uint256 i = 1; i <= _mintAmount; i++) {
            addressMintedBalance[msg.sender]++;
            _safeMint(msg.sender, supply + i);
        }
    }
// Solidity 0.8.10
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
        public
        view
        returns (uint256[] memory)
    {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
        for (uint256 i; i < ownerTokenCount; i++) {
            tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokenIds;
    }
// Solidity 0.8.10
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        if (revealed == false) {
            return notRevealedUri;
        }

        string memory currentBaseURI = _baseURI();
        return
            bytes(currentBaseURI).length > 0
                ? string(
                    abi.encodePacked(
                        currentBaseURI,
                        tokenId.toString(),
                        baseExtension
                    )
                )
                : "";
    }
// Solidity 0.8.10
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
        /// @notice Donate 10% to Assemble Pittsburgh
        (bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
            .call{value: (address(this).balance * 10) / 100}("");
        require(assemble);

        /// @notice Donate 10% to Black Girls Code
        (bool blackGirls, ) = payable(
            0x11708796f919758A0A0Af6B801E8F45382D5E2F3
        ).call{value: (address(this).balance * 10) / 100}("");
        require(blackGirls);

        /// @notice Donate 10% to Hack Club
        (bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
            .call{value: (address(this).balance * 10) / 100}("");
        require(hackClub);

        (bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
            .call{value: address(this).balance}("");
        require(superboys);
    }
// Solidity 0.6.12
/**
 * @notice internal utility function used to handle when no contract is deployed at expected address
 */
function handleNoContract(
        address _l1Token,
        address, /* expectedL2Address */
        address _from,
        address, /* _to */
        uint256 _amount,
        bytes memory /* gatewayData */
    ) internal override returns (bool shouldHalt) {
        // it is assumed that the custom token is deployed in the L2 before deposits are made
        // trigger withdrawal
        // we don't need the return value from triggerWithdrawal since this is forcing a withdrawal back to the L1
        // instead of composing with a L2 dapp
        triggerWithdrawal(_l1Token, address(this), _from, _amount, "");
        return true;
    }
// Solidity 0.6.12
/**
 * @notice Allows L1 Token contract to trustlessly register its custom L2 counterpart.
 * param _l2Address counterpart address of L1 token
 * param _maxGas max gas for L2 retryable exrecution
 * param _gasPriceBid gas price for L2 retryable ticket
 * param  _maxSubmissionCost base submission cost  L2 retryable tick3et
 * param _creditBackAddress address for crediting back overpayment of _maxSubmissionCost
 * return Retryable ticket ID
 */
function registerTokenToL2(
        address _l2Address,
        uint256 _maxGas,
        uint256 _gasPriceBid,
        uint256 _maxSubmissionCost,
        address _creditBackAddress
    ) public payable returns (uint256) {
        require(
            ArbitrumEnabledToken(msg.sender).isArbitrumEnabled() == uint8(0xa4b1),
            "NOT_ARB_ENABLED"
        );

        address currL2Addr = l1ToL2Token[msg.sender];
        if (currL2Addr != address(0)) {
            // if token is already set, don't allow it to set a different L2 address
            require(currL2Addr == _l2Address, "NO_UPDATE_TO_DIFFERENT_ADDR");
        }

        l1ToL2Token[msg.sender] = _l2Address;

        address[] memory l1Addresses = new address[](1);
        address[] memory l2Addresses = new address[](1);
        l1Addresses[0] = msg.sender;
        l2Addresses[0] = _l2Address;

        emit TokenSet(l1Addresses[0], l2Addresses[0]);

        bytes memory _data = abi.encodeWithSelector(
            L2CustomGateway.registerTokenFromL1.selector,
            l1Addresses,
            l2Addresses
        );

        return
            sendTxToL2(
                inbox,
                counterpartGateway,
                _creditBackAddress,
                msg.value,
                0,
                _maxSubmissionCost,
                _maxGas,
                _gasPriceBid,
                _data
            );
    }
// Solidity 0.6.12
/**
 * @notice Allows owner to force register a custom L1/L2 token pair.
 * @dev _l1Addresses[i] counterpart is assumed to be _l2Addresses[i]
 * @param _l1Addresses array of L1 addresses
 * @param _l2Addresses array of L2 addresses
 * @param _maxGas max gas for L2 retryable exrecution
 * @param _gasPriceBid gas price for L2 retryable ticket
 * @param  _maxSubmissionCost base submission cost  L2 retryable tick3et
 * @return Retryable ticket ID
 */
function forceRegisterTokenToL2(
        address[] calldata _l1Addresses,
        address[] calldata _l2Addresses,
        uint256 _maxGas,
        uint256 _gasPriceBid,
        uint256 _maxSubmissionCost
    ) external payable returns (uint256) {
        require(msg.sender == owner, "ONLY_OWNER");
        require(_l1Addresses.length == _l2Addresses.length, "INVALID_LENGTHS");

        for (uint256 i = 0; i < _l1Addresses.length; i++) {
            // here we assume the owner checked both addresses offchain before force registering
            // require(address(_l1Addresses[i]).isContract(), "MUST_BE_CONTRACT");
            l1ToL2Token[_l1Addresses[i]] = _l2Addresses[i];
            emit TokenSet(_l1Addresses[i], _l2Addresses[i]);
        }

        bytes memory _data = abi.encodeWithSelector(
            L2CustomGateway.registerTokenFromL1.selector,
            _l1Addresses,
            _l2Addresses
        );

        return
            sendTxToL2(
                inbox,
                counterpartGateway,
                msg.sender,
                msg.value,
                0,
                _maxSubmissionCost,
                _maxGas,
                _gasPriceBid,
                _data
            );
    }
// Solidity 0.7.1
/**
 * @dev Returns the protocol fee amount to charge for a flash loan of `amount`.
 */
function _calculateFlashLoanFeeAmount(uint256 amount) internal view returns (uint256) {
        // Fixed point multiplication introduces error: we round up, which means in certain scenarios the charged
        // percentage can be slightly higher than intended.
        uint256 percentage = getProtocolFeesCollector().getFlashLoanFeePercentage();
        return FixedPoint.mulUp(amount, percentage);
    }
// Solidity 0.7.1
/**
 * @dev Extracts the signature parameters from extra calldata.
 *
 * This function returns bogus data if no signature is included. This is not a security risk, as that data would not
 * be considered a valid signature in the first place.
 */
function _signature()
        internal
        pure
        returns (
            uint8 v,
            bytes32 r,
            bytes32 s
        )
    {
        // v, r and s are appended after the signature deadline, in that order.
        v = uint8(uint256(_decodeExtraCalldataWord(0x20)));
        r = _decodeExtraCalldataWord(0x40);
        s = _decodeExtraCalldataWord(0x60);
    }
// Solidity 0.5.10
/**
 * @dev Allows this contract to make approve call for a token
 * This method is expected to be called using externalCall method.
 * @param token The address of the token
 * @param to The address of the spender
 * @param amount The amount to be approved
 */
function approve(
        address token,
        address to,
        uint256 amount
    )
    external
    onlySelf
    {
        require(amount > 0, "Amount should be greater than 0!!");
        //1. Check for valid whitelisted address
        require(
            isWhitelisted(to),
            "AugustusSwapper: Not a whitelisted address!!"
        );

        //2. Check for ETH address
        if (token != ETH_ADDRESS) {
            //3. Approve
            IERC20 _token = IERC20(token);
            _token.safeApprove(to, amount);
        }

    }
// Solidity 0.5.10
/**
 * @dev The function which performs the actual swap.
 * The call data to the actual exchanges must be built offchain
 * and then sent to this method. It will be call those external exchanges using
 * data passed through externalCall function
 * It is a nonreentrant function
 * @param sourceToken Address of the source token
 * @param destinationToken Address of the destination token
 * @param sourceAmount Amount of source tokens to be swapped
 * @param minDestinationAmount Minimu destination token amount expected out of this swap
 * @param callees Address of the external callee. This will also contain address of exchanges
 * where actual swap will happen
 * @param exchangeData Concatenated data to be sent in external call to the above callees
 * @param startIndexes start index of calldata in above data structure for each callee
 * @param values Amount of ethers to be sent in external call to each callee
 * @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
 */
function swap(
        address sourceToken,
        address destinationToken,
        uint256 sourceAmount,
        uint256 minDestinationAmount,
        address[] memory callees,
        bytes memory exchangeData,
        uint256[] memory startIndexes,
        uint256[] memory values,
        string memory referrer,
        uint256 mintPrice
    )
    public
    payable
    whenNotPaused
    nonReentrant
    {
        uint receivedAmount = performSwap(
            sourceToken,
            destinationToken,
            sourceAmount,
            minDestinationAmount,
            callees,
            exchangeData,
            startIndexes,
            values,
            mintPrice
        );

        transferTokens(destinationToken, msg.sender, receivedAmount);

        emit Swapped(
            msg.sender,
            sourceToken,
            destinationToken,
            sourceAmount,
            receivedAmount,
            referrer
        );
    }
// Solidity 0.5.10
/**
 * @dev Helper method to refund gas using gas tokens
 */
function refundGas(uint256 initialGas, uint256 mintPrice) private {

        uint256 mintBase = 32254;
        uint256 mintToken = 36543;
        uint256 freeBase = 14154;
        uint256 freeToken = 6870;
        uint256 reimburse = 24000;

        uint256 tokens = initialGas.sub(
            gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
        );

        uint256 mintCost = mintBase.add(tokens.mul(mintToken));
        uint256 freeCost = freeBase.add(tokens.mul(freeToken));
        uint256 maxreimburse = tokens.mul(reimburse);

        uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
            mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
        );

        if (efficiency > 100) {
            freeGasTokens(tokens);
        }
    }
// Solidity 0.5.10
/**
 * @dev Helper method to free gas tokens
 */
function freeGasTokens(uint256 tokens) private {

        uint256 tokensToFree = tokens;
        uint256 safeNumTokens = 0;
        uint256 gas = gasleft();

        if (gas >= 27710) {
            safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
        }

        if (tokensToFree > safeNumTokens) {
            tokensToFree = safeNumTokens;
        }

        uint256 gasTokenBal = _gasToken.balanceOf(address(this));

        if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
            _gasToken.freeUpTo(tokensToFree);
        }

    }
// Solidity 0.5.10
/**
 * @dev Helper method to calculate fees
 * @param receivedAmount Received amount of tokens
 */
function calculateFee(
        address sourceToken,
        uint256 receivedAmount,
        uint256 calleesLength
    )
    private
    view
    returns (uint256)
    {
        uint256 fee = 0;
        if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
            return 0;
        }

        else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
            return 0;
        }

        if (_fee > 0) {
            fee = receivedAmount.mul(_fee).div(10000);
        }
        return fee;
    }
// Solidity 0.5.10
/**
 * @dev Source take from GNOSIS MultiSigWallet
 * @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
 */
function externalCall(
        address destination,
        uint256 value,
        uint256 dataOffset,
        uint dataLength,
        bytes memory data
    )
    private
    returns (bool)
    {
        bool result = false;
        assembly {
            let x := mload(0x40)   // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)

            let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
            result := call(
            sub(gas, 34710), // 34710 is the value that solidity is currently emitting
            // It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
            // callNewAccountGas (25000, in case the destination address does not exist and needs creating)
            destination,
            value,
            add(d, dataOffset),
            dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
            x,
            0                  // Output is ignored, therefore the output size is zero
            )
        }
        return result;
    }
// Solidity 0.7.1
/**
 * @dev Returns the original calldata, without the extra bytes containing the signature.
 *
 * This function returns bogus data if no signature is included.
 */
function _calldata() internal pure returns (bytes memory result) {
        result = msg.data; // A calldata to memory assignment results in memory allocation and copy of contents.
        if (result.length > _EXTRA_CALLDATA_LENGTH) {
            // solhint-disable-next-line no-inline-assembly
            assembly {
                // We simply overwrite the array length with the reduced one.
                mstore(result, sub(calldatasize(), _EXTRA_CALLDATA_LENGTH))
            }
        }
    }