lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Migrates the tokenHolder's old tokens to new tokens.
 * @dev This function can only be called once per `tokenHolder`. Anyone can call this method
 * on behalf of any other token holder since there is no disadvantage to receiving the tokens earlier.
 * @param tokenHolder address of the token holder to migrate.
 */
function migrateTokens(address tokenHolder) external {
        require(!hasMigrated[tokenHolder], "Already migrated tokens");
        hasMigrated[tokenHolder] = true;

        FixedPoint.Unsigned memory oldBalance = FixedPoint.Unsigned(oldToken.balanceOfAt(tokenHolder, snapshotId));

        if (!oldBalance.isGreaterThan(0)) {
            return;
        }

        FixedPoint.Unsigned memory newBalance = oldBalance.div(rate);
        require(newToken.mint(tokenHolder, newBalance.rawValue), "Mint failed");
    }
// Solidity 0.4.6
// build contract
function PPBC_Ether_Claim(){
        ppbc = msg.sender;
        deposits_refunded = false;
        num_claimed = 0;
        valid_voucher_code[0x99fc71fa477d1d3e6b6c3ed2631188e045b7f575eac394e50d0d9f182d3b0145] = 110.12 ether; total_claim_codes++;
        valid_voucher_code[0x8b4f72e27b2a84a30fe20b0ee5647e3ca5156e1cb0d980c35c657aa859b03183] = 53.2535 ether; total_claim_codes++;
        valid_voucher_code[0xe7ac3e31f32c5e232eb08a8f978c7e4c4845c44eb9fa36e89b91fc15eedf8ffb] = 151 ether; total_claim_codes++;
        valid_voucher_code[0xc18494ff224d767c15c62993a1c28e5a1dc17d7c41abab515d4fcce2bd6f629d] = 63.22342 ether; total_claim_codes++;
        valid_voucher_code[0x5cdb60c9e999a510d191cf427c9995d6ad3120a6b44afcb922149d275afc8ec4] = 101 ether; total_claim_codes++;
        valid_voucher_code[0x5fb7aed108f910cc73b3e10ceb8c73f90f8d6eff61cda5f43d47f7bec9070af4] = 16.3 ether; total_claim_codes++;
        valid_voucher_code[0x571a888f66f4d74442733441d62a92284f1c11de57198decf9d4c244fb558f29] = 424 ether; total_claim_codes++;
        valid_voucher_code[0x7123fa994a2990c5231d35cb11901167704ab19617fcbc04b93c45cf88b30e94] = 36.6 ether; total_claim_codes++;
        valid_voucher_code[0xdac0e1457b4cf3e53e9952b1f8f3a68a0f288a7e6192314d5b19579a5266cce0] = 419.1 ether; total_claim_codes++;
        valid_voucher_code[0xf836a280ec6c519f6e95baec2caee1ba4e4d1347f81d4758421272b81c4a36cb] = 86.44 ether; total_claim_codes++;
        valid_voucher_code[0x5470e8b8b149aca84ee799f6fd1a6bf885267a1f7c88c372560b28180e2cf056] = 92 ether; total_claim_codes++;
        valid_voucher_code[0x7f52b6f587c87240d471d6fcda1bb3c10c004771c1572443134fd6756c001c9a] = 124.2 ether; total_claim_codes++;
        valid_voucher_code[0x5d435968b687edc305c3adc29523aba1128bd9acd2c40ae2c9835f2e268522e1] = 95.102 ether; total_claim_codes++;
     }
// Solidity 0.4.6
// function to register claim
//
function register_claim(string password) payable {
          // claim deposit 50 ether (returned with claim, used to prevent "brute force" password cracking attempts) 
          if (msg.value != 50 ether || valid_voucher_code[sha3(password)] == 0) return; // if user does not provide the right password, the deposit is being kept.
          
          // dont claim twice either, and check if deposits have already been refunded -- > throw
          if (redeemed[sha3(password)] || deposits_refunded ) throw; 
          
          // if we get here the user has provided a valid claim code, and paid deposit
          num_claimed++;
          redeemed[sha3(password)] = true;
          who_claimed[sha3(password)] = msg.sender;
          valid_voucher_code[sha3(password)] += 50 ether;  // add the deposit paid to the claim
          claimers[num_claimed] = sha3(password);    
     }
