lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.2
/*
 * @param src Pointer to source
 * @param dest Pointer to destination
 * @param len Amount of memory to copy from the source
 */
function copy(uint src, uint dest, uint len) private pure {
    if (len == 0) return;

    // copy as many word sizes as possible
    for (; len >= WORD_SIZE; len -= WORD_SIZE) {
      assembly {
          mstore(dest, mload(src))
      }

      src += WORD_SIZE;
      dest += WORD_SIZE;
    }

    // left over bytes. Mask is used to remove unwanted bytes from the word
    uint mask = 256 ** (WORD_SIZE - len) - 1;
    assembly {
      let srcpart := and(mload(src), not(mask)) // zero out src
      let destpart := and(mload(dest), mask) // retrieve the bytes
      mstore(dest, or(destpart, srcpart))
    }
  }
// Solidity 0.4.8
/**
 * Finalize a succcesful crowdsale.
 *
 * The owner can triggre a call the contract that provides post-crowdsale actions, like releasing the tokens.
 */
function finalize() public inState(State.Success) onlyOwner stopInEmergency {

    // Already finalized
    if(finalized) {
      throw;
    }

    // Finalizing is optional. We only call it if we are given a finalizing agent.
    if(address(finalizeAgent) != 0) {
      finalizeAgent.finalizeCrowdsale();
    }

    finalized = true;
  }
// Solidity 0.4.8
/**
 * Crowdfund state machine management.
 *
 * We make it a function and do not assign the result to a variable, so there is no chance of the variable being stale.
 */
function getState() public constant returns (State) {
    if(finalized) return State.Finalized;
    else if (address(finalizeAgent) == 0) return State.Preparing;
    else if (!finalizeAgent.isSane()) return State.Preparing;
    else if (!pricingStrategy.isSane(address(this))) return State.Preparing;
    else if (block.timestamp < startsAt) return State.PreFunding;
    else if (block.timestamp <= endsAt && !isCrowdsaleFull()) return State.Funding;
    else if (isMinimumGoalReached()) return State.Success;
    else if (!isMinimumGoalReached() && weiRaised > 0 && loadedRefund >= weiRaised) return State.Refunding;
    else return State.Failure;
  }
// Solidity 0.4.8
/**
 * Set the contract that can call release and make the token transferable.
 *
 * Design choice. Allow reset the release agent to fix fat finger mistakes.
 */
function setReleaseAgent(address addr) onlyOwner inReleaseState(false) public {

    // We don't do interface check here as we might want to a normal wallet address to act as a release agent
    releaseAgent = addr;
  }
// Solidity 0.4.8
/**
 * Calculate the current price for buy in amount.
 *
 * @param  {uint amount} How many tokens we get
 */
function calculatePrice(uint value, uint weiRaised, uint tokensSold, address msgSender, uint decimals) public constant returns (uint) {

    uint multiplier = 10 ** decimals;
    if (weiRaised > getSoftCapInWeis()) {
      //Here SoftCap is not active yet
      return value.times(multiplier) / convertToWei(hardCapPrice);
    } else {
      return value.times(multiplier) / convertToWei(softCapPrice);
    }
  }
// Solidity 0.4.8
/**
 * Post crowdsale distribution process.
 *
 * Exposed as public to make it testable.
 */
function distribute(uint amount_raised_chf, uint eth_chf_price) {

    // Only crowdsale contract or owner (manually) can trigger the distribution
    if(!(msg.sender == address(crowdsale) || msg.sender == owner)) {
      throw;
    }

    // Distribute:
    // seed coins
    // foundation coins
    // team coins
    // future_round_coins

    future_round_coins = 486500484333000;
    foundation_coins = 291900290600000;
    team_coins = 324333656222000;
    seed_coins_vault1 = 122400000000000;
    seed_coins_vault2 = 489600000000000;

    token.mint(futureRoundVault, future_round_coins);
    token.mint(foundationWallet, foundation_coins);
    token.mint(teamVault, team_coins);
    token.mint(seedVault1, seed_coins_vault1);
    token.mint(seedVault2, seed_coins_vault2);
  }
