yuichiroaoki / poly-flashloan-bot

Flashloan Bot on Polygon
https://yuichiroaoki.medium.com/flashloan-bot-on-polygon-part-2-3eae0ac33986?sk=80821da4ca1d0462c7c9ae617df56bdd
MIT License
303 stars 192 forks source link

Fees calculation before send the transaction #27

Open ezera23 opened 2 years ago

ezera23 commented 2 years ago

Fees need to be calculated before send the transaction to avoid 'Not enough amount to return loan', 'INSUFFICIENT_OUTPUT_AMOUNT' errors... It would be nice if you can implement something like this:

  1. Get Quote
  2. Calculate each swap fees and add to it loan fees and ADD the slippery % (the one set in config.ts)
  3. Check the difference of % or calculate amount and check amount diff.
  4. If difference % or amnt is +n (this should be a const in config.ts to include/edit MATIC fees as needed) so send transaction BUT if difference % or amnt -n or = 0 so do not send the transaction

Actually when you swap 3 times in one transactions it can be 0.05x3 = 0.15 % fees on top of the flashloans fees 0.09%... Total 0.24% and.... slippery can add it on top again if the bot takes to long time to get the quote :) Eg: 0.24 + 6 = 6.24%

'const diffAmount' should be here MORE than 1000 + 6.24% or 62.4 USD to return to loan BUT we don't know how many swaps will be done before getting the quote so this const doesn't really help for now (but interesting to get it there).

Everything need to be done in milliseconds.

To avoid "high slippery" Im testing some auto rotation proxies services directly in the CallUrl... (I'm not a dev so I try easy way first) in order to increase transactions speed. I'll continue my tests...

With all of this we may have much less opportunities but at least we will be able to get a profit from them when their is big prices movements and to make it works.

https://polygonscan.com/address/0x3b89c1a54a2db96826b1319ae393b52a86938e60

lhalpin333 commented 2 years ago

i have similar output here https://polygonscan.com/address/0xb8fc2dc56022492292243994e0e20d0d38bdfa68