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

Impossible to set correct gas price for gas tokens with low decimals #79

Closed
rmeissner opened this issue Nov 16, 2018 · 4 comments
Closed

Comments

@rmeissner
Copy link
Member

Description

When paying with an erc20 you would take the exchange rate of token to eth and calculate a fair gas price based on that. For the correct token gas price it is also necessary to take into consideration that eth has 18 and some tokens have less. This can cause problems because the gas price can potentially be between 0 and 1 (which is impossible with uint).

Example calculation

Used gas token will be LOVE (0xb3a4bc89d8517e0e2c9b66703d09d3029ffa1e6d)

  1. Eth gas price is 5 GWei = 5 000 000 000 Wei
  2. For a conversion rate of 1 LOVE = 0.01 ETH this would be multiplied by 100
  3. LOVE only has 6 decimals (compared to the 18 of ETH) therefore we need to divite by 1e12
    • Resulting token gas price: 0.5

Steps to reproduce

@Chi-AnTai
Copy link

Hi, @rmeissner
I am also facing this problem, do you have any solution or advise on this ?

@rmeissner
Copy link
Member Author

Will not be fixed: #197

@mmv08
Copy link
Member

mmv08 commented Jun 9, 2022

I had a weird brainfart and struggled to understand the example calculations, so I'll leave some details for a future reference:

  1. The gas price in a token is calculated as gwei_price * 1_eth_to_token_ratio
  2. In the example 1_eth_to_token_ratio would be 100, 1 ETH = 100 LOVE
  3. The result is 5 * 10^11

My biggest problem was understanding where 1e12 came from. If we use uniswap, then the price 1_eth_to_token_ratio would be calculated as:
price = love_reserves / eth_reserves
where love_reserves and eth_reserves are in their smallest denomination; therefore, if we want to get to their largest denomination, every reserve has to be divided by 10 ^ token_decimals, so we get 10 ^ 6 / 10 ^ 18, which turns into 10 ^ -12.

The example calculation is in the largest denomination, so to get to the smallest, we need to multiply it by 10 ^ -12 which is the same as dividing by 10 ^ 12

@livingrockrises
Copy link

if you send tokenGasPrice multiplied by a factor say 1e18 and update handlePayment to divide by this fixed number then it solves the problem.
we tried to keep variable tokenGasPriceFactor but fixed high value also makes sense.

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

4 participants