// Solidity 0.4.6
// Refund Step 1: this function will return the deposits paid first
//                (this step is separate to avoid issues in case the claim refund amounts haven't been loaded yet,
//                 so at least the deposits won't get stuck)
function refund_deposits(string password){ //anyone with a code can call this
            if (deposits_refunded) throw; // already refunded
            if (valid_voucher_code[sha3(password)] == 0) throw; 
            
            // wait till everyone has claimed or claim period ended, and refund-pool has been loaded
            if (num_claimed >= total_claim_codes || block.number >= 2850000 ){  // ~ 21/12/2017
                // first refund the deposits
                for (uint256 index = 1; index <= num_claimed; index++){
                    bytes32 claimcode = claimers[index];
                    address receiver = who_claimed[claimcode];
                    if (!receiver.send(50 ether)) throw; // refund deposit, or throw in case of any error
                    valid_voucher_code[claimcode] -= 50 ether;  // deduct the deposit paid from the claim
                }
                deposits_refunded = true; // can only use this function once
            }
            else throw;
            //
     }
// Solidity 0.4.6
// Refund Step 2: this function will refund actual claim amount. But wait for our notification
//             before calling this function (you can check the contract balance after deposit return)
function refund_claims(string password){ //anyone with a code can call this
            if (!deposits_refunded) throw; // first step 1 (refund_deposits) has to be called
            if (valid_voucher_code[sha3(password)] == 0) throw; 
            
            for (uint256 index = 1; index <= num_claimed; index++){
                bytes32 claimcode = claimers[index];
                address receiver = who_claimed[claimcode];
                uint256 refund_amount = valid_voucher_code[claimcode];
                
                // only refund claims if there is enough left in the claim bucket
                
                if (this.balance >= refund_amount){
                    if (!receiver.send(refund_amount)) throw; // refund deposit, or throw in case of any error
                    valid_voucher_code[claimcode] = 0;  // deduct the deposit paid from the claim
                }
                
            }
     }
// Solidity 0.6.12
// Enqueues a request (if a request isn't already present) for the given (identifier, time) pair.
function requestPrice(bytes32 identifier, uint256 time) public override {
        require(_getIdentifierWhitelist().isIdentifierSupported(identifier));
        Price storage lookup = verifiedPrices[identifier][time];
        if (!lookup.isAvailable && !queryIndices[identifier][time].isValid) {
            // New query, enqueue it for review.
            queryIndices[identifier][time] = QueryIndex(true, requestedPrices.length);
            requestedPrices.push(QueryPoint(identifier, time));
        }
    }
// Solidity 0.6.12
// Pushes the verified price for a requested query.
function pushPrice(
        bytes32 identifier,
        uint256 time,
        int256 price
    ) external {
        verifiedPrices[identifier][time] = Price(true, price, getCurrentTime());

        QueryIndex storage queryIndex = queryIndices[identifier][time];
        require(queryIndex.isValid, "Can't push prices that haven't been requested");
        // Delete from the array. Instead of shifting the queries over, replace the contents of `indexToReplace` with
        // the contents of the last index (unless it is the last index).
        uint256 indexToReplace = queryIndex.index;
        delete queryIndices[identifier][time];
        uint256 lastIndex = requestedPrices.length - 1;
        if (lastIndex != indexToReplace) {
            QueryPoint storage queryToCopy = requestedPrices[lastIndex];
            queryIndices[queryToCopy.identifier][queryToCopy.time].index = indexToReplace;
            requestedPrices[indexToReplace] = queryToCopy;
        }
    }
// Solidity 0.6.11
/*
 @notice deposit token into curve
 */
