lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 * @dev Transfer token for a specified addresses
 * @param _from The address to transfer from.
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred.
 */
function _transfer(address _from, address _to, uint _value) internal {

require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
}
// Solidity 0.8.7
/**
 * @dev Hook that is called before any token transfer. This includes minting
 * and burning.
 * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
 */
function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override(ERC721) {
        super._beforeTokenTransfer(from, to, tokenId);
        Molecule memory mol = allMolecules[tokenId];
        require(mol.bonded == false,"Molecule is bonded!");
        mol.currentOwner = to;
        mol.numberOfTransfers += 1;
        mol.forSale = false;
        allMolecules[tokenId] = mol;
        if (from == address(0)) {
            _addTokenToAllTokensEnumeration(tokenId);
        } else if (from != to) {
            _removeTokenFromOwnerEnumeration(from, tokenId);
        }
        if (to == address(0)) {
            _removeTokenFromAllTokensEnumeration(tokenId);
        } else if (to != from) {
            _addTokenToOwnerEnumeration(to, tokenId);
        }
    }
// Solidity 0.8.7
// upgrade contract to allow OXG Nodes to 
function bondMolecule(address account,uint256 _tokenId, uint256 nodeCreationTime) external onlyAuthorized {
        require(_exists(_tokenId), "token not found");
        address tokenOwner = ownerOf(_tokenId);
        require(tokenOwner == account, "not owner");
        Molecule memory mol = allMolecules[_tokenId];
        require(mol.bonded == false, "Molecule already bonded");
        mol.bonded = true;
        allMolecules[_tokenId] = mol;
        emit moleculeBonded(_tokenId, account, nodeCreationTime);
    }
// Solidity 0.4.24
//  ownerOf(): get the current owner of point _tokenId
//
function ownerOf(uint256 _tokenId)
      public
      view
      validPointId(_tokenId)
      returns (address owner)
    {
      uint32 id = uint32(_tokenId);

      //  this will throw if the owner is the zero address,
      //  active points always have a valid owner.
      //
      require(azimuth.isActive(id));

      return azimuth.getOwner(id);
    }
// Solidity 0.4.24
//  safeTransferFrom(): transfer point _tokenId from _from to _to,
//                      and call recipient if it's a contract
//
function safeTransferFrom(address _from, address _to, uint256 _tokenId,
                              bytes _data)
      public
    {
      //  perform raw transfer
      //
      transferFrom(_from, _to, _tokenId);

      //  do the callback last to avoid re-entrancy
      //
      if (_to.isContract())
      {
        bytes4 retval = ERC721Receiver(_to)
                        .onERC721Received(msg.sender, _from, _tokenId, _data);
        //
        //  standard return idiom to confirm contract semantics
        //
        require(retval == erc721Received);
      }
    }
// Solidity 0.6.12
/// @notice Gets the maximum amount of debt available to generate
/// @param _cdpId Id of the CDP
/// @param _ilk Ilk of the CDP
function getMaxDebt(uint256 _cdpId, bytes32 _ilk) public override view returns (uint256) {
        uint256 price = getPrice(_ilk);

        (, uint256 mat) = spotter.ilks(_ilk);
        (uint256 collateral, uint256 debt) = getCdpInfo(manager, _cdpId, _ilk);

        return sub(wdiv(wmul(collateral, price), mat), debt);
    }
// Solidity 0.4.24
//  transferFrom(): transfer point _tokenId from _from to _to,
//                  WITHOUT notifying recipient contract
//
function transferFrom(address _from, address _to, uint256 _tokenId)
      public
      validPointId(_tokenId)
    {
      uint32 id = uint32(_tokenId);
      require(azimuth.isOwner(id, _from));

      //  the ERC721 operator/approved address (if any) is
      //  accounted for in transferPoint()
      //
      transferPoint(id, _to, true);
    }
// Solidity 0.8.6
// Check to see if the sell amount is greater than 5% of tokens in a 7 day period
function _justTakingProfits(uint256 sellAmount, address account) private view returns(bool) {
        // Basic cheak to see if we are selling more than 5% - if so return false
        if ((sellAmount * 20) > _balances[account]) {
            return false;
        } else {
            return true;
        }
    }
