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

Fee Estimation #17

Closed
apbendi opened this issue May 20, 2021 · 2 comments
Closed

Fee Estimation #17

apbendi opened this issue May 20, 2021 · 2 comments
Assignees

Comments

@apbendi
Copy link
Member

apbendi commented May 20, 2021

How to figure out gas that will be used by the transactions

  • Using the simulation
    • If the user has ETH, we can have the flashbots simulation tell us
    • If the user doesn't have ETH, the simulation will fail— could MEV geth change this?
    • Does the user have to sign the txs first? This makes for a weird UX, and also a problem in getting the amounts right before having the user sign
    • Also state related issue— what if user doesn't have token balance by final swapAndBribe, etc...
  • Estimate and hardcode for token transfers <--- probably MVP approach
    • Populating values for the initital token list
      • Look up a few approves, transfers, and swaps on Etherscan and eyeball it
      • Use Dune analytics query or etherscan API to pull values

Gas usage heuristic— how to figure out the gas price

  • Extremely naive option: multiply current gas price by 2 or 3
  • Other ideas: historical flashbots txs from API, last block tail gas, etc...
  • Ask Flashbots team for recommendations, likely to be impacted by bundle merging

User Experience

  • Once we have the gas estimate, show it in the selected token
  • Cannot be edited (?) (future— got higher but not lower?)
  • What happens if token balance is insufficient after fee is included? -- Toast or Form Validation on amount

Note: look into other solutions

@apbendi
Copy link
Member Author

apbendi commented Jun 3, 2021

Approach for MVP:

  1. Use Dune Analytics to calculate reasonable upper bound values for transfer, approve, and swap per Dune Analytics SQL Queries For Token Interactions #21
  2. Include values in token list as custom fields calculated above
  3. In the frontend, calculate the fee to be charged in the base token by:
    • Summing the gas values for transfer, approve, and swap
    • Checking the market rate for gas via gasnow API and multiplying by gas used in ETH
    • Take the amount calculated in previous step and apply some function to adjust it for Flashbots estimate, e.g. it will likely cost more than market gas rate from mempool, but how much more? 2x? Something more complicated? Should this be UI configurable? Gas premium toggle Low/High for example?
    • Use coingecko or other API to get spot price of the token in USD & the spot price of ETH in USD
    • Use values above to calculate amount of token needed for bribe to display to user
    • Alternatively: can we look directly at Uniswap v2 Pool spot price or swap estimation? Whichever is easier
    • Display the fee in selected token in non-editable (greyed out) field or other UI component
    • Validate that the user's total token balance is greater than or equal to the sum of the transfer amount & the fee/bribe amount; show error message if not

@apbendi
Copy link
Member Author

apbendi commented Jun 12, 2021

Closed with #37

@apbendi apbendi closed this as completed Jun 12, 2021
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

No branches or pull requests

2 participants