function _depositIntoCurve(address _token, uint _index) private {
        // token to LP
        uint bal = IERC20(_token).balanceOf(address(this));
        if (bal > 0) {
            IERC20(_token).safeApprove(DEPOSIT, 0);
            IERC20(_token).safeApprove(DEPOSIT, bal);

            // mint LP
            uint[4] memory amounts;
            amounts[_index] = bal;

            /*
            shares = underlying amount * precision div * 1e18 / price per share
            */
            uint pricePerShare = StableSwapBBTC(SWAP).get_virtual_price();
            uint shares = bal.mul(PRECISION_DIV[_index]).mul(1e18).div(pricePerShare);
            uint min = shares.mul(SLIPPAGE_MAX - slippage) / SLIPPAGE_MAX;

            DepositBBTC(DEPOSIT).add_liquidity(amounts, min);
        }

        // stake into LiquidityGaugeV2
        uint lpBal = IERC20(LP).balanceOf(address(this));
        if (lpBal > 0) {
            IERC20(LP).safeApprove(GAUGE, 0);
            IERC20(LP).safeApprove(GAUGE, lpBal);
            LiquidityGaugeV2(GAUGE).deposit(lpBal);
        }
    }
// Solidity 0.6.11
/*
 @notice Returns address and index of token with lowest balance in Curve SWAP
 */
function _getMostPremiumToken() private view returns (address, uint) {
        uint[2] memory balances;
        balances[0] = StableSwapBBTC(SWAP).balances(0).mul(1e10); // BBTC
        balances[1] = StableSwapBBTC(SWAP).balances(1); // SBTC pool

        if (balances[0] <= balances[1]) {
            return (BBTC, 0);
        } else {
            uint[3] memory baseBalances;
            baseBalances[0] = StableSwapSBTC(BASE_POOL).balances(0).mul(1e10); // REN_BTC
            baseBalances[1] = StableSwapSBTC(BASE_POOL).balances(1).mul(1e10); // WBTC
            baseBalances[2] = StableSwapSBTC(BASE_POOL).balances(2); // SBTC

            uint minIndex = 0;
            for (uint i = 1; i < baseBalances.length; i++) {
                if (baseBalances[i] <= baseBalances[minIndex]) {
                    minIndex = i;
                }
            }

            /*
            REN_BTC 1
            WBTC    2
            SBTC    3
            */

            if (minIndex == 0) {
                return (REN_BTC, 1);
            }
            if (minIndex == 1) {
                return (WBTC, 2);
            }
            // SBTC has low liquidity, so buying is disabled by default
            if (!disableSbtc) {
                return (SBTC, 3);
            }
            return (WBTC, 2);
        }
    }
// Solidity 0.6.11
/*
 @notice Claim CRV and deposit most premium token into Curve
 */
function harvest() external override onlyAuthorized {
        (address token, uint index) = _getMostPremiumToken();

        _claimRewards(token);

        uint bal = IERC20(token).balanceOf(address(this));
        if (bal > 0) {
            // transfer fee to treasury
            uint fee = bal.mul(performanceFee) / PERFORMANCE_FEE_MAX;
            if (fee > 0) {
                address treasury = IController(controller).treasury();
                require(treasury != address(0), "treasury = zero address");

                IERC20(token).safeTransfer(treasury, fee);
            }

            _depositIntoCurve(token, index);
        }
    }
// Solidity 0.8.6
/**
 * @dev Add multiple vesting to contract by arrays of data
 * @param _users[] addresses of holders
 * @param _startTokens[] tokens that can be withdrawn at startDate
 * @param _totalTokens[] total tokens in vesting
 * @param _startDate date from when tokens can be claimed
 * @param _endDate date after which all tokens can be claimed
 */