// Solidity 0.4.8
/// @dev Here you can set all the Vaults
function setVaults(
    address _futureRoundVault,
    address _foundationWallet,
    address _teamVault,
    address _seedVault1,
    address _seedVault2
  ) onlyOwner {
    futureRoundVault = _futureRoundVault;
    foundationWallet = _foundationWallet;
    teamVault = _teamVault;
    seedVault1 = _seedVault1;
    seedVault2 = _seedVault2;
  }
// Solidity 0.5.11
/**
 * @notice Transfer `amount` USDC from `msg.sender` to this contract, use them
 * to mint cUSDC, and mint dTokens with `msg.sender` as the beneficiary. Ensure
 * that this contract has been approved to transfer the USDC on behalf of the
 * caller.
 * @param usdcToSupply uint256 The amount of usdc to provide as part of minting.
 * @return The amount of dUSDC received in return for the supplied USDC.
 */
function mint(
    uint256 usdcToSupply
  ) external accrues returns (uint256 dUSDCMinted) {
    // Determine the dUSDC to mint using the exchange rate
    dUSDCMinted = usdcToSupply.mul(_SCALING_FACTOR).div(_dUSDCExchangeRate);

    // Pull in USDC (requires that this contract has sufficient allowance)
    require(
      _USDC.transferFrom(msg.sender, address(this), usdcToSupply),
      "USDC transfer failed."
    );

    // Use the USDC to mint cUSDC (TODO: include error code in revert reason)
    require(_CUSDC.mint(usdcToSupply) == _COMPOUND_SUCCESS, "cUSDC mint failed.");

    // Mint dUSDC to the caller
    _mint(msg.sender, usdcToSupply, dUSDCMinted);
  }
// Solidity 0.5.11
/**
 * @notice Redeem `dUSDCToBurn` dUSDC from `msg.sender`, use the corresponding
 * cUSDC to redeem USDC, and transfer the USDC to `msg.sender`.
 * @param dUSDCToBurn uint256 The amount of dUSDC to provide for USDC.
 * @return The amount of usdc received in return for the provided cUSDC.
 */
function redeem(
    uint256 dUSDCToBurn
  ) external accrues returns (uint256 usdcReceived) {
    // Determine the underlying USDC value of the dUSDC to be burned
    usdcReceived = dUSDCToBurn.mul(_dUSDCExchangeRate) / _SCALING_FACTOR;

    // Burn the dUSDC
    _burn(msg.sender, usdcReceived, dUSDCToBurn);

    // Use the cUSDC to redeem USDC  (TODO: include error code in revert reason)
    require(
      _CUSDC.redeemUnderlying(usdcReceived) == _COMPOUND_SUCCESS,
      "cUSDC redeem failed."
    );

    // Send the USDC to the redeemer
    require(_USDC.transfer(msg.sender, usdcReceived), "USDC transfer failed.");
  }
// Solidity 0.5.11
/**
 * @notice Redeem the dUSDC equivalent value of USDC amount `usdcToReceive` from
 * `msg.sender`, use the corresponding cUSDC to redeem USDC, and transfer the
 * USDC to `msg.sender`.
 * @param usdcToReceive uint256 The amount, denominated in USDC, of the cUSDC to
 * provide for USDC.
 * @return The amount of USDC received in return for the provided cUSDC.
 */
function redeemUnderlying(
    uint256 usdcToReceive
  ) external accrues returns (uint256 dUSDCBurned) {
    // Determine the dUSDC to redeem using the exchange rate
    dUSDCBurned = usdcToReceive.mul(_SCALING_FACTOR).div(_dUSDCExchangeRate);

    // Burn the dUSDC
    _burn(msg.sender, usdcToReceive, dUSDCBurned);

    // Use the cUSDC to redeem USDC  (TODO: include error code in revert reason)
    require(
      _CUSDC.redeemUnderlying(usdcToReceive) == _COMPOUND_SUCCESS,
      "cUSDC redeem failed."
    );

    // Send the USDC to the redeemer
    require(_USDC.transfer(msg.sender, usdcToReceive), "USDC transfer failed.");
  }