// Solidity 0.8.6
// Calculate the number of taxed tokens for a transaction
function _getTaxedValue(uint256 transTokens, address account) private view returns(uint256){
        uint256 taxRate = _getTaxRate(account);
        if (taxRate == 0) {
            return 0;
        } else {
            uint256 numerator = (transTokens * (10000 - (100 * taxRate)));
            return (((transTokens * 10000) - numerator) / 10000);
        }
    }
// Solidity 0.8.6
// Calculate the current tax rate.
function _getTaxRate(address account) private view returns(uint256) {
        uint256 numHours = _getHours(_tradingStartTimestamp, block.timestamp);

        if (numHours <= 24){
            // 20% Sell Tax first 24 Hours
            return 20;
        } else if (numHours <= 48){
            // 16% Sell Tax second 24 Hours
            return 16;
        } else {
            // 12% Sell Tax starting rate
            numHours = _getHours(_firstBuy[account], block.timestamp);
            uint256 numDays = (numHours / 24);
            if (numDays >= 84 ){
                //12 x 7 = 84 = tax free!
                return 0;
            } else {
                uint256 numWeeks = (numDays / 7);
                return (12 - numWeeks);
            }
        }
    }
// Solidity 0.5.16
/// @dev Fallback function forwards all transactions and returns all received return data.
function ()
        external
        payable
    {
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            let masterCopy := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
            // 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
            if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
                mstore(0, masterCopy)
                return(0, 0x20)
            }
            calldatacopy(0, 0, calldatasize())
            let success := delegatecall(gas, masterCopy, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            if eq(success, 0) { revert(0, returndatasize()) }
            return(0, returndatasize())
        }
    }
// Solidity 0.6.12
/// @notice Starts the process to move users position 1 collateral and 1 borrow
/// @dev User must approve COMPOUND_IMPORT_FLASH_LOAN to pull _cCollateralToken
/// @param _cCollateralToken Collateral we are moving to DSProxy
/// @param _cBorrowToken Borrow token we are moving to DSProxy
function importLoan(address _cCollateralToken, address _cBorrowToken) external burnGas(20) {
        address proxy = getProxy();

        uint loanAmount = CTokenInterface(_cBorrowToken).borrowBalanceCurrent(msg.sender);
        bytes memory paramsData = abi.encode(_cCollateralToken, _cBorrowToken, msg.sender, proxy);

        givePermission(COMPOUND_IMPORT_FLASH_LOAN);

        lendingPool.flashLoan(COMPOUND_IMPORT_FLASH_LOAN, getUnderlyingAddr(_cBorrowToken), loanAmount, paramsData);

        removePermission(COMPOUND_IMPORT_FLASH_LOAN);

        logger.Log(address(this), msg.sender, "CompoundImport", abi.encode(loanAmount, 0, _cCollateralToken));
    }
// Solidity 0.4.24
//  castUpgradeVote(): as _galaxy, cast a _vote on the ecliptic
//                     upgrade _proposal
//
//    _vote is true when in favor of the proposal, false otherwise
//
//    If this vote results in a majority for the _proposal, it will
//    be upgraded to immediately.
//
function castUpgradeVote(uint8 _galaxy,
                              EclipticBase _proposal,
                              bool _vote)
      external
      activePointVoter(_galaxy)
    {
      //  majority: true if the vote resulted in a majority, false otherwise
      //
      bool majority = polls.castUpgradeVote(_galaxy, _proposal, _vote);

      //  if a majority is in favor of the upgrade, it happens as defined
      //  in the ecliptic base contract
      //
      if (majority)
      {
        upgrade(_proposal);
      }
    }
// Solidity 0.4.24
//  updateUpgradePoll(): check whether the _proposal has achieved
//                      majority, upgrading to it if it has
//
function updateUpgradePoll(EclipticBase _proposal)
      external
    {
      //  majority: true if the poll ended in a majority, false otherwise
      //
      bool majority = polls.updateUpgradePoll(_proposal);

      //  if a majority is in favor of the upgrade, it happens as defined
      //  in the ecliptic base contract
      //
      if (majority)
      {
        upgrade(_proposal);
      }
    }
