lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.11
/**
 * @notice See whitelisted currencies in the system
 * @param cursor cursor (should start at 0 for first request)
 * @param size size of the response (e.g., 50)
 */
function viewWhitelistedCurrencies(uint256 cursor, uint256 size)
        external
        view
        override
        returns (address[] memory, uint256)
    {
        uint256 length = size;

        if (length > _whitelistedCurrencies.length() - cursor) {
            length = _whitelistedCurrencies.length() - cursor;
        }

        address[] memory whitelistedCurrencies = new address[](length);

        for (uint256 i = 0; i < length; i++) {
            whitelistedCurrencies[i] = _whitelistedCurrencies.at(cursor + i);
        }

        return (whitelistedCurrencies, cursor + length);
    }
// Solidity 0.7.3
/// @notice User withdraws converted Basket token
function withdrawBMI(address _token, uint256 _id) public nonReentrant {
        require(_id < curId[_token], "!weaved");
        require(!claimed[_token][msg.sender][_id], "already-claimed");
        uint256 userDeposited = deposits[_token][msg.sender][_id];
        require(userDeposited > 0, "!deposit");

        uint256 ratio = userDeposited.mul(1e18).div(totalDeposited[_token][_id]);
        uint256 userBasketAmount = minted[_token][_id].mul(ratio).div(1e18);
        claimed[_token][msg.sender][_id] = true;

        IERC20(address(bmi)).safeTransfer(msg.sender, userBasketAmount);
    }
// Solidity 0.5.12
/**********************************************************************************************
 // calcSpotPrice                                                                             //
 // sP = spotPrice                                                                            //
 // bI = tokenBalanceIn                ( bI / wI )         1                                  //
 // bO = tokenBalanceOut         sP =  -----------  *  ----------                             //
 // wI = tokenWeightIn                 ( bO / wO )     ( 1 - sF )                             //
 // wO = tokenWeightOut                                                                       //
 // sF = swapFee                                                                              //
 **********************************************************************************************/
function calcSpotPrice(
        uint tokenBalanceIn,
        uint tokenWeightIn,
        uint tokenBalanceOut,
        uint tokenWeightOut,
        uint swapFee
    )
    internal pure
    returns (uint spotPrice)
    {
        uint numer = bdiv(tokenBalanceIn, tokenWeightIn);
        uint denom = bdiv(tokenBalanceOut, tokenWeightOut);
        uint ratio = bdiv(numer, denom);
        uint scale = bdiv(BONE, bsub(BONE, swapFee));
        return  (spotPrice = bmul(ratio, scale));
    }
// Solidity 0.5.12
/**********************************************************************************************
 // calcOutGivenIn                                                                            //
 // aO = tokenAmountOut                                                                       //
 // bO = tokenBalanceOut                                                                      //
 // bI = tokenBalanceIn              /      /            bI             \    (wI / wO) \      //
 // aI = tokenAmountIn    aO = bO * |  1 - | --------------------------  | ^            |     //
 // wI = tokenWeightIn               \      \ ( bI + ( aI * ( 1 - sF )) /              /      //
 // wO = tokenWeightOut                                                                       //
 // sF = swapFee                                                                              //
 **********************************************************************************************/
function calcOutGivenIn(
        uint tokenBalanceIn,
        uint tokenWeightIn,
        uint tokenBalanceOut,
        uint tokenWeightOut,
        uint tokenAmountIn,
        uint swapFee
    )
    public pure
    returns (uint tokenAmountOut)
    {
        uint weightRatio = bdiv(tokenWeightIn, tokenWeightOut);
        uint adjustedIn = bsub(BONE, swapFee);
        adjustedIn = bmul(tokenAmountIn, adjustedIn);
        uint y = bdiv(tokenBalanceIn, badd(tokenBalanceIn, adjustedIn));
        uint foo = bpow(y, weightRatio);
        uint bar = bsub(BONE, foo);
        tokenAmountOut = bmul(tokenBalanceOut, bar);
        return tokenAmountOut;
    }
// Solidity 0.5.12
/**********************************************************************************************
 // calcInGivenOut                                                                            //
 // aI = tokenAmountIn                                                                        //
 // bO = tokenBalanceOut               /  /     bO      \    (wO / wI)      \                 //
 // bI = tokenBalanceIn          bI * |  | ------------  | ^            - 1  |                //
 // aO = tokenAmountOut    aI =        \  \ ( bO - aO ) /                   /                 //
 // wI = tokenWeightIn           --------------------------------------------                 //
 // wO = tokenWeightOut                          ( 1 - sF )                                   //
 // sF = swapFee                                                                              //
 **********************************************************************************************/
