etherdelta / etherdelta.github.io

https://etherdelta.com
555 stars 689 forks source link

Bad Instruction - Trade #531

Open ateene opened 6 years ago

ateene commented 6 years ago

I'm getting a "Warning! Error encountered during contract execution [Bad instruction]" when submitting a trade transaction through the API / Smart Contract. I check the availableVolume and testTrade before submitting the trade so I believe the parameters are correct, and using 4 Gewi for the gas. I'm not sure how to debug this. https://etherscan.io/tx/0xd939cff5edbfc4ca47a865d2710a121649f99189943404a8ce21c548d5d76920 `

        var funcInput = new object[] {
            order.TokenGet,
            order.AmountGet,
            order.TokenGive,
            order.AmountGive,
            order.Expires,
            order.Nonce,
            order.User,
            order.V,
            order.R.HexToByteArray(),
            order.S.HexToByteArray(),
            amount,
            user
        };

        var fnTestTrade = ForkDeltaContract.GetFunction("testTrade");
        var goodTrade = await fnTestTrade.CallAsync<bool>(funcInput);

        if (!goodTrade)
        {
            Console.WriteLine($"Trade \"{tradeInfo}\" will fail");
            return false;
        }
        Array.Resize(ref funcInput, funcInput.Count() - 1);

        var fnTrade = ForkDeltaContract.GetFunction("trade");
        var data = fnTrade.GetData(funcInput);

        var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(config.User);
        var encoded = Web3.OfflineTransactionSigner.SignTransaction(config.PrivateKey, config.ForkDeltaAddress, amount,
                    txCount, config.GasPrice, config.GasLimit, data);
        var verified = Web3.OfflineTransactionSigner.VerifyTransaction(encoded);

        var txId = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(encoded.EnsureHexPrefix());
        var txReceipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId); 

`

ateene commented 6 years ago

I entered two exact same trades; one via the UI and one with the API / Smart Contract. The UI trade (https://etherscan.io/tx/0x7d5eddce72335e71d1c2d4e4a7bc426be3acac88bf3fc14e2dd63ac002394e55) succeeded but the Smart Contract trade failed (https://etherscan.io/tx/0xf04b0b40e071b230cfb857fc0b8777a1dafcbd878c89dd54eea8f27c7ca8ef44). From what I can tell, all the input parameters are the same.