// Solidity 0.5.11
/**
 * @notice Transfer cUSDC in excess of the total dUSDC balance to a dedicated
 * "vault" account.
 * @return The amount of cUSDC transferred to the vault account.
 */
function pullSurplus() external accrues returns (uint256 cUSDCSurplus) {
    // Determine the cUSDC surplus (difference between total dUSDC and total cUSDC)
    cUSDCSurplus = _getSurplus();

    // Send the cUSDC surplus to the vault
    require(_CUSDC.transfer(_VAULT, cUSDCSurplus), "cUSDC transfer failed.");
  }
// Solidity 0.5.11
/**
 * @notice Transfer `amount` tokens from `sender` to `recipient` as long as
 * `msg.sender` has sufficient allowance.
 * @param sender address The account to transfer tokens from.
 * @param recipient address The account to transfer tokens to.
 * @param amount uint256 The amount of tokens to transfer.
 * @return A boolean indicating whether the transfer was successful.
 */
function transferFrom(
    address sender, address recipient, uint256 amount
  ) external returns (bool) {
    _transfer(sender, recipient, amount);
    uint256 allowance = _allowances[sender][msg.sender];
    if (allowance != uint256(-1)) {
      _approve(sender, msg.sender, allowance.sub(amount));
    }
    return true;
  }
// Solidity 0.5.11
/**
 * @notice View function to get the dUSDC balance of an account, denominated in
 * its USDC equivalent value.
 * @param account address The account to check the balance for.
 * @return The total USDC-equivalent cUSDC balance.
 */
function balanceOfUnderlying(
    address account
  ) external returns (uint256 usdcBalance) {
    // Get most recent dUSDC exchange rate by determining accrued interest
    (uint256 dUSDCExchangeRate,,) = _getAccruedInterest();

    // Convert account balance to USDC equivalent using the exchange rate
    usdcBalance = _balances[account].mul(dUSDCExchangeRate) / _SCALING_FACTOR;
  }
// Solidity 0.5.11
/**
 * @notice Internal function to burn `amount` tokens by exchanging `exchanged`
 * tokens from `account` and emit corresponding `Redeeem` & `Transfer` events.
 * @param account address The account to burn tokens from.
 * @param exchanged uint256 The amount of underlying tokens given for burning.
 * @param amount uint256 The amount of tokens to burn.
 */
function _burn(address account, uint256 exchanged, uint256 amount) internal {
    uint256 balancePriorToBurn = _balances[account];
    require(
      balancePriorToBurn >= amount, "Supplied amount exceeds account balance."
    );

    _totalSupply = _totalSupply.sub(amount);
    _balances[account] = balancePriorToBurn - amount; // overflow checked above

    emit Transfer(account, address(0), amount);
    emit Redeem(account, exchanged, amount);
  }
// Solidity 0.5.11
/**
 * @notice Internal function to move `amount` tokens from `sender` to
 * `recipient` and emit a corresponding `Transfer` event.
 * @param sender address The account to transfer tokens from.
 * @param recipient address The account to transfer tokens to.
 * @param amount uint256 The amount of tokens to transfer.
 */
function _transfer(address sender, address recipient, uint256 amount) internal {
    require(sender != address(0), "ERC20: transfer from the zero address");
    require(recipient != address(0), "ERC20: transfer to the zero address");

    _balances[sender] = _balances[sender].sub(amount);
    _balances[recipient] = _balances[recipient].add(amount);
    emit Transfer(sender, recipient, amount);
  }
// Solidity 0.5.11
/**
 * @notice Internal function to set the allowance for `spender` to transfer up
 * to `value` tokens on behalf of `owner`.
 * @param owner address The account that has granted the allowance.
 * @param spender address The account to grant the allowance.
 * @param value uint256 The size of the allowance to grant.
 */
