ExtropyIO / defi-bot

Tutorial for building DeFi arbitrage bots
1.18k stars 467 forks source link

Fail with error 'OneSplit: swap makes no sense' #4

Open bryan27118 opened 3 years ago

bryan27118 commented 3 years ago

Transaction keeps reverting with the error "Fail with error 'OneSplit: swap makes no sense'"

https://etherscan.io/tx/0x35c7e07964a90184d8f3571ae4b5d6b976b978b55f306cd21dcfeca39e5eff49

It seems the error is being thrown from OneSplit's swap function

function swap(
        IERC20 fromToken,
        IERC20 toToken,
        uint256 amount,
        uint256 minReturn,
        uint256[] memory distribution,
        uint256 featureFlags // See contants in IOneSplit.sol
    ) public payable {
        require(fromToken != toToken && amount > 0, "OneSplit: swap makes no sense");
        require((msg.value != 0) == fromToken.isETH(), "OneSplit: msg.value shoule be used only for ETH swap");

        uint256 fromTokenBalanceBefore = fromToken.universalBalanceOf(address(this)).sub(msg.value);
        uint256 toTokenBalanceBefore = toToken.universalBalanceOf(address(this));

        fromToken.universalTransferFromSenderToThis(amount);
        fromToken.universalApprove(address(oneSplitImpl), amount);

        oneSplitImpl.swap.value(msg.value)(
            fromToken,
            toToken,
            amount,
            minReturn,
            distribution,
            featureFlags
        );

        uint256 fromTokenBalanceAfter = fromToken.universalBalanceOf(address(this));
        uint256 toTokenBalanceAfter = toToken.universalBalanceOf(address(this));

        uint256 returnAmount = toTokenBalanceAfter.sub(toTokenBalanceBefore);
        require(returnAmount >= minReturn, "OneSplit: actual return amount is less than minReturn");
        toToken.universalTransfer(msg.sender, returnAmount);

        if (fromTokenBalanceAfter > fromTokenBalanceBefore) {
            fromToken.universalTransfer(msg.sender, fromTokenBalanceAfter.sub(fromTokenBalanceBefore));
        }
    }

More specifically, this line here require(fromToken != toToken && amount > 0, "OneSplit: swap makes no sense");

My guess is that the amount being passed is less than zero in the TradingBot contract. https://github.com/ExtropyIO/defi-bot/blob/f77ea1cf0f9317496275ca97a5f0da66ab301e8b/src/contracts/TradingBot.sol#L290-L293

Does anyone have any ideas what might be happening or how to work around this?

ezynda3 commented 3 years ago

I'm getting the same error. It seems that the ZRX trade is always getting 0 tokens back for some reason...

codemedici commented 3 years ago

https://extropy-io.medium.com/arbitrage-bot-part-2-97e7b710dcf

The article explains it best. Essentially you are getting front-rjn, or at least that's the common opinion, I havent dug deep enough but it seems like the result from 0x is 0 because somebody front run you and hence 1inch complains that zero amount makes no sense (selling)

ezynda3 commented 3 years ago

Ah ok. That makes sense then. Thanks!

codemedici commented 3 years ago

@ezynda3 any updates on that? Have you tried testing with a forked version of Mainnet? That might prove or disprove whether it was front-runners after all.

nfujimori-godaddy commented 3 years ago

@codemedici I'm getting the same error. It seems that the ZRX trade is always getting 0 even with very high gas, did you found any issue on contract?

Welsh-Boogie commented 2 years ago

@Bcantz27 does this bot work?

codemedici commented 2 years ago

@nfujimori-godaddy @Welsh-Boogie Tbh I also go the same error when I was running the bot and it's been a year since, I never figured out the issue, haven't tried figuring it out either. I thought it was front runners that caused you to try and trade a 0 amount with OneInch (see the error message generated by the OneSplit contract ), but I'm not so sure actually...

So the question remains, has anyone been able to successfully run this bot?