function calcInGivenOut(
        uint tokenBalanceIn,
        uint tokenWeightIn,
        uint tokenBalanceOut,
        uint tokenWeightOut,
        uint tokenAmountOut,
        uint swapFee
    )
    public pure
    returns (uint tokenAmountIn)
    {
        uint weightRatio = bdiv(tokenWeightOut, tokenWeightIn);
        uint diff = bsub(tokenBalanceOut, tokenAmountOut);
        uint y = bdiv(tokenBalanceOut, diff);
        uint foo = bpow(y, weightRatio);
        foo = bsub(foo, BONE);
        tokenAmountIn = bsub(BONE, swapFee);
        tokenAmountIn = bdiv(bmul(tokenBalanceIn, foo), tokenAmountIn);
        return tokenAmountIn;
    }
// Solidity 0.5.12
/**********************************************************************************************
 // calcPoolOutGivenSingleIn                                                                  //
 // pAo = poolAmountOut         /                                              \              //
 // tAi = tokenAmountIn        ///      /     //    wI \      \\       \     wI \             //
 // wI = tokenWeightIn        //| tAi *| 1 - || 1 - --  | * sF || + tBi \    --  \            //
 // tW = totalWeight     pAo=||  \      \     \\    tW /      //         | ^ tW   | * pS - pS //
 // tBi = tokenBalanceIn      \\  ------------------------------------- /        /            //
 // pS = poolSupply            \\                    tBi               /        /             //
 // sF = swapFee                \                                              /              //
 **********************************************************************************************/
function calcPoolOutGivenSingleIn(
        uint tokenBalanceIn,
        uint tokenWeightIn,
        uint poolSupply,
        uint totalWeight,
        uint tokenAmountIn,
        uint swapFee
    )
    internal pure
    returns (uint poolAmountOut)
    {
        // Charge the trading fee for the proportion of tokenAi
        ///  which is implicitly traded to the other pool tokens.
        // That proportion is (1- weightTokenIn)
        // tokenAiAfterFee = tAi * (1 - (1-weightTi) * poolFee);
        uint normalizedWeight = bdiv(tokenWeightIn, totalWeight);
        uint zaz = bmul(bsub(BONE, normalizedWeight), swapFee);
        uint tokenAmountInAfterFee = bmul(tokenAmountIn, bsub(BONE, zaz));

        uint newTokenBalanceIn = badd(tokenBalanceIn, tokenAmountInAfterFee);
        uint tokenInRatio = bdiv(newTokenBalanceIn, tokenBalanceIn);

        // uint newPoolSupply = (ratioTi ^ weightTi) * poolSupply;
        uint poolRatio = bpow(tokenInRatio, normalizedWeight);
        uint newPoolSupply = bmul(poolRatio, poolSupply);
        poolAmountOut = bsub(newPoolSupply, poolSupply);
        return poolAmountOut;
    }
// Solidity 0.5.12
/**********************************************************************************************
 // calcSingleOutGivenPoolIn                                                                  //
 // tAo = tokenAmountOut            /      /                                             \\   //
 // bO = tokenBalanceOut           /      // pS - (pAi * (1 - eF)) \     /    1    \      \\  //
 // pAi = poolAmountIn            | bO - || ----------------------- | ^ | --------- | * b0 || //
 // ps = poolSupply                \      \\          pS           /     \(wO / tW)/      //  //
 // wI = tokenWeightIn      tAo =   \      \                                             //   //
 // tW = totalWeight                    /     /      wO \       \                             //
 // sF = swapFee                    *  | 1 - |  1 - ---- | * sF  |                            //
 // eF = exitFee                        \     \      tW /       /                             //
 **********************************************************************************************/
