swapr-dapp icon indicating copy to clipboard operation
swapr-dapp copied to clipboard

Gas estimation

Open Mi-Lan opened this issue 2 years ago • 2 comments

Linked to this sdk pr https://github.com/ImpeccableHQ/swapr-sdk/pull/276

  • In this current version I added support for uniswap trade gas estimation , 1inch and 0xTrade for those it will always work and also gas estimation will work when selected currency is native in all types of trade
  • For the Univ2 dexes on erc20 tokens estimation will work only when you have enough balance and approved the router
  • I have code ready for alchemy estimation bundle api but since right now their gas estimates are not working properly I commented it out Screenshot 2023-02-28 at 09 18 18

To test:

  • Try to make a transaction with specific trade and see if it matches the amount in gas column.

Some notes from my research:

  1. Looking into the uniswaps smart order router I think this comment sums it up pretty good they basically do it off chain https://github.com/Uniswap/smart-order-router/blob/adf5b62fe5264f72903571537861de327c850751/src/routers/alpha-router/gas-models/gas-model.ts#L104
  2. Tenderly Simulation api won't work since forks and simulation api is rate limited to wayy below our needs https://docs.tenderly.co/simulations-and-forks/simulation-api/simulation-api-rate-limits#simulation-api
  3. Alchemy's bundle simulation https://docs.alchemy.com/reference/simulation-bundle could potentially work but there seems to be some issues on their side I submitted a ticket on discord and they contacted me thanking for pointing it out so well see based on response if this is feasable. Also regarding api limits one api call costs 2500 CU and with paid plan we get 400,000,000CPU's so that comes to about 160,000 estimations a month. Which I think its enough with some optimizations for fetching it will be fine! I made it so that if regular estimate gas fails it will try this simulation api...Not in all cases

Mi-Lan avatar Feb 10 '23 15:02 Mi-Lan