// Solidity 0.4.24
//
//  Contract owner operations
//
//  createGalaxy(): grant _target ownership of the _galaxy and register
//                  it for voting
//
function createGalaxy(uint8 _galaxy, address _target)
      external
      onlyOwner
    {
      //  only currently unowned (and thus also inactive) galaxies can be
      //  created, and only to non-zero addresses
      //
      require( azimuth.isOwner(_galaxy, 0x0) &&
               0x0 != _target );

      //  new galaxy means a new registered voter
      //
      polls.incrementTotalVoters();

      //  if the caller is sending the galaxy to themselves,
      //  assume it knows what it's doing and resolve right away
      //
      if (msg.sender == _target)
      {
        doSpawn(_galaxy, _target, true, 0x0);
      }
      //
      //  when sending to a "foreign" address, enforce a withdraw pattern,
      //  making the caller the owner in the mean time
      //
      else
      {
        doSpawn(_galaxy, _target, false, msg.sender);
      }
    }
// Solidity 0.4.24
//
//  Buyer operations
//
//  available(): returns true if the _planet is available for purchase
//
function available(uint32 _planet)
      public
      view
      returns (bool result)
    {
      uint16 prefix = azimuth.getPrefix(_planet);

      return ( //  planet must not have an owner yet
               //
               azimuth.isOwner(_planet, 0x0) &&
               //
               //  this contract must be allowed to spawn for the prefix
               //
               azimuth.isSpawnProxy(prefix, this) &&
               //
               //  prefix must be linked
               //
               azimuth.hasBeenLinked(prefix) );
    }
// Solidity 0.4.24
//  purchase(): pay the :price, acquire ownership of the _planet
//
//    discovery of available planets can be done off-chain
//
function purchase(uint32 _planet)
      external
      payable
    {
      require( //  caller must pay exactly the price of a planet
               //
               (msg.value == price) &&
               //
               //  the planet must be available for purchase
               //
               available(_planet) );

      //  spawn the planet to us, then immediately transfer to the caller
      //
      //    spawning to the caller would give the point's prefix's owner
      //    a window of opportunity to cancel the transfer
      //
      Ecliptic ecliptic = Ecliptic(azimuth.owner());
      ecliptic.spawn(_planet, this);
      ecliptic.transferPoint(_planet, msg.sender, false);
      emit PlanetSold(azimuth.getPrefix(_planet), _planet);
    }
// Solidity 0.4.23
/// @dev Transfer tokens to addresses registered for airdrop
/// @param dests Array of addresses that have registered for airdrop
/// @param values Array of token amount for each address that have registered for airdrop
/// @return Number of transfers
function airdrop(address[] dests, uint256[] values) public onlyOwner returns (uint256) {
        require(dests.length == values.length);
        uint256 i = 0;
        while (i < dests.length) {
            token.transfer(dests[i], values[i]);
            i += 1;
        }
        return (i); 
    }
// Solidity 0.5.11
/**
 * @dev Returns the multiplication of two unsigned integers, reverting on overflow.
 */
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
            if (a == 0) {
                return 0;
            }

            uint256 c = a * b;
            require(c / a == b, "SafeMath: multiplication overflow");

            return c;
        }
// Solidity 0.5.11
/**
 * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
 * division by zero. The result is rounded towards zero.
 */
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
            // Solidity only automatically asserts when dividing by 0
            require(b > 0, errorMessage);
            return a / b;
        }
// Solidity 0.4.24
/**
 * @dev Finds currently applicable rate modifier.
 * @return Current rate modifier percentage.
 */
function currentModifier() public view returns (uint256 rateModifier) {
        // solium-disable-next-line security/no-block-members
        uint256 comparisonVariable = now;
        for (uint i = 0; i < modifiers.length; i++) {
            if (comparisonVariable >= modifiers[i].start) {
                rateModifier = modifiers[i].ratePermilles;
            }
        }
    }
// Solidity 0.7.3
/**
 * @dev Delegates the current call to `implementation`.
 *
 * This function does not return to its internall call site, it will return directly to the external caller.
 */
