lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.19
// Called by a token holding address, this method migrates the
// tokens from an older version of the contract to this version.
// The migrated tokens are merged with any existing tokens in this
// version of the contract, resulting in the locked token count
// being set to the sum of locked tokens in the old and new
// contracts and the lock expiration being set the longest lock
// duration for this address in either contract.  The playerId is
// transferred unless it was already set in the new contract.
//
// NOTE - allowances (approve) are *not* transferred.  If you gave
// another address an allowance in the old contract you need to
// re-approve it in the new contract.
//
function optIn() public returns (bool success) {
    require(migrateFrom != MigrationSource(0));
    User storage user = users[msg.sender];
    uint256 balance;
    uint256 lock_value;
    uint256 lock_endTime;
    bytes32 opId;
    bytes32 playerId;
    (balance, lock_value, lock_endTime, opId, playerId) =
        migrateFrom.vacate(msg.sender);

    OptIn(msg.sender, balance);
    
    user.balance = user.balance.add(balance);

    bool lockTimeIncreased = false;
    user.lock_value = user.lock_value.add(lock_value);
    if (user.lock_endTime < lock_endTime) {
      user.lock_endTime = lock_endTime;
      lockTimeIncreased = true;
    }
    if (lock_value > 0 || lockTimeIncreased) {
      LockIncrease(msg.sender, user.lock_value, user.lock_endTime);
    }

    if (user.operatorId == bytes32(0) && opId != bytes32(0)) {
      user.operatorId = opId;
      user.playerId = playerId;
      Associate(msg.sender, msg.sender, opId, playerId);
    }

    totalSupply_ = totalSupply_.add(balance);

    return true;
  }
// Solidity 0.7.6
/**
 * @notice Initiates a new rebase operation, provided the minimum time period has elapsed.
 *
 * @dev The supply adjustment equals (_totalSupply * DeviationFromTargetRate) / rebaseLag
 *      Where DeviationFromTargetRate is (MarketOracleRate - targetRate) / targetRate
 *      and targetRate is CpiOracleRate / baseCpi
 */
function rebase() external onlyOrchestrator {
        require(inRebaseWindow());

        // This comparison also ensures there is no reentrancy.
        require(lastRebaseTimestampSec.add(minRebaseTimeIntervalSec) < block.timestamp);

        // Snap the rebase time to the start of this window.
        lastRebaseTimestampSec = block
            .timestamp
            .sub(block.timestamp.mod(minRebaseTimeIntervalSec))
            .add(rebaseWindowOffsetSec);

        epoch = epoch.add(1);

        uint256 targetRate = TARGET_RATE;

        uint256 exchangeRate;
        bool rateValid;
        (exchangeRate, rateValid) = marketOracle.getData();
        require(rateValid);

        if (exchangeRate > MAX_RATE) {
            exchangeRate = MAX_RATE;
        }

        int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);

        // Apply the Dampening factor.
        supplyDelta = supplyDelta.div(rebaseLag.toInt256Safe());

        if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
            supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
        }

        uint256 supplyAfterRebase = uFrags.rebase(epoch, supplyDelta);
        assert(supplyAfterRebase <= MAX_SUPPLY);
        emit LogRebase(epoch, exchangeRate, supplyDelta, block.timestamp);
    }
// Solidity 0.7.6
/**
 * @dev ZOS upgradable contract initialization method.
 *      It is called at the time of contract creation to invoke parent class initializers and
 *      initialize the contract's state variables.
 */
function initialize(
        address owner_,
        IUFragments uFrags_
    ) public initializer {
        Ownable.initialize(owner_);

        // deviationThreshold = 0.05e18 = 5e16
        deviationThreshold = 5 * 10**(DECIMALS - 2);

        rebaseLag = 3;
        minRebaseTimeIntervalSec = 1 days;
        rebaseWindowOffsetSec = 72000; // 8PM UTC
        rebaseWindowLengthSec = 15 minutes;
        lastRebaseTimestampSec = 0;
        epoch = 0;

        uFrags = uFrags_;
    }
// Solidity 0.7.6
/**
 * @return Computes the total supply adjustment in response to the exchange rate
 *         and the targetRate.
 */