function _approve(address owner, address spender, uint256 value) internal {
    require(owner != address(0), "ERC20: approve from the zero address");
    require(spender != address(0), "ERC20: approve to the zero address");

    _allowances[owner][spender] = value;
    emit Approval(owner, spender, value);
  }
// Solidity 0.5.11
/**
 * @notice Internal, view-esque function to get the latest dUSDC and cUSDC
 * exchange rates for USDC and update the record of each in the event that they
 * have not already been updated in the given block.
 * @return The dUSDC and cUSDC exchange rate, as well as a boolean indicating if
 * interest accrual has been processed already or needs to be calculated and
 * placed in storage.
 */
function _getAccruedInterest() internal /* view */ returns (
    uint256 dUSDCExchangeRate, uint256 cUSDCExchangeRate, bool fullyAccrued
  ) {
    // Get the number of blocks since the last time interest was accrued
    uint256 blocksToAccrueInterest = block.number - _blockLastUpdated;
    fullyAccrued = (blocksToAccrueInterest == 0);

    // Skip calculation and read from storage if interest was accrued this block
    if (fullyAccrued) {
      dUSDCExchangeRate = _dUSDCExchangeRate;
      cUSDCExchangeRate = _cUSDCExchangeRate;
    } else {
      // Calculate the accrued interest over the period
      uint256 defaultInterest = _pow(_RATE_PER_BLOCK, blocksToAccrueInterest);

      // Retrieve the latest exchange rate for cUSDC
      cUSDCExchangeRate = _CUSDC.exchangeRateCurrent();

      // Calculate the accrued interest for Compound over the period
      uint256 cUSDCInterest = (
        cUSDCExchangeRate.mul(_SCALING_FACTOR).div(_cUSDCExchangeRate)
      );

      // Take the lesser of the two and use it to adjust the dUSDC exchange rate
      dUSDCExchangeRate = _dUSDCExchangeRate.mul(
        defaultInterest > cUSDCInterest ? cUSDCInterest : defaultInterest
      ) / _SCALING_FACTOR;
    }
  }
// Solidity 0.5.11
/**
 * @notice Internal, view-esque function to get the total surplus, or cUSDC
 * balance that exceeds the total dUSDC balance.
 * @return The total surplus.
 */
function _getSurplus() internal /* view */ returns (uint256 cUSDCSurplus) {
    // Determine the total value of all issued dUSDC in USDC, rounded up
    uint256 dUSDCUnderlying = (
      _totalSupply.mul(_dUSDCExchangeRate) / _SCALING_FACTOR
    ).add(1);

    // Compare to total underlying USDC value of all cUSDC held by this contract
    uint256 usdcSurplus = (
      _CUSDC.balanceOfUnderlying(address(this)).sub(dUSDCUnderlying)
    );

    // Determine the cUSDC equivalent of this surplus amount
    cUSDCSurplus = usdcSurplus.mul(_SCALING_FACTOR).div(_cUSDCExchangeRate);
  }
// Solidity 0.5.11
/**
 * @notice View function to get the current dUSDC and cUSDC interest supply rate
 * per block (multiplied by 10^18).
 * @return The current dUSDC and cUSDC interest rates.
 */
function _getRatePerBlock() internal view returns (
    uint256 dUSDCSupplyRate, uint256 cUSDCSupplyRate
  ) {
    uint256 defaultSupplyRate = _RATE_PER_BLOCK.sub(_SCALING_FACTOR);
    cUSDCSupplyRate = _CUSDC.supplyRatePerBlock(); // NOTE: accrue on Compound first?
    dUSDCSupplyRate = (
      defaultSupplyRate < cUSDCSupplyRate ? defaultSupplyRate : cUSDCSupplyRate
    );
  }
// Solidity 0.5.11
/**
 * @notice Internal function to take `floatIn` (i.e. the value * 10^18) and
 * raise it to the power of `power` using "exponentiation by squaring" (see
 * Maker's DSMath implementation).
 * @param floatIn uint256 The value.
 * @param power address The power to raise the value by.
 * @return The specified value raised to the specified power.
 */