function _delegate(address implementation) internal {
        // solhint-disable-next-line no-inline-assembly
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }
// Solidity 0.6.12
/// @notice Called by Aave when sending back the FL amount
/// @param _reserve The address of the borrowed token
/// @param _amount Amount of FL tokens received
/// @param _fee FL Aave fee
/// @param _params The params that are sent from the original FL caller contract
function executeOperation(
        address _reserve,
        uint256 _amount,
        uint256 _fee,
        bytes calldata _params)
    external override {
        // Format the call data for DSProxy
        (CompCreateData memory compCreate, ExchangeData memory exchangeData)
                                 = packFunctionCall(_amount, _fee, _params);


        address leveragedAsset = _reserve;

        // If the assets are different
        if (compCreate.cCollAddr != compCreate.cDebtAddr) {
            (, uint sellAmount) = _sell(exchangeData);
            getFee(sellAmount, exchangeData.destAddr, compCreate.proxyAddr);

            leveragedAsset = exchangeData.destAddr;
        }

        // Send amount to DSProxy
        sendToProxy(compCreate.proxyAddr, leveragedAsset);

        address compOpenProxy = shifterRegistry.getAddr("COMP_SHIFTER");

        // Execute the DSProxy call
        DSProxyInterface(compCreate.proxyAddr).execute(compOpenProxy, compCreate.proxyData);

        // Repay the loan with the money DSProxy sent back
        transferFundsBackToPoolInternal(_reserve, _amount.add(_fee));

        // if there is some eth left (0x fee), return it to user
        if (address(this).balance > 0) {
            // solhint-disable-next-line avoid-tx-origin
            tx.origin.transfer(address(this).balance);
        }
    }
// Solidity 0.6.12
/// @notice Formats function data call so we can call it through DSProxy
/// @param _amount Amount of FL
/// @param _fee Fee of the FL
/// @param _params Saver proxy params
function packFunctionCall(uint _amount, uint _fee, bytes memory _params) internal pure  returns (CompCreateData memory compCreate, ExchangeData memory exchangeData) {
        (
            uint[4] memory numData, // srcAmount, destAmount, minPrice, price0x
            address[6] memory cAddresses, // cCollAddr, cDebtAddr, srcAddr, destAddr, exchangeAddr, wrapper
            bytes memory callData,
            address proxy
        )
        = abi.decode(_params, (uint256[4],address[6],bytes,address));

        bytes memory proxyData = abi.encodeWithSignature(
            "open(address,address,uint256)",
                                cAddresses[0], cAddresses[1], (_amount + _fee));

         exchangeData = SaverExchangeCore.ExchangeData({
            srcAddr: cAddresses[2],
            destAddr: cAddresses[3],
            srcAmount: numData[0],
            destAmount: numData[1],
            minPrice: numData[2],
            wrapper: cAddresses[5],
            exchangeAddr: cAddresses[4],
            callData: callData,
            price0x: numData[3]
        });

        compCreate = CompCreateData({
            proxyAddr: payable(proxy),
            proxyData: proxyData,
            cCollAddr: cAddresses[0],
            cDebtAddr: cAddresses[1]
        });

        return (compCreate, exchangeData);
    }
// Solidity 0.6.12
//////////////////////// INTERNAL FUNCTIONS //////////////////////////
function _callCloseAndOpen(
        SaverExchangeCore.ExchangeData memory _exchangeData,
        LoanShiftData memory _loanShift
    ) internal {
        address protoAddr = shifterRegistry.getAddr(getNameByProtocol(uint8(_loanShift.fromProtocol)));

        if (_loanShift.wholeDebt) {
            _loanShift.debtAmount = ILoanShifter(protoAddr).getLoanAmount(_loanShift.id1, _loanShift.debtAddr1);
        }

        (
            uint[8] memory numData,
            address[8] memory addrData,
            uint8[3] memory enumData,
            bytes memory callData
        )
        = _packData(_loanShift, _exchangeData);

        // encode data
        bytes memory paramsData = abi.encode(numData, addrData, enumData, callData, address(this));

        address payable loanShifterReceiverAddr = payable(shifterRegistry.getAddr("LOAN_SHIFTER_RECEIVER"));

        loanShifterReceiverAddr.transfer(address(this).balance);

        // call FL
        givePermission(loanShifterReceiverAddr);

        lendingPool.flashLoan(loanShifterReceiverAddr,
           getLoanAddr(_loanShift.debtAddr1, _loanShift.fromProtocol), _loanShift.debtAmount, paramsData);

        removePermission(loanShifterReceiverAddr);

        unsubFromAutomation(
            _loanShift.unsub,
            _loanShift.id1,
            _loanShift.id2,
            _loanShift.fromProtocol,
            _loanShift.toProtocol
        );

        logEvent(_exchangeData, _loanShift);
    }
// Solidity 0.5.11
/**
 * @dev Accept ownership of the contract.
 *
 * Can only be called by the new owner.
 */
function acceptOwnership() public {
            require(msg.sender == _newOwner, "Ownable: caller is not the new owner address");
            require(msg.sender != address(0), "Ownable: caller is the zero address");

            emit OwnershipAccepted(_owner, msg.sender);
            _owner = msg.sender;
            _newOwner = address(0);
        }
