0

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 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.