function calcSingleOutGivenPoolIn(
        uint tokenBalanceOut,
        uint tokenWeightOut,
        uint poolSupply,
        uint totalWeight,
        uint poolAmountIn,
        uint swapFee
    )
    internal pure
    returns (uint tokenAmountOut)
    {
        uint normalizedWeight = bdiv(tokenWeightOut, totalWeight);
        // charge exit fee on the pool token side
        // pAiAfterExitFee = pAi*(1-exitFee)
        uint poolAmountInAfterExitFee = bmul(poolAmountIn, BONE);
        uint newPoolSupply = bsub(poolSupply, poolAmountInAfterExitFee);
        uint poolRatio = bdiv(newPoolSupply, poolSupply);

        // newBalTo = poolRatio^(1/weightTo) * balTo;
        uint tokenOutRatio = bpow(poolRatio, bdiv(BONE, normalizedWeight));
        uint newTokenBalanceOut = bmul(tokenOutRatio, tokenBalanceOut);

        uint tokenAmountOutBeforeSwapFee = bsub(tokenBalanceOut, newTokenBalanceOut);

        // charge swap fee on the output token side
        //uint tAo = tAoBeforeSwapFee * (1 - (1-weightTo) * swapFee)
        uint zaz = bmul(bsub(BONE, normalizedWeight), swapFee);
        tokenAmountOut = bmul(tokenAmountOutBeforeSwapFee, bsub(BONE, zaz));
        return tokenAmountOut;
    }
// Solidity 0.5.12
// DSMath.wpow
function bpowi(uint a, uint n)
    internal pure
    returns (uint)
    {
        uint z = n % 2 != 0 ? a : BONE;

        for (n /= 2; n != 0; n /= 2) {
            a = bmul(a, a);

            if (n % 2 != 0) {
                z = bmul(z, a);
            }
        }
        return z;
    }
// Solidity 0.5.12
// Compute b^(e.w) by splitting it into (b^e)*(b^0.w).
// Use `bpowi` for `b^e` and `bpowK` for k iterations
// of approximation of b^0.w
function bpow(uint base, uint exp)
    internal pure
    returns (uint)
    {
        require(base >= MIN_BPOW_BASE, "ERR_BPOW_BASE_TOO_LOW");
        require(base <= MAX_BPOW_BASE, "ERR_BPOW_BASE_TOO_HIGH");

        uint whole  = bfloor(exp);
        uint remain = bsub(exp, whole);

        uint wholePow = bpowi(base, btoi(whole));

        if (remain == 0) {
            return wholePow;
        }

        uint partialResult = bpowApprox(base, remain, BPOW_PRECISION);
        return bmul(wholePow, partialResult);
    }
// Solidity 0.4.18
// runs when crowdsale is active - can only be called by main crowdsale contract
function crowdsale ( address tokenholder  ) onlyFront payable {
        
        
        uint award;  // amount of dragons to send to tokenholder
        uint donation; // donation to charity
        DragonPricing pricingstructure = new DragonPricing();
        ( award , donation ) = pricingstructure.crowdsalepricing( tokenholder, msg.value, crowdsaleCounter ); 
         crowdsaleCounter += award;
        
        tokenReward.transfer ( tokenholder , award ); // immediate transfer to token holders
       
        if ( advisorCut < advisorTotal ) { advisorSiphon();} // send advisor his share
       
        else 
          { beneficiary.transfer ( msg.value ); } //send all ether to beneficiary
        
        etherRaised = etherRaised.add( msg.value );  //etherRaised += msg.value; // tallies ether raised
        tokensSold = tokensSold.add(award); //tokensSold  += award; // tallies total dragons sold
       
        
        
    }
// Solidity 0.4.18
// pays the advisor part of the incoming ether
function advisorSiphon() internal {
        
         uint share = msg.value/10;
         uint foradvisor = share;
             
           if ( (advisorCut + share) > advisorTotal ) foradvisor = advisorTotal.sub( advisorCut ); 
             
           advisor.transfer ( foradvisor );  // advisor gets 10% of the incoming ether
            
           advisorCut = advisorCut.add( foradvisor );
           beneficiary.transfer( share * 9 ); // the ether balance goes to the benfeciary
           if ( foradvisor != share ) beneficiary.transfer( share.sub(foradvisor) ); // if 10% of the incoming ether exceeds the total advisor is supposed to get , then this gives them a smaller share to not exceed max
        
        
        
    }
