lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
// Returns `true` if the term sheet has NOT been yet added.
function _isMissingTerms(TermSheet memory newSheet)
        internal
        view
        returns (bool)
    {
        for (uint256 i = 0; i < termSheets.length; i++) {
            TermSheet memory sheet = termSheets[i];
            if (
                sheet.token == newSheet.token &&
                sheet.minAmount == newSheet.minAmount &&
                sheet.maxAmountFactor == newSheet.maxAmountFactor &&
                sheet.lockHours == newSheet.lockHours &&
                sheet.rewardLockHours == newSheet.rewardLockHours &&
                sheet.rewardFactor == newSheet.rewardFactor
            ) {
                return false;
            }
        }
        return true;
    }
// Solidity 0.6.12
// Assuming the given array does contain the given element
function _removeArrayElement(uint256[] storage arr, uint256 el) internal {
        uint256 lastIndex = arr.length - 1;
        if (lastIndex != 0) {
            uint256 replaced = arr[lastIndex];
            if (replaced != el) {
                // Shift elements until the one being removed is replaced
                do {
                    uint256 replacing = replaced;
                    replaced = arr[lastIndex - 1];
                    lastIndex--;
                    arr[lastIndex] = replacing;
                } while (replaced != el && lastIndex != 0);
            }
        }
        // Remove the last (and quite probably the only) element
        arr.pop();
    }
// Solidity 0.8.7
/// @dev Creates a new Artwork and mint an edition
function createArtworkAndMintEdition(
        uint256 _artworkNumber,
        uint8 _scarcity,
        string memory _tokenUri,
        uint16 _totalLeft,
        bool _active,
        address _to
    ) external whenNotPaused onlyMinter returns (uint256) {
        _createArtwork(
            _artworkNumber,
            _scarcity,
            _tokenUri,
            _totalLeft,
            _active
        );

        // Create the token
        return
            _mintEdition(
                _to,
                _artworkNumber,
                artworkNumberToArtworkDetails[_artworkNumber].tokenUri
            );
    }
// Solidity 0.8.7
/// @dev Get artwork details from artworkNumber
function getArtwork(uint256 artworkNumber)
        external
        view
        returns (
            uint8 scarcity,
            uint16 totalMinted,
            uint16 totalLeft,
            string memory tokenUri,
            bool active
        )
    {
        ArtworkDetails storage a = artworkNumberToArtworkDetails[artworkNumber];
        scarcity = a.scarcity;
        totalMinted = a.totalMinted;
        totalLeft = a.totalLeft;
        tokenUri = a.tokenUri;
        active = a.active;
    }
// Solidity 0.8.7
/**
 * @dev Internal factory method to generate an new tokenId based
 * @dev based on artwork number
 */
function _getNextTokenId(uint256 _artworkNumber)
        internal
        view
        returns (uint256)
    {
        ArtworkDetails storage _artworkDetails = artworkNumberToArtworkDetails[
            _artworkNumber
        ];

        // Build next token ID e.g. 100000 + (1 - 1) = ID of 100001 (this first in the edition set)
        return _artworkDetails.artworkNumber.add(_artworkDetails.totalMinted);
    }
// Solidity 0.8.7
/**
 * @dev Internal factory method to mint a new edition
 * @dev for an artwork
 */
function _mintEdition(
        address _to,
        uint256 _artworkNumber,
        string memory _tokenUri
    ) internal returns (uint256) {
        // Construct next token ID e.g. 100000 + 1 = ID of 100001 (this first in the edition set)
        uint256 _tokenId = _getNextTokenId(_artworkNumber);

        // Mint new base token
        super._mint(_to, _tokenId);
        super._setTokenURI(_tokenId, _tokenUri);

        // Maintain mapping for tokenId to artwork for lookup
        tokenIdToArtworkNumber[_tokenId] = _artworkNumber;

        // Maintain mapping of edition to token array for "edition minted tokens"
        artworkNumberToTokenIds[_artworkNumber].push(_tokenId);

        ArtworkDetails storage _artworkDetails = artworkNumberToArtworkDetails[
            _artworkNumber
        ];
        // Increase number totalMinted
        _artworkDetails.totalMinted += 1;
        // Decrease number totalLeft
        _artworkDetails.totalLeft -= 1;

        // Emit minted event
        emit ArtworkEditionMinted(_tokenId, _artworkNumber, _to);
        return _tokenId;
    }
