I’m developing a solidity contract that needs to swap between ETH and Stable coins like USDC. I’m having trouble finding an appropriate, production ready, setting for sqrtPriceLimitX96. All documentation that I have found use 0 stating that for production it needs to be handled differently, without specifying how. Can someone help me on how to set this parameter appropriately for a production ready contract?
1 Answer
In typescript:
const priceToSqrtPrice = (price: number) => {
const result = BigInt(Math.floor(Math.sqrt(price) * 2 ** 96))
return result
}
Pass the human readable price and it will return the square root price.