// Solidity 0.5.11
/**
 * @dev Rescue compatible ERC20 Token
 *
 * Can only be called by the current owner.
 */
function rescueTokens(address tokenAddr, address recipient, uint256 amount) external onlyOwner {
            IERC20 _token = IERC20(tokenAddr);
            require(recipient != address(0), "Rescue: recipient is the zero address");
            uint256 balance = _token.balanceOf(address(this));

            require(balance >= amount, "Rescue: amount exceeds balance");
            _token.transfer(recipient, amount);
        }
// Solidity 0.6.12
/// @notice Handles that the amount is not bigger than cdp debt and not dust
function limitLoanAmount(uint _cdpId, bytes32 _ilk, uint _paybackAmount, address _owner) internal returns (uint256) {
        uint debt = getAllDebt(address(vat), manager.urns(_cdpId), manager.urns(_cdpId), _ilk);

        if (_paybackAmount > debt) {
            ERC20(DAI_ADDRESS).transfer(_owner, (_paybackAmount - debt));
            return debt;
        }

        uint debtLeft = debt - _paybackAmount;

        (,,,, uint dust) = vat.ilks(_ilk);
        dust = dust / 10**27;

        // Less than dust value
        if (debtLeft < dust) {
            uint amountOverDust = (dust - debtLeft);

            ERC20(DAI_ADDRESS).transfer(_owner, amountOverDust);

            return (_paybackAmount - amountOverDust);
        }

        return _paybackAmount;
    }
// Solidity 0.6.12
/// @notice Bots call this method to repay for user when conditions are met
/// @dev If the contract ownes gas token it will try and use it for gas price reduction
function repayFor(
        SaverExchangeCore.ExchangeData memory _exchangeData,
        uint _cdpId,
        uint _nextPrice,
        address _joinAddr
    ) public payable onlyApproved burnGas(REPAY_GAS_TOKEN) {

        (bool isAllowed, uint ratioBefore) = canCall(Method.Repay, _cdpId, _nextPrice);
        require(isAllowed);

        uint gasCost = calcGasCost(REPAY_GAS_COST);

        address owner = subscriptionsContract.getOwner(_cdpId);

        monitorProxyContract.callExecute{value: msg.value}(
            owner,
            mcdSaverTakerAddress,
            abi.encodeWithSignature(
            "repayWithLoan((address,address,uint256,uint256,uint256,address,address,bytes,uint256),uint256,uint256,address)",
            _exchangeData, _cdpId, gasCost, _joinAddr));


        (bool isGoodRatio, uint ratioAfter) = ratioGoodAfter(Method.Repay, _cdpId, _nextPrice);
        require(isGoodRatio);

        returnEth();

        logger.Log(address(this), owner, "AutomaticMCDRepay", abi.encode(ratioBefore, ratioAfter));
    }
// Solidity 0.5.11
/**
 * @dev Withdraw Ether
 *
 * Can only be called by the current owner.
 */
function withdrawEther(address payable recipient, uint256 amount) external onlyOwner {
            require(recipient != address(0), "Withdraw: recipient is the zero address");

            uint256 balance = address(this).balance;

            require(balance >= amount, "Withdraw: amount exceeds balance");
            recipient.transfer(amount);
        }
// Solidity 0.6.12
/// @notice Gets CDP info (collateral, debt)
/// @param _cdpId Id of the CDP
/// @param _ilk Ilk of the CDP
function getCdpInfo(uint _cdpId, bytes32 _ilk) public view returns (uint, uint) {
        address urn = manager.urns(_cdpId);

        (uint collateral, uint debt) = vat.urns(_ilk, urn);
        (,uint rate,,,) = vat.ilks(_ilk);

        return (collateral, rmul(debt, rate));
    }
// Solidity 0.6.12
/// @notice Gets CDP ratio
/// @param _cdpId Id of the CDP
/// @param _nextPrice Next price for user
function getRatio(uint _cdpId, uint _nextPrice) public view returns (uint) {
        bytes32 ilk = manager.ilks(_cdpId);
        uint price = (_nextPrice == 0) ? getPrice(ilk) : _nextPrice;

        (uint collateral, uint debt) = getCdpInfo(_cdpId, ilk);

        if (debt == 0) return 0;

        return rdiv(wmul(collateral, price), debt) / (10 ** 18);
    }