function computeSupplyDelta(uint256 rate, uint256 targetRate) internal view returns (int256) {
        if (withinDeviationThreshold(rate, targetRate)) {
            return 0;
        }

        // supplyDelta = totalSupply * (rate - targetRate) / targetRate
        int256 targetRateSigned = targetRate.toInt256Safe();
        return
            uFrags.totalSupply().toInt256Safe().mul(rate.toInt256Safe().sub(targetRateSigned)).div(
                targetRateSigned
            );
    }
// Solidity 0.4.19
// The vacate method is called by a newer version of the CashBetCoin
// contract to extract the token state for an address and migrate it
// to the new contract.
//
function vacate(address _addr) public returns (uint256 o_balance,
                                                 uint256 o_lock_value,
                                                 uint256 o_lock_endTime,
                                                 bytes32 o_opId,
                                                 bytes32 o_playerId) {
    require(msg.sender == migrateTo);
    User storage user = users[_addr];
    require(user.balance > 0);

    o_balance = user.balance;
    o_lock_value = user.lock_value;
    o_lock_endTime = user.lock_endTime;
    o_opId = user.operatorId;
    o_playerId = user.playerId;

    totalSupply_ = totalSupply_.sub(user.balance);

    user.balance = 0;
    user.lock_value = 0;
    user.lock_endTime = 0;
    user.operatorId = bytes32(0);
    user.playerId = bytes32(0);

    Vacate(_addr, o_balance);
  }
// Solidity 0.8.10
/**
 * @notice Initialize the auction house and base contracts,
 * populate configuration values, and pause the contract.
 * @dev This function can only be called once.
 */
function initialize(
        IAxons _axons,
        IAxonsVoting _axonsVoting,
        address _axonsToken,
        uint256 _timeBuffer,
        uint256 _reservePrice,
        uint8 _minBidIncrementPercentage,
        uint256 _duration
    ) external initializer {
        __Pausable_init();
        __ReentrancyGuard_init();
        __Ownable_init();

        _pause();

        axons = _axons;
        axonsToken = _axonsToken;
        axonsVoting = _axonsVoting;
        timeBuffer = _timeBuffer;
        reservePrice = _reservePrice * 10**18;
        minBidIncrementPercentage = _minBidIncrementPercentage;
        duration = _duration;
    }
// Solidity 0.8.10
/**
 * @dev Generates a random axon number
 * @param _a The address to be used within the hash.
 */
function randomAxonNumber(
        address _a,
        uint256 _c
    ) internal view returns (uint256) {
        uint256 _rand = uint256(
            uint256(
                keccak256(
                    abi.encodePacked(
                        block.timestamp,
                        block.difficulty,
                        _a,
                        _c
                    )
                )
            ) % 900719925474000
        );

        return _rand;
    }
// Solidity 0.8.10
/**
 * @notice Create an auction.
 * @dev Store the auction details in the `auction` state variable and emit an AuctionCreated event.
 * If the mint reverts, the minter was updated without pausing this contract first. To remedy this,
 * catch the revert and pause this contract.
 */
function _createAuction(uint256 axonId) internal {
        try axons.mint(axonId) returns (uint256 tokenId) {
            uint256 startTime = block.timestamp;
            uint256 endTime = startTime + duration;

            auction = Auction({
                axonId: tokenId,
                amount: 0,
                startTime: startTime,
                endTime: endTime,
                bidder: payable(0),
                settled: false,
                counter: auctionCounter
            });

            emit AuctionCreated(axonId, startTime, endTime);

            auctionCounter++;
        } catch Error(string memory) {
            _pause();
        }
    }
// Solidity 0.4.23
/**
 * @notice owner should transfer to this smart contract {_supply} Mozo tokens manually
 * @param _mozoToken Mozo token smart contract
 * @param _coOwner Array of coOwner
 * @param _supply Total number of tokens = No. tokens * 10^decimals = No. tokens * 100
 * @param _rate number of wei to buy 0.01 Mozo sale token
 * @param _openingTime The opening time in seconds (unix Time)
 * @param _closingTime The closing time in seconds (unix Time)
 */
function MozoSaleToken(
        OwnerERC20 _mozoToken,
        address[] _coOwner,
        uint _supply,
        uint _rate,
        uint _openingTime,
        uint _closingTime
    )
    public
    ChainCoOwner(_mozoToken, _coOwner)
    Timeline(_openingTime, _closingTime)
    onlyOwner()
    {
        require(_supply > 0);
        require(_rate > 0);

        rate = _rate;
        totalSupply_ = _supply;

        //assign all sale tokens to owner
        balances[_mozoToken.owner()] = totalSupply_;

        //add owner and co_owner to whitelist
        addAddressToWhitelist(msg.sender);
        addAddressesToWhitelist(_coOwner);
        emit Transfer(0x0, _mozoToken.owner(), totalSupply_);
    }
