0

when i monitor a profitable trade. The difference in profit calculated by my own method and the result of getAmoutsOut is not significant. Before sending the transaction, I would use the getAmoutsOut function to double check if the output amount is greater than input amount. If the output amount is greater than input amount I would send the transaction. But I encountered a problem that if the arbitrage is profitable, let's say greater than or equal to 0.1 WBNB, then after flash loan arbitrage the output amount is less than input amount, can not repay the loan and the transaction reverted. In testing, if the profit is in the range of 10 to the power of -4 or even less, the transaction usually succeed. I reality, even all the profitable arbitrage chance would fail. Anyone can tell me why this happend?

4
  • Could you add more info. Does your profitability check account for gas fees? Does the check account for loan fees? Could you clarify the discrepancy in getAmountsOut? Do you have any exact amounts as an example?
    – Maka
    Sep 17, 2023 at 2:41
  • The profitability check does not account for gas fees. Because the profit threshold i set is far higher than gas fee. For example the profit is 0.1 WBNB(20$) and the gas is just 0.0023 WBNB(0.5$). My own method would calculate the most profitable input amount, output amount based on calculated input amount, profit and trade path. The quantity I calculated using my own method is basically consistent with getAmountsOut which pancakeswap provided, with little difference. Sep 17, 2023 at 2:56
  • I do account the 0.25% swap fee in my calculation. The situation I encounter right now is my own calculation method and pancakeswap's getAmountsOut all told me that this trade is profitable but in reality the output amount even can not repay the flash loan Sep 17, 2023 at 3:16
  • Ok, well we know that getAmountOut produces correct calculations, so it isn't an issue with that. If the difference can be confirmed (easy enough with reserves, block numbers and transaction state changes) you have to assume you are either executing the trade incorrectly, or that the opportunity isn't there by the time you attempt to execute it. I would step through reserves and transactions across the block, confirm the opportunity, since if it existed and you didn't take it someone else did it. If it didn't exist then you are calculating incorrectly.
    – Maka
    Sep 17, 2023 at 16:49

1 Answer 1

0

Every swap() that occurs on the LP contract must fee of around 0.3%. Different AMM's have different fee rates, and even some LPs have different fee rates among themselves within an AMM.

When swapping between AMMs to take advantage of an arbitrage opportunity you must take into account the swap fees on LP in the AMM where the swap() occurs. This, along with gas prices, can quickly remove any potential profit to be made and should be accounted for as best as possible.

One potential solution is to to do real human due diligence on each market you plan on scraping for arbs. Get a list of AMMs, comb their docs, and start to construct a object/json with each AMMs details including fee rates, contract addresses, etc. Using this object as a constant within your arb bot can add necessary context for your code to calculate fees while also reducing unnecessary calls to the chain; i.e. making individual calls to the LP contract to determine fees.

2
  • I do account the 0.25% swap fee in my calculation(All the pancakeswap v2 pairs are the same). The situation I encounter right now is my own calculation method and pancakeswap's getAmountsOut all told me that this trade is profitable but in reality the output amount even can not repay the flash loan Sep 17, 2023 at 3:58
  • I do have a json includes all the pancakeswap v2 paris monitored which contains the fee, token symbol, token decimal, token address and the pair address Sep 17, 2023 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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