admin 管理员组文章数量: 1086019
I'm using Uniswap V3 to quoteSingleInput of how many token1 I get for token0. WETH/ARB in this case, both having 18 decimals. I've asked ChatGPT how I do it, and it keeps trying to get me to get the gas price in wei
const gasPriceData = (await provider.getFeeData()).gasPrice
But I want the gas price in ARB not wei, to minus it from the the amountOut. Has anyone come across this ? Do I multiply the gasPriceData by anything ? I'm really confused
async function fetchGasToToken(_gasUnits, _token1) {try {const gasCost = new BigNumber(_gasUnits);const gasCostInToken = gasCost.div(new BigNumber(10).pow(_token1.decimals));return gasCostInToken;} catch (error) {console.error("❌ Error converting gas to token1:", error);throw error;}}
const params = {tokenIn: _token0.address,tokenOut: _token1.address,fee: p.fee,amountIn: _amount,sqrtPriceLimitX96: 0,}
const [amountOut, sqrtPriceX96After, initializedTicksCrossed, gasEstimate] =await withTimeout(uniswap_v3.quoter.quoteExactInputSingle.staticCall(params),10000 // 10-second timeout)
const gasInToken = await fetchGasToToken(gasEstimate, _token1) // gasEsimate is 102848
const finalAmount = BigNumber(amountOut).minus(gasInToken);`
I tried dividing gasUnits by the token1 Decimals after multiplying by the power of 10.
本文标签:
版权声明:本文标题:javascript - How do I calculate Uniswap V3 gas units to token1 ? Response from Uniswap V3 quoteExactInputSingle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744069236a2528184.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论