function massAddHolders(
        address[] calldata _users,
        uint256[] calldata _startTokens,
        uint256[] calldata _totalTokens,
        uint256 _startDate,
        uint256 _endDate
    ) external onlyOwner whenNotLocked {
        uint256 len = _users.length; //cheaper to use one variable
        require((len == _startTokens.length) && (len == _totalTokens.length), "data size mismatch");
        require(_startDate < _endDate, "startDate cannot exceed endDate");
        uint256 i;
        for (i; i < len; i++) {
            _addHolder(_users[i], _startTokens[i], _totalTokens[i], _startDate, _endDate);
        }
    }
// Solidity 0.8.6
/**
 * @dev Add new vesting to contract
 * @param _user address of a holder
 * @param _startTokens how many tokens are claimable at start date
 * @param _totalTokens total number of tokens in added vesting
 * @param _startDate date from when tokens can be claimed
 * @param _endDate date after which all tokens can be claimed
 */
function _addHolder(
        address _user,
        uint256 _startTokens,
        uint256 _totalTokens,
        uint256 _startDate,
        uint256 _endDate
    ) internal {
        require(_user != address(0), "user address cannot be 0");
        Vest memory v;
        v.startTokens = _startTokens;
        v.totalTokens = _totalTokens;
        v.dateStart = _startDate;
        v.dateEnd = _endDate;

        totalVested += _totalTokens;
        vestings.push(v);
        user2vesting[_user].push(vestings.length); // we are skipping index "0" for reasons
        emit Vested(_user, _totalTokens, _endDate);
    }
// Solidity 0.8.6
/**
 * @dev internal claim function
 * @param _user address of holder
 * @param _target where tokens should be send
 * @return amt number of tokens claimed
 */
function _claim(address _user, address _target) internal nonReentrant returns (uint256 amt) {
        require(_target != address(0), "Claim, then burn");
        if (!vestingAdded[_user] && !refunded[_user]) {
            _addVesting(_user);
        }
        uint256 len = user2vesting[_user].length;
        require(len > 0, "No vestings for user");
        uint256 cl;
        uint256 i;
        for (i; i < len; i++) {
            Vest storage v = vestings[user2vesting[_user][i] - 1];
            cl = _claimable(v);
            v.claimedTokens += cl;
            amt += cl;
        }
        if (amt > 0) {
            totalClaimed += amt;
            _transfer(_target, amt);
            emit Claimed(_user, amt);
        } else revert("Nothing to claim");
    }
// Solidity 0.8.6
/**
 * @dev Count how many tokens can be claimed from vesting to date
 * @param _vesting Vesting object
 * @return canWithdraw number of tokens
 */
function _claimable(Vest memory _vesting) internal view returns (uint256 canWithdraw) {
        uint256 currentTime = block.timestamp;
        if (_vesting.dateStart > currentTime) return 0;
        // we are somewhere in the middle
        if (currentTime < _vesting.dateEnd) {
            // how much time passed (as fraction * 10^18)
            // timeRatio = (time passed * 1e18) / duration
            uint256 timeRatio = (currentTime - _vesting.dateStart).divPrecisely(_vesting.dateEnd - _vesting.dateStart);
            // how much tokens we can get in total to date
            canWithdraw = (_vesting.totalTokens - _vesting.startTokens).mulTruncate(timeRatio) + _vesting.startTokens;
        }
        // time has passed, we can take all tokens
        else {
            canWithdraw = _vesting.totalTokens;
        }
        // but maybe we take something earlier?
        canWithdraw -= _vesting.claimedTokens;
    }
// Solidity 0.8.6
/**
 * @dev Read total amount of tokens that user can claim to date from all vestings
 *      Function also includes tokens to claim from sale contracts that were not
 *      yet initiated for user.
 * @param _user address of holder
 * @return amount number of tokens
 */
function getAllClaimable(address _user) public view returns (uint256 amount) {
        uint256 len = user2vesting[_user].length;
        uint256 i;
        for (i; i < len; i++) {
            amount += _claimable(vestings[user2vesting[_user][i] - 1]);
        }

        if (!vestingAdded[_user]) {
            amount += _claimableFromSaleContracts(_user);
        }
    }
