zeta-chain / node

ZetaChain’s blockchain node and an observer validator client
https://zetachain.com
MIT License
164 stars 105 forks source link

`gas_payment`: Investigate value obtained vs value expected small differences when using Uniswap pool #1303

Closed lumtis closed 7 months ago

lumtis commented 11 months ago

When using Uniswap to obtain gas for payment, it appears there can be small differences between the amount expected and obtained:

"gas obtained for burn (119734577374817) not equal to gas fee(119734550670000): invalid gas amount"

The amount we swap out from the GetAmountIn call in Uniswap contract doesn't exactly match the value we provide to the GetAmountIn function.

We should investigate the cause of these small mismatches. It can be caused by low liquidity if GetAmountIn doesn't account the slippage during swaps

If we find the cause of it and it can be fixed so the amounts always exactly match, we should introduce the checks and return errors during mismatch.

brewmaster012 commented 11 months ago

Looks like getAmountIn() returns

Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.

Note the "minimum".

It might not be possible to get exact output amount, as we are using Uniswap v2 SwapExactTokensForTokens(). To get exact output we might need to use SwapTokensForExactTokens() instead.

lumtis commented 7 months ago

Looks no longer relevant