// Solidity 0.4.18
//manually send different dragon packages
function manualSend ( address tokenholder, uint packagenumber ) onlyOwner {
        
          require ( tokenholder != 0x00 );
          if ( packagenumber != 1 &&  packagenumber != 2 &&  packagenumber != 3 ) revert();
        
          uint award;
          uint donation;
          
          if ( packagenumber == 1 )  { award =   10800000000; donation =   800000000; }
          if ( packagenumber == 2 )  { award =  108800000000; donation =  8800000000; }
          if ( packagenumber == 3 )  { award = 1088800000000; donation = 88800000000; }
          
          
          tokenReward.transfer ( tokenholder , award ); 
          tokenReward.transfer ( charity , donation ); 
          
          presold = presold.add( award ); //add number of tokens sold in presale
          presold = presold.add( donation ); //add number of tokens sent via charity
          tokensSold = tokensSold.add(award); // tallies total dragons sold
          tokensSold = tokensSold.add(donation); // tallies total dragons sold
        
    }
// Solidity 0.4.21
// Allocate tokens for founder vested gradually for 1 year
function allocateTokensForFounder() external isActive onlyOwnerOrAdmin {
        require(saleState == END_SALE);
        require(founderAddress != address(0));
        uint256 amount;
        if (founderAllocatedTime == 1) {
            amount = founderAllocation;
            balances[founderAddress] = balances[founderAddress].add(amount);
            emit AllocateTokensForFounder(founderAddress, founderAllocatedTime, amount);
            founderAllocatedTime = 2;
            return;
        }
        revert();
    }
// Solidity 0.4.21
// Allocate tokens for team vested gradually for 1 year
function allocateTokensForTeam() external isActive onlyOwnerOrAdmin {
        require(saleState == END_SALE);
        require(teamAddress != address(0));
        uint256 amount;
        if (teamAllocatedTime == 1) {
            amount = teamAllocation * 40/100;
            balances[teamAddress] = balances[teamAddress].add(amount);
            emit AllocateTokensForTeam(teamAddress, teamAllocatedTime, amount);
            teamAllocatedTime = 2;
            return;
        }
        if (teamAllocatedTime == 2) {
            require(now >= icoEndTime + lockPeriod1);
            amount = teamAllocation * 60/100;
            balances[teamAddress] = balances[teamAddress].add(amount);
            emit AllocateTokensForTeam(teamAddress, teamAllocatedTime, amount);
            teamAllocatedTime = 3;
            return;
        }
        revert();
    }
// Solidity 0.6.8
/**
 * @dev Create deterministic vault.
 */
function executeVault(bytes32 _key, IERC20 _token, address _to) internal returns (uint256 value) {
        address addr;
        bytes memory slotcode = code;

        /* solium-disable-next-line */
        assembly{
          // Create the contract arguments for the constructor
          addr := create2(0, add(slotcode, 0x20), mload(slotcode), _key)
        }

        value = _token.balanceOf(addr);
        /* solium-disable-next-line */
        (bool success, ) = addr.call(
            abi.encodePacked(
                abi.encodeWithSelector(
                    _token.transfer.selector,
                    _to,
                    value
                ),
                address(_token)
            )
        );

        require(success, "Error pulling tokens");
    }
// Solidity 0.6.8
/**
 * @notice Create an ETH to token order
 * @param _data - Bytes of an ETH to token order. See `encodeEthOrder` for more info
 */
function depositEth(
        bytes calldata _data
    ) external payable {
        require(msg.value > 0, "HyperLimit#depositEth: VALUE_IS_0");

        (
            address module,
            address inputToken,
            address payable owner,
            address witness,
            bytes memory data,
        ) = decodeOrder(_data);

        require(inputToken == ETH_ADDRESS, "HyperLimit#depositEth: WRONG_INPUT_TOKEN");

        bytes32 key = keyOf(
            IModule(uint160(module)),
            IERC20(inputToken),
            owner,
            witness,
            data
        );

        ethDeposits[key] = ethDeposits[key].add(msg.value);
        emit DepositETH(key, msg.sender, msg.value, _data);
    }
// Solidity 0.6.8
/**
 * @notice Cancel order
 * @dev The params should be the same used for the order creation
 * @param _module - Address of the module to use for the order execution
 * @param _inputToken - Address of the input token
 * @param _owner - Address of the order's owner
 * @param _witness - Address of the witness
 * @param _data - Bytes of the order's data
 */
function cancelOrder(
        IModule _module,
        IERC20 _inputToken,
        address payable _owner,
        address _witness,
        bytes calldata _data
    ) external {
        require(msg.sender == _owner, "HyperLimit#cancelOrder: INVALID_OWNER");
        bytes32 key = keyOf(
            _module,
            _inputToken,
            _owner,
            _witness,
            _data
        );

        uint256 amount = _pullOrder(_inputToken, key, msg.sender);

        emit OrderCancelled(
            key,
            address(_inputToken),
            _owner,
            _witness,
            _data,
            amount
        );
    }