// Solidity 0.8.7
/// @dev Migrates tokens to a potential new version of this contract
/// @param tokenIds - list of tokens to transfer
function migrateTokens(uint256[] calldata tokenIds) external {
        require(
            address(newContract) != address(0),
            "LaCollection: New contract not set"
        );

        for (uint256 index = 0; index < tokenIds.length; index++) {
            transferFrom(_msgSender(), address(this), tokenIds[index]);
        }

        newContract.migrateTokens(tokenIds, _msgSender());
    }
// Solidity 0.8.11
//Yes this is ugly but it saves gas through binary search & probability theory, a total of 5-10 ETH for our dear hodlers will be saved because of this ugliness
function multiMint(uint amount, address to) private {
        require(amount > 0, "Invalid amount");
        require(_checkOnERC721Received(address(0), to, _mint(to), ''), "ERC721: transfer to non ERC721Receiver implementer"); //Safe mint 1st and regular mint rest to save gas! 
        if (amount < 4) {
            if (amount == 2) {
                _mint(to);
            } else if (amount == 3) {
                _mint(to);
                _mint(to);
            }
        } else {
            if (amount > 5) {
                if (amount == 6) {
                    _mint(to);
                    _mint(to);
                    _mint(to);
                    _mint(to);
                    _mint(to);
                } else { // 7
                    _mint(to);
                    _mint(to);
                    _mint(to);
                    _mint(to);
                    _mint(to);
                    _mint(to);
                }
            } else {
                if (amount == 4) {
                    _mint(to);
                    _mint(to);
                    _mint(to);
                } else { // 5
                    _mint(to);
                    _mint(to);
                    _mint(to);
                    _mint(to);
                }
            }
        }

    }
// Solidity 0.4.26
/*
 * @dev Get GMI to user
 */
function getUnLockedGMI() public 
	isActivated() 
	isExhausted()
		payable {

 		uint256 currentTakeGMI = 0;
 		uint256 unlockedCount = 0;
		uint256 unlockedGMI = 0;
		uint256 userLockedGMI = 0;
		uint256 userTakeTime = 0;
        (currentTakeGMI, unlockedCount, unlockedGMI, userLockedGMI, userTakeTime) = calculateUnLockerGMI(msg.sender);
		takenAmount[msg.sender] = safeAdd(takenAmount[msg.sender], currentTakeGMI);
		takenTime[msg.sender] = now;
		gmiToken.transfer(msg.sender, currentTakeGMI);
    }
// Solidity 0.4.26
/*
 * @dev  calculate user unlocked GMI amount
 */
function calculateUnLockerGMI(address userAddr) private isActivated() 
    view returns(uint256, uint256, uint256, uint256, uint256)  {
        uint256 unlockedCount = 0;
		uint256 currentTakeGMI = 0;
		uint256 userTakenTime = takenTime[userAddr];
		uint256 userLockedGMI = lockList[userAddr];

	    unlockedCount = safeDiv(safeSub(now, activatedTime), timeInterval);
		
		if(unlockedCount == 0) {
		    return (0, unlockedCount, unlockedGMI, userLockedGMI, userTakenTime);
		}
		
		if(unlockedCount > unLockedAmount) {
		    unlockedCount = unLockedAmount;
		}

		uint256 unlockedGMI =  safeDiv(safeMul(userLockedGMI, unlockedCount), unLockedAmount);
		currentTakeGMI = safeSub(unlockedGMI, takenAmount[userAddr]);
		if(unlockedCount == unLockedAmount) {
		   currentTakeGMI = safeSub(userLockedGMI, takenAmount[userAddr]);
		}
	    return (currentTakeGMI, unlockedCount, unlockedGMI, userLockedGMI, userTakenTime);
    }
