0

I'm making if else function and if price == stopOrder it should do executeOrder but it's giving me error

    function sellLogic() public {
        require(StopOrder != 0 || LimitOrder != 0, "stop order or LimitOrder are 0!");

       
        //if else to se if it will sell during the dump
       
        if (price >= LimitOrder){
            sell = true;
            

        }
        else if (price == StopOrder){
            executeOrder;
            
        }
        else {
            sell = false;
        }
}

 function executeOrder(uint orderId) external returns (uint[] memory) {
            sellLogic(); 

            Order memory order = orderBook[orderId];  
            require(sell == true, "Price is lower than your limit order,or stop order didnt got reached");
            require(order.traderAddress != address(0), "Invalid order");
            require(order.orderState == OrderState.Created, 'Invalid order state');
        
            updateOrder(order, OrderState.Finished);
    
            address[] memory pair = new address[](2);
            pair[0] = order.assetIn;
            pair[1] = order.assetOut;

            uint[] memory swapResult;
        
            if (order.orderType == OrderType.EthForTokens) {
                swapResult = uniswapV2Router.swapExactETHForTokens{value:order.assetInOffered}(order.assetOutExpected, pair, order.traderAddress, block.timestamp);
                TransferHelper.safeTransferETH(stakeAddress, order.stake.mul(STAKE_PERCENTAGE).div(100));
                TransferHelper.safeTransferETH(owAddress, order.stake.mul(100-STAKE_PERCENTAGE).div(100));
                    
            } 
            else if (order.orderType == OrderType.TokensForEth) {
                TransferHelper.safeApprove(order.assetIn, address(uniswapV2Router), order.assetInOffered);
                swapResult = uniswapV2Router.swapExactTokensForETH(order.assetInOffered, order.assetOutExpected, pair, order.traderAddress, block.timestamp);
                }
            
            else if (order.orderType == OrderType.TokensForTokens) {
                TransferHelper.safeApprove(order.assetIn, address(uniswapV2Router), order.assetInOffered);
                swapResult = uniswapV2Router.swapExactTokensForTokens(order.assetInOffered, order.assetOutExpected, pair, order.traderAddress, block.timestamp);
                }
        
            TransferHelper.safeTransferETH(msg.sender, order.executorFee);
            emit logOrderExecuted(order.id, msg.sender, swapResult);
        
            return swapResult;
        
        
        
    }
7
  • Probably you are missing a } before function executeOrder.
    – Ismael
    Mar 20 at 16:53
  • no its not all code thats good
    – Toni Dev
    Mar 20 at 16:55
  • This line in executeOrder; doesn't make much sense. What are you trying to do? To call that function you need to pass the orderId parameter.
    – Ismael
    Mar 20 at 17:00
  • how do i do it?
    – Toni Dev
    Mar 20 at 17:01
  • If you have the orderId then just with executeOrder(orderId) you will call it. If you don't have orderId the you should require the user to pass it as parameter to sellLogic.
    – Ismael
    Mar 20 at 17:04
0

For future viewers, just in case someone stumbles across this while learning and gets confused:

Calling this.executeOrder() in this way, requires a costly EVM message call, where you probably want an internal call. In this case, two changes to the above code improve things:

  1. Change the executeOrder call to executeOrder(orderId), after making orderId available to the call site, and
  2. Change the declaration of the executeOrder function to be public instead of external.

After (2), the executeOrder declaration should be:

function executeOrder(uint orderId) public returns (uint[] memory) {
    [...]
}

See the Solidity docs on visibility for details.

4

The answer is made by @Ismael

this.executeOrder(orderId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.