swapr-dapp
swapr-dapp copied to clipboard
Gas estimation
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
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:
- 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
- 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
- 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