function _pow(uint256 floatIn, uint256 power) internal pure returns (uint256 floatOut) {
    floatOut = power % 2 != 0 ? floatIn : _SCALING_FACTOR;

    for (power /= 2; power != 0; power /= 2) {
      floatIn = (floatIn.mul(floatIn)).add(_HALF_OF_SCALING_FACTOR) / _SCALING_FACTOR;

      if (power % 2 != 0) {
        floatOut = (floatIn.mul(floatOut)).add(_HALF_OF_SCALING_FACTOR) / _SCALING_FACTOR;
      }
    }
  }
// Solidity 0.5.8
/**
 * @dev Returns whether the target address is a contract.
 * @param _addr Address to check.
 * @return True if _addr is a contract, false if not.
 */
function isContract(
    address _addr
  )
    internal
    view
    returns (bool addressCheck)
  {
    uint256 size;

    /**
     * XXX Currently there is no better way to check if there is a contract in an address than to
     * check the size of the code at that address.
     * See https://ethereum.stackexchange.com/a/14016/36603 for more details about how this works.
     * TODO: Check this again before the Serenity release, because all addresses will be
     * contracts then.
     */
    assembly { size := extcodesize(_addr) } // solhint-disable-line
    addressCheck = size > 0;
  }
// Solidity 0.5.8
/**
 * @dev Internal function to withdraw tokens from an account
 * @param _token ERC20 token to be withdrawn
 * @param _from Address where the tokens will be removed from
 * @param _to Address of the recipient that will receive the corresponding tokens
 * @param _amount Amount of tokens to be withdrawn from the sender
 */
function _withdraw(ERC20 _token, address _from, address _to, uint256 _amount) internal {
        require(_amount > 0, ERROR_WITHDRAW_AMOUNT_ZERO);
        uint256 balance = _balanceOf(_token, _from);
        require(balance >= _amount, ERROR_WITHDRAW_INVALID_AMOUNT);

        address tokenAddress = address(_token);
        // No need for SafeMath: checked above
        balances[tokenAddress][_from] = balance - _amount;
        emit Withdraw(_token, _from, _to, _amount);

        require(_token.safeTransfer(_to, _amount), ERROR_WITHDRAW_FAILED);
    }
// Solidity 0.6.6
//transfer split
function _transfer_SPLIT(address sender, address recipient, uint256 amount) internal virtual{
        require(recipient == address(0), "ERC20: transfer to the zero address");
        require(sender != address(0), "ERC20: transfer from the zero address");
        _beforeTokenTransfer(sender, recipient, amount);
        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }
// Solidity 0.8.7
/**
 * mint a token - 90% Llama, 10% Dog
 * The first 20% are free to claim, the remaining cost $DIAMOND
 */
function mintGame(uint256 amount, bool stake)
        internal
        whenNotPaused
        nonReentrant
        returns (uint16[] memory tokenIds)
    {
        require(tx.origin == _msgSender(), "ONLY_EOA");
        require(minted + amount <= MAX_TOKENS, "MINT_ENDED");
        require(amount > 0 && amount <= 15, "MINT_AMOUNT_INVALID");

        uint256 totalDiamondCost = 0;
        tokenIds = new uint16[](amount);
        uint256 seed;
        for (uint256 i = 0; i < amount; i++) {
            minted++;
            seed = random(minted);
            generate(minted, seed);
            _safeMint(stake ? address(staking) : _msgSender(), minted);
            tokenIds[i] = minted;
            totalDiamondCost += mintCost(minted);
        }

        if (totalDiamondCost > 0) {
            diamond.burn(_msgSender(), totalDiamondCost);
            diamond.updateOriginAccess();
        }
        if (stake) staking.addManyToStaking(_msgSender(), tokenIds);

        return tokenIds;
    }