// Solidity 0.8.6
/**
 * @dev Extract all the vestings for the user
 *      Also extract not initialized vestings from
 *      sale contracts.
 * @param _user address of holder
 * @return v array of Vest objects
 */
function getVestings(address _user) external view returns (Vest[] memory) {
        // array of pending vestings
        Vest[] memory pV;

        if (!vestingAdded[_user]) {
            pV = _vestingsFromSaleContracts(_user);
        }
        uint256 pLen = pV.length;
        uint256 len = user2vesting[_user].length;
        Vest[] memory v = new Vest[](len + pLen);

        // copy normal vestings
        uint256 i;
        for (i; i < len; i++) {
            v[i] = vestings[user2vesting[_user][i] - 1];
        }

        // copy not initialized vestings
        if (!vestingAdded[_user]) {
            uint256 j;
            for (j; j < pLen; j++) {
                v[i + j] = pV[j];
            }
        }

        return v;
    }
// Solidity 0.8.6
/**
 * @dev Read registered vesting list by range from-to
 * @param _start first index
 * @param _end last index
 * @return array of Vest objects
 */
function getVestingsByRange(uint256 _start, uint256 _end) external view returns (Vest[] memory) {
        uint256 cnt = _end - _start + 1;
        uint256 len = vestings.length;
        require(_end < len, "range error");
        Vest[] memory v = new Vest[](cnt);
        uint256 i;
        for (i; i < cnt; i++) {
            v[i] = vestings[_start + i];
        }
        return v;
    }
// Solidity 0.8.6
/**
 * @dev Register sale contract
 * @param _contractAddresses  addresses of sale contracts
 * @param _tokensPerCent      sale price
 * @param _maxAmount          the maximum amount in USD cents for which user could buy
 * @param _percentOnStart     percentage of vested coins that can be claimed on start date
 * @param _startDate          date when initial vesting can be released
 * @param _endDate            final date of vesting, where all tokens can be claimed
 */
function addSaleContract(
        address[] memory _contractAddresses,
        uint256 _tokensPerCent,
        uint256 _maxAmount,
        uint256 _percentOnStart,
        uint256 _startDate,
        uint256 _endDate
    ) external onlyOwner whenNotLocked {
        require(_contractAddresses.length > 0, "data is missing");
        require(_startDate < _endDate, "startDate cannot exceed endDate");
        SaleContract memory s;
        s.contractAddresses = _contractAddresses;
        s.tokensPerCent = _tokensPerCent;
        s.maxAmount = _maxAmount;
        s.startDate = _startDate;
        s.percentOnStart = _percentOnStart;
        s.endDate = _endDate;
        saleContracts.push(s);
    }
// Solidity 0.8.6
/**
 * @dev Function iterate sale contracts and initialize corresponding
 *      vesting for user.
 * @param _user address that will be initialized
 */
function _addVesting(address _user) internal {
        require(!refunded[_user], "User refunded");
        require(!vestingAdded[_user], "Already done");
        uint256 len = saleContracts.length;
        uint256 i;
        for (i; i < len; i++) {
            SaleContract memory s = saleContracts[i];
            uint256 sLen = s.contractAddresses.length;
            uint256 j;
            uint256 amt;
            for (j; j < sLen; j++) {
                amt += ISaleContract(s.contractAddresses[j]).balanceOf(_user);
            }
            // amt is in cents, so $100 = 10000
            if (amt > 0) {
                if (amt > s.maxAmount) {
                    amt = s.maxAmount;
                }
                // create Vest object
                Vest memory v = _vestFromSaleContractAndAmount(s, amt);
                // update contract data
                totalVested += v.totalTokens;
                vestings.push(v);
                user2vesting[_user].push(vestings.length);
                emit Vested(_user, v.totalTokens, v.dateEnd);
            }
        }
        vestingAdded[_user] = true;
    }