// Solidity 0.4.23
/**
 * @dev add an address to the whitelist, sender must have enough tokens
 * @param _address address for adding to whitelist
 * @return true if the address was added to the whitelist, false if the address was already in the whitelist
 */
function addAddressToWhitelist(address _address) onlyOwnerOrCoOwner public returns (bool success) {
        if (!whitelist[_address]) {
            whitelist[_address] = true;
            //transfer pending amount of tokens to user
            uint noOfTokens = pendingAmounts[_address];
            if (noOfTokens > 0) {
                pendingAmounts[_address] = 0;
                transfer(_address, noOfTokens);
            }
            success = true;
        }
    }
// Solidity 0.4.23
/**
 * @dev add addresses to the whitelist, sender must have enough tokens
 * @param _addresses addresses for adding to whitelist
 * @return true if at least one address was added to the whitelist, 
 * false if all addresses were already in the whitelist  
 */
function addAddressesToWhitelist(address[] _addresses) onlyOwnerOrCoOwner public returns (bool success) {
        uint length = _addresses.length;
        for (uint i = 0; i < length; i++) {
            if (addAddressToWhitelist(_addresses[i])) {
                success = true;
            }
        }
    }
// Solidity 0.4.23
/**
 * @dev remove addresses from the whitelist
 * @param _addresses addresses
 * @return true if at least one address was removed from the whitelist, 
 * false if all addresses weren't in the whitelist in the first place
 */
function removeAddressesFromWhitelist(address[] _addresses) onlyOwnerOrCoOwner public returns (bool success) {
        uint length = _addresses.length;
        for (uint i = 0; i < length; i++) {
            if (removeAddressFromWhitelist(_addresses[i])) {
                success = true;
            }
        }
    }
// Solidity 0.8.10
/**
 * @notice Settle an auction, finalizing the bid and paying out to the owner.
 * @dev If there are no bids, the Axon is burned.
 */
function _settleAuction() internal {
        IAxonsAuctionHouse.Auction memory _auction = auction;

        require(_auction.startTime != 0, "Auction hasn't begun");
        require(!_auction.settled, 'Auction has already been settled');
        require(block.timestamp >= _auction.endTime, "Auction hasn't completed");

        auction.settled = true;

        if (_auction.bidder == address(0)) {
            axons.burn(_auction.axonId);
        } else {
            axons.transferFrom(address(this), _auction.bidder, _auction.axonId);
        }

        if (_auction.amount > 0) {
            IAxonsToken(axonsToken).transferFrom(address(this), msg.sender, 1 * 10**18);
            IAxonsToken(axonsToken).burn(_auction.amount - (1 * 10**18));
        }

        emit AuctionSettled(_auction.axonId, _auction.bidder, _auction.amount);
    }
// Solidity 0.4.23
/**
 * @param _recipients list of repicients
 * @param _amount list of no. tokens
 */
function bonusToken(address[] _recipients, uint[] _amount) public onlyOwnerOrCoOwner onlyStopping {
        uint len = _recipients.length;
        uint len1 = _amount.length;
        require(len == len1);
        require(len <= MAX_TRANSFER);
        uint i;
        uint total = 0;
        for (i = 0; i < len; i++) {
            if (bonus_transferred_repicients[_recipients[i]] == false) {
                bonus_transferred_repicients[_recipients[i]] = transfer(_recipients[i], _amount[i]);
                total = total.add(_amount[i]);
            }
        }
        totalBonusToken = totalBonusToken.add(total);
        noBonusTokenRecipients = noBonusTokenRecipients.add(len);
    }
// Solidity 0.5.7
/**
 * Add an address to the whitelist
 *
 * @param _key     Key type address to add to the whitelist
 * @param _value   Value type address to add to the whitelist under _key
 */
function addPair(
        address _key,
        address _value
    )
        external
        timeLockUpgrade
    {
        require(
            whitelist[_key] == address(0),
            "AddressToAddressWhiteList.addPair: Address pair already exists."
        );

        require(
            _value != address(0),
            "AddressToAddressWhiteList.addPair: Value must be non zero."
        );

        keys.push(_key);
        whitelist[_key] = _value;

        emit PairAdded(_key, _value);
    }
