Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas estimation #1726

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

Gas estimation #1726

wants to merge 18 commits into from

Conversation

Mi-Lan
Copy link
Collaborator

@Mi-Lan Mi-Lan commented Feb 10, 2023

Linked to this sdk pr
SwaprHQ/swapr-sdk#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

@netlify
Copy link

netlify bot commented Feb 10, 2023

Deploy Preview for swapr ready!

Name Link
🔨 Latest commit d5517ed
🔍 Latest deploy log https://app.netlify.com/sites/swapr/deploys/6400ddecefa8d30007ba28e2
😎 Deploy Preview https://deploy-preview-1726--swapr.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot temporarily deployed to gas-estimation February 22, 2023 17:31 Destroyed
@github-actions github-actions bot temporarily deployed to gas-estimation February 22, 2023 19:09 Destroyed
@Mi-Lan Mi-Lan changed the title WIP: Gas estimation Gas estimation Feb 27, 2023
@github-actions github-actions bot temporarily deployed to gas-estimation February 27, 2023 05:30 Destroyed
@github-actions github-actions bot temporarily deployed to gas-estimation February 28, 2023 16:36 Destroyed
Copy link
Collaborator

@berteotti berteotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. Code looks good just needs a few improvements.

src/constants/data.ts Outdated Show resolved Hide resolved
Comment on lines 230 to 238
let transactionRequest: any
try {
transactionRequest = await call.transactionParameters
} catch (e) {
console.log('Failed to get transaction parameters', e)
}

// Ignore gas estimation if the request has gasLimit property
if (transactionRequest.gasLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If transactionRequest is undefined it could break when checking transactionRequest.gasLimit. Also I don't think we want to console.log the error, use .error in this case.

Copy link
Collaborator Author

@Mi-Lan Mi-Lan Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this part I noticed during testing that it wasn't handling the error so I put this in place. It didn't throw it for me.

@MilanVojnovic95
Copy link
Collaborator

Tested and looks ok to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants