最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I calculate Uniswap V3 gas units to token1 ? Response from Uniswap V3 quoteExactInputSingle - Stack Overflow

programmeradmin0浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论