// Solidity 0.4.24
/**
 * @dev Limit burn functions to owner and reduce cap after burning
 */
function _burn(address _who, uint256 _value) internal onlyOwner {
        // no need to check _value <= cap since totalSupply <= cap and 
        // _value <= totalSupply was checked in burn functions
        super._burn(_who, _value);
        cap = cap.sub(_value);
    }
// Solidity 0.7.6
/**
 * Creates new tokens. Can only be called by one of the three owners. Includes
 * signatures from each of the 3 owners.
 * The signed messages is a bytes32(equivalent to uint256), which includes the
 * nonce and the amount intended to be minted. The network ID is not included,
 * which means owner keys cannot be shared across networks because of the
 * possibility of replay. The lower 128 bits of the signedMessage contain
 * the amount to be minted, and the upper 128 bits contain the nonce.
 */
function mint(bytes32 signedMessage, uint8 sigV1, bytes32 sigR1, bytes32 sigS1, uint8 sigV2, bytes32 sigR2, bytes32 sigS2, uint8 sigV3, bytes32 sigR3, bytes32 sigS3) external {
    require(isOwner(), "Must be owner");
    require(ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", signedMessage)), sigV1, sigR1, sigS1) == owner1, "Not approved by owner1");
    require(ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", signedMessage)), sigV2, sigR2, sigS2) == owner2, "Not approved by owner2");
    require(ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", signedMessage)), sigV3, sigR3, sigS3) == owner3, "Not approved by owner3");
    // cast message to a uint256
    uint256 signedMessageUint256 = uint256(signedMessage);
    // bitwise-and the lower 128 bits of message to get the amount
    uint256 amount = signedMessageUint256 & (2**128-1);
    // right-shift the message by 128 bits to get the nonce in the correct position
    signedMessageUint256 = signedMessageUint256 / (2**128);
    // bitwise-and the message by 128 bits to get the nonce
    uint32 nonce = uint32(signedMessageUint256 & (2**128-1));
    require(nonce == mintingNonce, "nonce must match");
    mintingNonce += 1;
    _mint(owner1, amount);
    emit Minted(owner1, amount);
  }
// Solidity 0.8.7
/**
 * @dev See {IRoyaltyEngineV1-getRoyalty}
 */
function getRoyalty(address tokenAddress, uint256 tokenId, uint256 value) public override returns(address payable[] memory recipients, uint256[] memory amounts) {
        int16 spec;
        address royaltyAddress;
        bool addToCache;

        (recipients, amounts, spec, royaltyAddress, addToCache) = _getRoyaltyAndSpec(tokenAddress, tokenId, value);
        if (addToCache) _specCache[royaltyAddress] = spec;
        return (recipients, amounts);
    }
// Solidity 0.8.7
/**
 * @dev See {IRoyaltyEngineV1-getRoyaltyView}.
 */
function getRoyaltyView(address tokenAddress, uint256 tokenId, uint256 value) public view override returns(address payable[] memory recipients, uint256[] memory amounts) {
        (recipients, amounts, , , ) = _getRoyaltyAndSpec(tokenAddress, tokenId, value);
        return (recipients, amounts);
    }
// Solidity 0.8.7
/**
 * Compute royalty amounts
 */
function _computeAmounts(uint256 value, uint256[] memory bps) private pure returns(uint256[] memory amounts) {
        amounts = new uint256[](bps.length);
        uint256 totalAmount;
        for (uint i = 0; i < bps.length; i++) {
            amounts[i] = value*bps[i]/10000;
            totalAmount += amounts[i];
        }
        require(totalAmount < value, "Invalid royalty amount");
        return amounts;
    }
// Solidity 0.7.6
/// @notice Fetches a time-weighted observation for a given Uniswap V3 pool
/// @param pool Address of the pool that we want to observe
/// @param period Number of seconds in the past to start calculating the time-weighted observation
/// @return observation An observation that has been time-weighted from (block.timestamp - period) to block.timestamp
function consult(address pool, uint32 period) internal view returns (PeriodObservation memory observation) {
    require(period != 0, 'BP');

    uint192 periodX160 = uint192(period) * type(uint160).max;

    uint32[] memory secondsAgos = new uint32[](2);
    secondsAgos[0] = period;
    secondsAgos[1] = 0;

    (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) = IUniswapV3Pool(pool).observe(secondsAgos);
    int56 tickCumulativesDelta = tickCumulatives[1] - tickCumulatives[0];
    uint160 secondsPerLiquidityCumulativesDelta = secondsPerLiquidityCumulativeX128s[1] - secondsPerLiquidityCumulativeX128s[0];

    observation.arithmeticMeanTick = int24(tickCumulativesDelta / period);
    // Always round to negative infinity
    if (tickCumulativesDelta < 0 && (tickCumulativesDelta % period != 0)) observation.arithmeticMeanTick--;

    // We are shifting the liquidity delta to ensure that the result doesn't overflow uint128
    observation.harmonicMeanLiquidity = uint128(periodX160 / (uint192(secondsPerLiquidityCumulativesDelta) << 32));
  }
// Solidity 0.7.6
/// @notice Given some time-weighted observations, calculates the arithmetic mean tick, weighted by liquidity
/// @param observations A list of time-weighted observations
/// @return arithmeticMeanWeightedTick The arithmetic mean tick, weighted by the observations' time-weighted harmonic average liquidity
function getArithmeticMeanTickWeightedByLiquidity(PeriodObservation[] memory observations)
    internal
    pure
    returns (int24 arithmeticMeanWeightedTick)
  {
    // Accumulates the sum of all observations' products between each their own average tick and harmonic average liquidity
    // Each product can be stored in a int160, so it would take approximatelly 2**96 observations to overflow this accumulator
    int256 numerator;

    // Accumulates the sum of the harmonic average liquidities from the given observations
    // Each average liquidity can be stored in a uint128, so it will take approximatelly 2**128 observations to overflow this accumulator
    uint256 denominator;

    for (uint256 i; i < observations.length; i++) {
      numerator += int256(observations[i].harmonicMeanLiquidity) * observations[i].arithmeticMeanTick;
      denominator += observations[i].harmonicMeanLiquidity;
    }

    arithmeticMeanWeightedTick = int24(numerator / int256(denominator));

    // Always round to negative infinity
    if (numerator < 0 && (numerator % int256(denominator) != 0)) arithmeticMeanWeightedTick--;
  }
// Solidity 0.4.16
/**
 * @dev Function to check the amount of tokens that an owner allowed to a spender.
 * @param _totalSupply total supply of the token.
 * @param _name token name e.g Dijets.
 * @param _symbol token symbol e.g DJT.
 * @param _decimals amount of decimals.
 */
function DijetsToken(uint256 _totalSupply, string _name, string _symbol, uint8 _decimals) {
        balances[msg.sender] = _totalSupply;    // Give the creator all initial tokens
        totalSupply = _totalSupply;
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
    }
// Solidity 0.8.4
/**
 * @dev Locking {_amounts} with {_unlockAt} date for specific {_account}.
 */
function lock(address _account, uint256[] memory _unlockAt, uint256[] memory _amounts)
        external
        onlyOwner
        returns (uint256 totalAmount)
    {
        require(_account != address(0), "Zero address");
        require(
            _unlockAt.length == _amounts.length &&
            _unlockAt.length <= MAX_LOCK_LENGTH,
            "Wrong array length"
        );
        require(_unlockAt.length != 0, "Zero array length");

        for (uint i = 0; i < _unlockAt.length; i++) {
            if (i == 0) {
                require(_unlockAt[0] >= startAt, "Early unlock");
            }

            if (i > 0) {
                if (_unlockAt[i-1] >= _unlockAt[i]) {
                    require(false, "Timeline violation");
                }
            }

            totalAmount += _amounts[i];
        }

        token.safeTransferFrom(msg.sender, address(this), totalAmount);

        _balances[_account].locks.push(Lock({
            amounts: _amounts,
            unlockAt: _unlockAt,
            released: 0
        }));

        emit TokensVested(_account, totalAmount);
    }
// Solidity 0.8.4
/**
 * @dev Returns next unlock timestamp by all locks, if return zero,
 *      no time points available.
 */
function getNextUnlock(address _participant) external view returns (uint256 timestamp) {
        uint256 locksLen = _balances[_participant].locks.length;
        uint currentUnlock;
        uint i;
        for (i; i < locksLen; i++) {
            currentUnlock = _getNextUnlock(_participant, i);
            if (currentUnlock != 0) {
                if (timestamp == 0) {
                    timestamp = currentUnlock;
                } else {
                    if (currentUnlock < timestamp) {
                        timestamp = currentUnlock;
                    }
                }
            }
        }
    }
// Solidity 0.6.12
/**
 * @dev Grants tokens to an account.
 *
 * @param beneficiary = Address to which tokens will be granted.
 * @param vestingAmount = The number of tokens subject to vesting.
 * @param startDay = Start day of the grant's vesting schedule, in days since the UNIX epoch
 *   (start of day). The startDay may be given as a date in the future or in the past, going as far
 *   back as year 2000.
 * @param vestingLocation = Account where the vesting schedule is held (must already exist).
 */
function _addGrant(
    address beneficiary,
    uint256 vestingAmount,
    uint32 startDay,
    address vestingLocation
  ) internal {
    // Make sure no prior grant is in effect.
    require(!_tokenGrants[beneficiary].isActive, "grant already exists");

    // Check for valid vestingAmount
    require(
      vestingAmount > 0 &&
        startDay >= _JAN_1_2000_DAYS &&
        startDay < _JAN_1_3000_DAYS,
      "invalid vesting params"
    );

    // Create and populate a token grant, referencing vesting schedule.
    _tokenGrants[beneficiary] = tokenGrant(
      true, // isActive
      false, // wasRevoked
      startDay,
      vestingAmount,
      vestingLocation, // The wallet address where the vesting schedule is kept.
      0 // claimedAmount
    );
    _allBeneficiaries.push(beneficiary);

    // Emit the event.
    emit VestingTokensGranted(
      beneficiary,
      vestingAmount,
      startDay,
      vestingLocation
    );
  }
// Solidity 0.6.12
/**
 * @dev returns all information about the grant's vesting as of the given day
 * for the given account. Only callable by the account holder or a contract owner.
 *
 * @param grantHolder = The address to do this for.
 * @param onDayOrToday = The day to check for, in days since the UNIX epoch. Can pass
 *   the special value 0 to indicate today.
 * return = A tuple with the following values:
 *   amountVested = the amount that is already vested
 *   amountNotVested = the amount that is not yet vested (equal to vestingAmount - vestedAmount)
 *   amountOfGrant = the total amount of tokens subject to vesting.
 *   amountAvailable = the amount of funds in the given account which are available for use as of the given day
 *   amountClaimed = out of amountVested, the amount that has been already transferred to beneficiary
 *   vestStartDay = starting day of the grant (in days since the UNIX epoch).
 *   isActive = true if the vesting schedule is currently active.
 *   wasRevoked = true if the vesting schedule was revoked.
 */
function getGrantInfo(address grantHolder, uint32 onDayOrToday)
    external
    view
    override
    onlyOwnerOrSelf(grantHolder)
    returns (
      uint256 amountVested,
      uint256 amountNotVested,
      uint256 amountOfGrant,
      uint256 amountAvailable,
      uint256 amountClaimed,
      uint32 vestStartDay,
      bool isActive,
      bool wasRevoked
    )
  {
    tokenGrant storage grant = _tokenGrants[grantHolder];
    uint256 notVestedAmount = _getNotVestedAmount(grantHolder, onDayOrToday);

    return (
      grant.amount.sub(notVestedAmount),
      notVestedAmount,
      grant.amount,
      _getAvailableAmountImpl(grant, notVestedAmount),
      grant.claimedAmount,
      grant.startDay,
      grant.isActive,
      grant.wasRevoked
    );
  }
// Solidity 0.6.12
/**
 * @dev If the account has a revocable grant, this forces the grant to end immediately.
 * After this function is called, getGrantInfo will return incomplete data
 * and there will be no possibility to claim non-claimed tokens
 *
 * @param grantHolder = Address to which tokens will be granted.
 */
function revokeGrant(address grantHolder) external override onlyOwner {
    tokenGrant storage grant = _tokenGrants[grantHolder];
    vestingSchedule storage vesting = _vestingSchedules[grant.vestingLocation];

    // Make sure a vesting schedule has previously been set.
    require(grant.isActive, "no active grant");
    // Make sure it's revocable.
    require(vesting.isRevocable, "irrevocable");

    // Kill the grant by updating wasRevoked and isActive.
    _tokenGrants[grantHolder].wasRevoked = true;
    _tokenGrants[grantHolder].isActive = false;

    // Emits the GrantRevoked event.
    emit GrantRevoked(grantHolder);
  }
// Solidity 0.7.6
/**
 * This function will take a pair and make sure that all Uniswap V3 pools for the pair are properly initialized for future use.
 * It will also add all available pools to an internal list, to avoid future queries to the factory.
 * It can be called multiple times for the same pair of tokens, to include and re-configure new pools that might appear in the future.
 * Will revert if there are no pools available for the given pair of tokens.
 */
function addSupportForPair(address _tokenA, address _tokenB) external override {
    uint256 _length = _supportedFeeTiers.length();
    (address __tokenA, address __tokenB) = _sortTokens(_tokenA, _tokenB);
    EnumerableSet.AddressSet storage _pools = _poolsForPair[__tokenA][__tokenB];
    uint16 _cardinality = uint16(period / _AVERAGE_BLOCK_INTERVAL) + 10; // We add 10 just to be on the safe side
    for (uint256 i; i < _length; i++) {
      address _pool = factory.getPool(__tokenA, __tokenB, uint24(_supportedFeeTiers.at(i)));
      if (_pool != address(0) && !_pools.contains(_pool) && IUniswapV3Pool(_pool).liquidity() >= MINIMUM_LIQUIDITY_THRESHOLD) {
        _pools.add(_pool);
        IUniswapV3Pool(_pool).increaseObservationCardinalityNext(_cardinality);
      }
    }
    require(_pools.length() > 0, 'PairNotSupported');
    emit AddedSupportForPair(__tokenA, __tokenB);
  }
// Solidity 0.6.7
// **** State mutations **** //
// Do a `callStatic` on this.
// If it returns true then run it for realz. (i.e. eth_signedTx, not eth_call)
function sync() public returns (bool) {
        uint256 colFactor = getColFactor();
        uint256 safeSyncColFactor = getSafeSyncColFactor();

        // If we're not safe
        if (colFactor > safeSyncColFactor) {
            uint256 unleveragedSupply = getSuppliedUnleveraged();
            uint256 idealSupply = getLeveragedSupplyTarget(unleveragedSupply);

            deleverageUntil(idealSupply);

            return true;
        }

        return false;
    }