// Solidity 0.5.7
/**
 * Remove a address to address pair from the whitelist
 *
 * @param _key    Key type address to remove to the whitelist
 */
function removePair(
        address _key
    )
        external
        timeLockUpgrade
    {
        address valueToRemove = whitelist[_key];

        require(
            valueToRemove != address(0),
            "AddressToAddressWhiteList.removePair: key type address is not current whitelisted."
        );

        keys = keys.remove(_key);
        whitelist[_key] = address(0);

        emit PairRemoved(_key, valueToRemove);
    }
// Solidity 0.5.7
/**
 * Edit value type address associated with a key
 *
 * @param _key       Key type address to add to the whitelist
 * @param _value     Value type address to add to the whitelist under _key
 */
function editPair(
        address _key,
        address _value
    )
        external
        timeLockUpgrade
    {
        require(
            whitelist[_key] != address(0),
            "AddressToAddressWhiteList.editPair: Address pair must exist."
        );

        require(
            _value != address(0),
            "AddressToAddressWhiteList.editPair: New value must be non zero."
        );

        emit PairRemoved(
            _key,
            whitelist[_key]
        );

        // Set new value type address for passed key type address
        whitelist[_key] = _value;

        emit PairAdded(
            _key,
            _value
        );
    }
// Solidity 0.5.7
/**
 * Return array of value type addresses based on passed in key type addresses
 *
 * @param  _key                Array of key type addresses to get value type addresses for
 * @return address[]           Array of value type addresses
 */
function getValues(
        address[] calldata _key
    )
        external
        view
        returns (address[] memory)
    {
        // Get length of passed array
        uint256 arrayLength = _key.length;

        // Instantiate value type addresses array
        address[] memory values = new address[](arrayLength);

        for (uint256 i = 0; i < arrayLength; i++) {
            // Get value type address for key type address at index i
            values[i] = getValue(
                _key[i]
            );
        }

        return values;
    }
// Solidity 0.5.7
/**
 * Return value type address associated with a passed key type address
 *
 * @param  _key               Address of key type
 * @return address            Address associated with _key
 */
function getValue(
        address _key
    )
        public
        view
        returns (address)
    {
        // Require key to have matching value type address
        require(
            whitelist[_key] != address(0),
            "AddressToAddressWhiteList.getValue: No value for that address."
        );

        // Return address associated with key
        return whitelist[_key];
    }
// Solidity 0.5.7
/**
 * Verifies an array of addresses against the whitelist
 *
 * @param  _keys                Array of key type addresses to check if value exists
 * @return bool                 Whether all addresses in the list are whitelisted
 */
function areValidAddresses(
        address[] calldata _keys
    )
        external
        view
        returns (bool)
    {
        // Get length of passed array
        uint256 arrayLength = _keys.length;

        for (uint256 i = 0; i < arrayLength; i++) {
            // Return false if key type address doesn't have matching value type address
            if (whitelist[_keys[i]] == address(0)) {
                return false;
            }
        }

        return true;
    }
// Solidity 0.4.25
/**
 * @dev calculate reward
 */
function calculateReward(address _addr, uint256 _round) public view returns(uint256)
    {
        Player memory p = players[_addr];
        Game memory g = games[_round];
        if (g.endTime > now) return 0;
        if (g.crystals == 0) return 0;
        if (p.lastRound >= _round) return 0; 
        return SafeMath.div(SafeMath.mul(g.prizePool, p.share), g.crystals);
    }
// Solidity 0.4.26
/**
 	 * @notice `msg.sender` approves `_spender` to spend `_value` tokens
 	 * @param _spender The address of the account able to transfer the tokens
 	 * @param _value The amount of tokens to be approved for transfer
 	 * @return Whether the approval was successful or not
 	 */
function approve(address _spender, uint256 _value) public returns (bool success) {
		// The amount has to be bigger or equal to 0
		require(_value >= 0);

		allowances[msg.sender][_spender] = _value;

		// Generate the public approval event and return success
		emit Approval(msg.sender, _spender, _value);
		return true;
	}