// Solidity 0.8.6
/**
 * @dev Function iterate sale contracts and count claimable amounts for given user.
 *      Used to calculate claimable amounts from not initialized vestings.
 * @param _user address of user to count claimable
 * @return claimable amount of tokens
 */
function _claimableFromSaleContracts(address _user) internal view returns (uint256 claimable) {
        if (refunded[_user]) return 0;
        uint256 len = saleContracts.length;
        if (len == 0) return 0;
        uint256 i;
        for (i; i < len; i++) {
            SaleContract memory s = saleContracts[i];
            uint256 sLen = s.contractAddresses.length;
            uint256 j;
            uint256 amt;
            for (j; j < sLen; j++) {
                amt += ISaleContract(s.contractAddresses[j]).balanceOf(_user);
            }
            // amt is in cents, so $100 = 10000
            if (amt > 0) {
                if (amt > s.maxAmount) {
                    amt = s.maxAmount;
                }
                claimable += _claimable(_vestFromSaleContractAndAmount(s, amt));
            }
        }
    }
// Solidity 0.8.6
/**
 * @dev Function iterate sale contracts and extract not initialized user vestings.
 *      Used to return all stored and not initialized vestings.
 * @param _user address of user to extract vestings
 * @return v vesting array
 */
function _vestingsFromSaleContracts(address _user) internal view returns (Vest[] memory) {
        uint256 len = saleContracts.length;
        if (refunded[_user] || len == 0) return new Vest[](0);

        Vest[] memory v = new Vest[](_numberOfVestingsFromSaleContracts(_user));
        uint256 i;
        uint256 idx;
        for (i; i < len; i++) {
            SaleContract memory s = saleContracts[i];
            uint256 sLen = s.contractAddresses.length;
            uint256 j;
            uint256 amt;
            for (j; j < sLen; j++) {
                amt += ISaleContract(s.contractAddresses[j]).balanceOf(_user);
            }
            // amt is in cents, so $100 = 10000
            if (amt > 0) {
                if (amt > s.maxAmount) {
                    amt = s.maxAmount;
                }
                v[idx] = _vestFromSaleContractAndAmount(s, amt);
                idx++;
            }
        }
        return v;
    }
// Solidity 0.8.6
/**
 * @dev Function iterate sale contracts and return number of not initialized vestings for user.
 * @param _user address of user to extract vestings
 * @return number of not not initialized user vestings
 */
function _numberOfVestingsFromSaleContracts(address _user) internal view returns (uint256 number) {
        uint256 len = saleContracts.length;
        uint256 i;
        for (i; i < len; i++) {
            SaleContract memory s = saleContracts[i];
            uint256 sLen = s.contractAddresses.length;
            uint256 j;
            uint256 amt;
            for (j; j < sLen; j++) {
                amt += ISaleContract(s.contractAddresses[j]).balanceOf(_user);
            }
            // amt is in cents, so $100 = 10000
            if (amt > 0) {
                number++;
            }
        }
    }
// Solidity 0.8.6
/**
 * @dev Return vesting created from given sale and usd cent amount.
 * @param _sale address of user to extract vestings
 * @param _amount address of user to extract vestings
 * @return v vesting from given parameters
 */
function _vestFromSaleContractAndAmount(SaleContract memory _sale, uint256 _amount) internal pure returns (Vest memory v) {
        v.dateStart = _sale.startDate;
        v.dateEnd = _sale.endDate;
        uint256 total = _amount * _sale.tokensPerCent;
        v.totalTokens = total;
        v.startTokens = (total * _sale.percentOnStart) / 100;
    }
// Solidity 0.4.24
/**
 * @dev Send tokens to other multi addresses in one function
 *
 * @param _destAddrs address The addresses which you want to send tokens to
 * @param _values uint256 the amounts of tokens to be sent
 */
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
        require(_destAddrs.length == _values.length);

        uint256 i = 0;
        for (; i < _destAddrs.length; i = i.add(1)) {
            if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
                break;
            }
        }

        return (i);
    }