// Solidity 0.6.8
/**
 * @notice Get the calldata needed to create a token to token/ETH order
 * @dev Returns the input data that the user needs to use to create the order
 * The _secret is used to prevent a front-running at the order execution
 * The _amount is used as the param `_value` for the ERC20 `transfer` function
 * @param _module - Address of the module to use for the order execution
 * @param _inputToken - Address of the input token
 * @param _owner - Address of the order's owner
 * @param _witness - Address of the witness
 * @param _data - Bytes of the order's data
 * @param _secret - Private key of the _witness
 * @param _amount - uint256 of the order amount
 * @return bytes - input data to send the transaction
 */
function encodeTokenOrder(
        IModule _module,
        IERC20 _inputToken,
        address payable _owner,
        address _witness,
        bytes calldata _data,
        bytes32 _secret,
        uint256 _amount
    ) external view returns (bytes memory) {
        return abi.encodeWithSelector(
            _inputToken.transfer.selector,
            vaultOfOrder(
                _module,
                _inputToken,
                _owner,
                _witness,
                _data
            ),
            _amount,
            abi.encode(
                _module,
                _inputToken,
                _owner,
                _witness,
                _data,
                _secret
            )
        );
    }
// Solidity 0.6.12
/**
 	 * @notice Accepts a deposit to the gToken using ETH. The gToken must
 	 *         have WETH as its reserveToken. This is a payable method and
 	 *         expects ETH to be sent; which in turn will be converted into
 	 *         shares. See GToken.sol and GTokenBase.sol for further
 	 *         documentation.
 	 * @param _growthToken The WETH based gToken.
 	 */
function deposit(address _growthToken) public payable
	{
		address _from = msg.sender;
		uint256 _cost = msg.value;
		address _reserveToken = GToken(_growthToken).reserveToken();
		require(_reserveToken == $.WETH, "ETH operation not supported by token");
		G.safeWrap(_cost);
		G.approveFunds(_reserveToken, _growthToken, _cost);
		GToken(_growthToken).deposit(_cost);
		uint256 _netShares = G.getBalance(_growthToken);
		G.pushFunds(_growthToken, _from, _netShares);
	}
// Solidity 0.6.8
/**
 * @notice Get order's properties
 * @param _data - Bytes of the order
 * @return module - Address of the module to use for the order execution
 * @return inputToken - Address of the input token
 * @return owner - Address of the order's owner
 * @return witness - Address of the witness
 * @return data - Bytes of the order's data
 * @return secret -  Private key of the _witness
 */
function decodeOrder(
        bytes memory _data
    ) public pure returns (
        address module,
        address inputToken,
        address payable owner,
        address witness,
        bytes memory data,
        bytes32 secret
    ) {
        (
            module,
            inputToken,
            owner,
            witness,
            data,
            secret
        ) = abi.decode(
            _data,
            (
                address,
                address,
                address,
                address,
                bytes,
                bytes32
            )
        );
    }
// Solidity 0.6.8
/**
 * @notice Executes an order
 * @dev The sender should use the _secret to sign its own address
 * to prevent front-runnings
 * @param _module - Address of the module to use for the order execution
 * @param _inputToken - Address of the input token
 * @param _owner - Address of the order's owner
 * @param _data - Bytes of the order's data
 * @param _signature - Signature to calculate the witness
 * @param _auxData - Bytes of the auxiliar data used for the handlers to execute the order
 */
function executeOrder(
        IModule _module,
        IERC20 _inputToken,
        address payable _owner,
        bytes calldata _data,
        bytes calldata _signature,
        bytes calldata _auxData
    ) external {
        // Calculate witness using signature
        address witness = ECDSA.recover(
            keccak256(abi.encodePacked(msg.sender)),
            _signature
        );

        bytes32 key = keyOf(
            _module,
            _inputToken,
            _owner,
            witness,
            _data
        );

        // Pull amount
        uint256 amount = _pullOrder(_inputToken, key, address(_module));
        require(amount > 0, "HyperLimit#executeOrder: INVALID_ORDER");

        uint256 bought = _module.execute(
            _inputToken,
            amount,
            _owner,
            _data,
            _auxData
        );

        emit OrderExecuted(
            key,
            address(_inputToken),
            _owner,
            witness,
            _data,
            _auxData,
            amount,
            bought
        );
    }