用的之前看到的合约代码,uniswapv3 在测试网上添加流动性后,前端页面和在合约里面查到的价格差了10倍,是哪里不对吗?
function getPrice(address tokenIn, address tokenOut)
external
view
returns (uint256 price)
{
IUniswapV3Pool pool = IUniswapV3Pool(factory.getPool(tokenIn, tokenOut, fee));
(uint160 sqrtPriceX96,,,,,,) = pool.slot0();
return uint(sqrtPriceX96).mul(uint(sqrtPriceX96)).mul(1e18) >> (96 * 2);
}
function getQuote(address tokenA, uint amountA, address tokenB) public view override returns (uint256 amountB) {
int24 tick = OracleLibrary.consult(factory.getPool(tokenIn, tokenOut, fee), 60);
return OracleLibrary.getQuoteAtTick(tick, uint128(amountA), tokenA, tokenB);
}