0

I am doing some research on front running transactions. My goal is to purchase a token in PancakeSwap in the same block that liquidity is added.

Lets take this token as an example: https://bscscan.com/token/0x195d3576bbf6504d8eac5b614dcb756e32b911d5

It was launched on block https://bscscan.com/block/7699663, which a single transaction adding 20 BNB LP on the PancakeSwap V2 Router (https://bscscan.com/tx/0x48b3b3b9dafcaff0f77e4c40abd80afcc47a20b19db23d9dc96a9ff326446a8c).

I used that transaction as a trigger for my swap order (only 0.01 BNB, 10 gwei) https://bscscan.com/tx/0xa66fbba13749cbd3005957d257da22e5afb07cfc007fe790976cda284a64c1f0 which failed. I want to understand why.

Maybe I placed my order too soon, but that is the goal, right? How should I estimate when to place then order then?

I can also think the problem was the gas price. My gas price was 10 gwei and the tx that added the liquidity had a price of 5 gwei. Does this mean that my tx will get processed first, and therefor will fail because there is not enough liquidity yet?

If this explanation is correct, would doing this transaction with the same gas price as the liquidity (or perhaps 1 less gwei?) guarantee that it will get processed? What would be the best way to achieve a good compromise between speed and success rate?

From this little experiment I can imagine that detecting a pending transaction (with a low or average gas price) and then submitting an equivalent swap with x2-3 gas price will likely result in my transaction being processed first, right?

Isn't this a very important flaw of DEX? how can one solve this problem?

Thanks!

3 Answers 3

2

There's no predefined order for transactions in a block. The only requirement is for transactions from the same address to be sorted by the transaction's nonce but transactions from different addresses can be in any order.

In Ethereum mainnet miners will sort by gas price because they will get a larger reward. But it is not always the case, search for "Miner Extractable Value" and the Flashbot project, some times miners will get a bigger reward by including a group of transactions.

Unfortunately I don't know a solution that will work in a PoA network like BSC.

1

The transaction failed because due to the higher gas price and being on the same block, it was executed before the liquidity was added. I was confusing the nonce with the block position.

0

It is a gas problem, if it is in the same block the gas price has to be the same if you want to succeed in backrunning the liquidity transaction, the thing is once you are in the same block with the same gas price then It is pretty much casual the order, most of the people use contracts that sends many many transactions at the same time so that many transactions enters the block you are interested in and they have higher chance of being the first transaction after liquidity in the block. But how do you manage to enter the same block with a single transaction ? (meaning do you trigger only 1 transaction right ?)

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