// Solidity 0.6.12
// Withdraw partial funds, normally used with a jar withdrawal
function withdraw(uint256 _amount) external {
        require(msg.sender == controller, "!controller");
        uint256 _balance = IERC20_1(want).balanceOf(address(this));
        if (_balance < _amount) {
            _amount = _withdrawSome(_amount.sub(_balance));
            _amount = _amount.add(_balance);
        }

        uint256 _feeDev = _amount.mul(withdrawalDevFundFee).div(
            withdrawalDevFundMax
        );
        IERC20_1(want).safeTransfer(IController(controller).devfund(), _feeDev);

        uint256 _feeTreasury = _amount.mul(withdrawalTreasuryFee).div(
            withdrawalTreasuryMax
        );
        IERC20_1(want).safeTransfer(
            IController(controller).treasury(),
            _feeTreasury
        );

        address _jar = IController(controller).jars(address(want));
        require(_jar != address(0), "!jar"); // additional protection so we don't burn the funds

        IERC20_1(want).safeTransfer(_jar, _amount.sub(_feeDev).sub(_feeTreasury));
    }
// Solidity 0.6.12
// Withdraw all funds, normally used when migrating strategies
function withdrawAll() external returns (uint256 balance) {
        require(msg.sender == controller, "!controller");
        _withdrawAll();

        balance = IERC20_1(want).balanceOf(address(this));

        address _jar = IController(controller).jars(address(want));
        require(_jar != address(0), "!jar"); // additional protection so we don't burn the funds
        IERC20_1(want).safeTransfer(_jar, balance);
    }
// Solidity 0.6.12
// **** Emergency functions ****
function execute(address _target, bytes memory _data)
        public
        payable
        returns (bytes memory response)
    {
        require(msg.sender == timelock, "!timelock");
        require(_target != address(0), "!target");

        // call contract in current context
        assembly {
            let succeeded := delegatecall(
                sub(gas(), 5000),
                _target,
                add(_data, 0x20),
                mload(_data),
                0,
                0
            )
            let size := returndatasize()

            response := mload(0x40)
            mstore(
                0x40,
                add(response, and(add(add(size, 0x20), 0x1f), not(0x1f)))
            )
            mstore(response, size)
            returndatacopy(add(response, 0x20), 0, size)

            switch iszero(succeeded)
                case 1 {
                    // throw if delegatecall failed
                    revert(add(response, 0x20), size)
                }
        }
    }
// Solidity 0.4.24
// transfer tokens held by this contract in escrow to the recipient. Used when either claiming or cancelling gifts
function transferFromEscrow(address _recipient,uint256 _tokenId) internal{
        require(super.ownerOf(_tokenId) == address(this),"The card must be owned by the contract for it to be in escrow");
        super.clearApproval(this, _tokenId);
        super.removeTokenFrom(this, _tokenId);
        super.addTokenTo(_recipient, _tokenId);
        emit Transfer(this, _recipient, _tokenId);
    }
// Solidity 0.4.8
//Allow addresses to buy token for another account
function buyRecipient(address recipient) public payable whenNotHalted {
        if(msg.value == 0) throw;
        if(!(preCrowdsaleOn()||crowdsaleOn())) throw;//only allows during presale/crowdsale
        if(contributions[recipient].add(msg.value)>perAddressCap()) throw;//per address cap
        uint256 tokens = msg.value.mul(returnRate()); //decimals=18, so no need to adjust for unit
        if(crowdsaleTokenSold.add(tokens)>crowdsaleTokenSupply) throw;//max supply limit

        balances[recipient] = balances[recipient].add(tokens);
        totalSupply = totalSupply.add(tokens);
        presaleEtherRaised = presaleEtherRaised.add(msg.value);
        contributions[recipient] = contributions[recipient].add(msg.value);
        crowdsaleTokenSold = crowdsaleTokenSold.add(tokens);
        if(crowdsaleTokenSold == crowdsaleTokenSupply){
        //If crowdsale token sold out, end crowdsale
            if(block.number < preEndBlock) {
                preEndBlock = block.number;
            }
            endBlock = block.number;
        }
        if (!multisig.send(msg.value)) throw; //immediately send Ether to multisig address
        Transfer(this, recipient, tokens);
    }
// Solidity 0.4.8
//Return rate of token against ether.
function returnRate() public constant returns(uint256) {
        if (block.number>=startBlock && block.number<=preEndBlock) return 8888; //Pre-crowdsale
        if (block.number>=phase1StartBlock && block.number<=phase1EndBlock) return 8000; //Crowdsale phase1
        if (block.number>phase1EndBlock && block.number<=phase2EndBlock) return 7500; //Phase2
        if (block.number>phase2EndBlock && block.number<=phase3EndBlock) return 7000; //Phase3
    }