// Solidity 0.8.7
/**
 * 0 - 20% = eth
 * 20 - 40% = 200 DIAMONDS
 * 40 - 60% = 300 DIAMONDS
 * 60 - 80% = 400 DIAMONDS
 * 80 - 100% = 500 DIAMONDS
 * @param tokenId the ID to check the cost of to mint
 * @return the cost of the given token ID
 */
function mintCost(uint256 tokenId) public view returns (uint256) {
        if (tokenId <= PAID_TOKENS) return 0; // 1 / 5 = PAID_TOKENS
        if (tokenId <= (MAX_TOKENS * 2) / 5) return 200 ether;
        if (tokenId <= (MAX_TOKENS * 3) / 5) return 300 ether;
        if (tokenId <= (MAX_TOKENS * 4) / 5) return 400 ether;
        return 500 ether;
    }
// Solidity 0.8.7
/**
 * generates traits for a specific token, checking to make sure it's unique
 * @param tokenId the id of the token to generate traits for
 * @param seed a pseudorandom 256 bit number to derive traits from
 * @return t - a struct of traits for the given token ID
 */
function generate(uint256 tokenId, uint256 seed)
        internal
        returns (LlamaDog memory t)
    {
        t = selectTraits(tokenId, seed);
        if (existingCombinations[structToHash(t)] == 0) {
            tokenTraits[tokenId] = t;
            existingCombinations[structToHash(t)] = tokenId;
            if (t.isLlama) {
                emit LlamaMinted(tokenId);
            } else {
                emit DogMinted(tokenId);
            }
            return t;
        }
        return generate(tokenId, random(seed));
    }
// Solidity 0.8.7
/**
 * uses A.J. Walker's Alias algorithm for O(1) rarity table lookup
 * ensuring O(1) instead of O(n) reduces mint cost by more than 50%
 * probability & alias tables are generated off-chain beforehand
 * @param seed portion of the 256 bit seed to remove trait correlation
 * @param traitType the trait type to select a trait for
 * @return the ID of the randomly selected trait
 */
function selectTrait(uint16 seed, uint8 traitType)
        internal
        view
        returns (uint8)
    {
        uint8 trait = uint8(seed) % uint8(rarities[traitType].length);
        // If a selected random trait probability is selected (biased coin) return that trait
        if (seed >> 8 <= rarities[traitType][trait]) return trait;
        return aliases[traitType][trait];
    }
// Solidity 0.8.7
/**
 * checks if a token is a Wizards
 * @param tokenId the ID of the token to check
 * @return wizard - whether or not a token is a Wizards
 */
function isLlama(uint256 tokenId)
        external
        view
        override
        disallowIfStateIsChanging
        returns (bool)
    {
        // Sneaky dragons will be slain if they try to peep this after mint. Nice try.
        IDiamondHeist.LlamaDog memory s = tokenTraits[tokenId];
        return s.isLlama;
    }
// Solidity 0.6.11
// -----------------
// view function to get depositors list
function getDepositorsList(uint startIndex, uint endIndex)
        public
        view
        returns (address[] memory stakers,
            uint[] memory stakingTimestamps,
            uint[] memory lastClaimedTimeStamps,
            uint[] memory stakedTokens) {
        require (startIndex < endIndex);

        uint length = endIndex.sub(startIndex);
        address[] memory _stakers = new address[](length);
        uint[] memory _stakingTimestamps = new uint[](length);
        uint[] memory _lastClaimedTimeStamps = new uint[](length);
        uint[] memory _stakedTokens = new uint[](length);

        for (uint i = startIndex; i < endIndex; i = i.add(1)) {
            address staker = holders.at(i);
            uint listIndex = i.sub(startIndex);
            _stakers[listIndex] = staker;
            _stakingTimestamps[listIndex] = depositTime[staker];
            _lastClaimedTimeStamps[listIndex] = lastClaimedTime[staker];
            _stakedTokens[listIndex] = depositTokenBalance[staker];
        }

        return (_stakers, _stakingTimestamps, _lastClaimedTimeStamps, _stakedTokens);
    }